* Applied 2 patches:
[monky] / src / diskio.c
1 /*
2  * Conky, a system monitor, based on torsmo
3  *
4  * Any original torsmo code is licensed under the BSD license
5  *
6  * All code written since the fork of torsmo is licensed under the GPL
7  *
8  * Please see COPYING for details
9  *
10  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
11  * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al.
12  * (see AUTHORS)
13  * All rights reserved.
14  *
15  * This program is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  * You should have received a copy of the GNU General Public License
25  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26  *
27  *  $Id$
28  */
29
30 #include <limits.h>
31 #include "conky.h"
32
33 static struct diskio_stat diskio_stats_[MAX_DISKIO_STATS];
34 struct diskio_stat *diskio_stats = diskio_stats_;
35
36 void clear_diskio_stats()
37 {
38         unsigned i;
39         for(i = 0; i < MAX_DISKIO_STATS; i++) {
40                 if (diskio_stats[i].dev) {
41                         free(diskio_stats[i].dev);
42                         diskio_stats[i].dev = 0;
43                 }
44         }
45 }
46
47 struct diskio_stat *prepare_diskio_stat(const char *s)
48 {
49         struct diskio_stat *new = 0;
50         unsigned i;
51         /* lookup existing or get new */
52         for (i = 0; i < MAX_DISKIO_STATS; i++) {
53                 if (diskio_stats[i].dev) {
54                         if (strcmp(diskio_stats[i].dev, s) == 0) {
55                                 return &diskio_stats[i];
56                         }
57                 } else {
58                         new = &diskio_stats[i];
59                         break;
60                 }
61         }
62         /* new dev */
63         if (!new) {
64                 ERR("too many diskio stats");
65                 return 0;
66         }
67         new->dev = strdup(s);
68         new->current = 0;
69         new->current_read = 0;
70         new ->current_write = 0;
71         new->last = UINT_MAX;
72         new->last_read = UINT_MAX;
73         new->last_write = UINT_MAX;
74         return new;
75 }