aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_cpuinfo.c
diff options
context:
space:
mode:
authorreinelt <>2004-03-11 06:39:59 +0000
committerreinelt <>2004-03-11 06:39:59 +0000
commitb241d736825d0469b7716847ee4ef5de269d2423 (patch)
treee3f51842280e06133de00726fa987765d4464f10 /plugin_cpuinfo.c
parent888c37c1b1aa181c76253af8425b2bbbac4bbc4a (diff)
downloadlcd4linux-b241d736825d0469b7716847ee4ef5de269d2423.tar.gz
[lcd4linux @ 2004-03-11 06:39:58 by reinelt]
big patch from Martin: - reuse filehandles - memory leaks fixed - earlier busy-flag checking with HD44780 - reuse memory for strings in RESULT and hash - netdev_fast to wavid time-consuming regex
Diffstat (limited to 'plugin_cpuinfo.c')
-rw-r--r--plugin_cpuinfo.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/plugin_cpuinfo.c b/plugin_cpuinfo.c
index 1bec66b..2fcb98d 100644
--- a/plugin_cpuinfo.c
+++ b/plugin_cpuinfo.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_cpuinfo.c,v 1.8 2004/03/03 03:47:04 reinelt Exp $
+/* $Id: plugin_cpuinfo.c,v 1.9 2004/03/11 06:39:59 reinelt Exp $
*
* plugin for /proc/cpuinfo parsing
*
@@ -23,6 +23,14 @@
*
*
* $Log: plugin_cpuinfo.c,v $
+ * Revision 1.9 2004/03/11 06:39:59 reinelt
+ * big patch from Martin:
+ * - reuse filehandles
+ * - memory leaks fixed
+ * - earlier busy-flag checking with HD44780
+ * - reuse memory for strings in RESULT and hash
+ * - netdev_fast to wavid time-consuming regex
+ *
* Revision 1.8 2004/03/03 03:47:04 reinelt
* big patch from Martin Hejl:
* - use qprintf() where appropriate
@@ -84,24 +92,22 @@
static HASH CPUinfo = { 0, };
-
+static FILE *stream = NULL;
static int parse_cpuinfo (void)
{
int age;
- FILE *stream;
// reread every second only
age=hash_age(&CPUinfo, NULL, NULL);
if (age>0 && age<=1000) return 0;
-
- stream=fopen("/proc/cpuinfo", "r");
- if (stream==NULL) {
+ if (stream == NULL) stream=fopen("/proc/cpuinfo", "r");
+ if (stream == NULL) {
error ("fopen(/proc/cpuinfo) failed: %s", strerror(errno));
return -1;
}
-
+ rewind(stream);
while (!feof(stream)) {
char buffer[256];
char *c, *key, *val;
@@ -123,7 +129,6 @@ static int parse_cpuinfo (void)
hash_set (&CPUinfo, key, val);
}
- fclose (stream);
return 0;
}
@@ -153,5 +158,9 @@ int plugin_init_cpuinfo (void)
void plugin_exit_cpuinfo(void)
{
- hash_destroy(&CPUinfo);
+ if (stream != NULL) {
+ fclose (stream);
+ stream = NULL;
+ }
+ hash_destroy(&CPUinfo);
}