aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_cpuinfo.c
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-06-17 06:23:43 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-06-17 06:23:43 +0000
commit1d354fd87d4c07906e82d104ba8614d30ae9cbbe (patch)
treeca9aafd446dda125df1411933930669d303c9a30 /plugin_cpuinfo.c
parente8e56418dc7375b50f36e930fb6752fbe25b4ae1 (diff)
downloadlcd4linux-1d354fd87d4c07906e82d104ba8614d30ae9cbbe.tar.gz
[lcd4linux @ 2004-06-17 06:23:39 by reinelt]
hash handling rewritten to solve performance issues git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@473 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'plugin_cpuinfo.c')
-rw-r--r--plugin_cpuinfo.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/plugin_cpuinfo.c b/plugin_cpuinfo.c
index 2fcb98d..f5923cc 100644
--- a/plugin_cpuinfo.c
+++ b/plugin_cpuinfo.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_cpuinfo.c,v 1.9 2004/03/11 06:39:59 reinelt Exp $
+/* $Id: plugin_cpuinfo.c,v 1.10 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for /proc/cpuinfo parsing
*
@@ -23,6 +23,10 @@
*
*
* $Log: plugin_cpuinfo.c,v $
+ * Revision 1.10 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.9 2004/03/11 06:39:59 reinelt
* big patch from Martin:
* - reuse filehandles
@@ -91,7 +95,7 @@
#include "hash.h"
-static HASH CPUinfo = { 0, };
+static HASH CPUinfo;
static FILE *stream = NULL;
static int parse_cpuinfo (void)
@@ -99,10 +103,10 @@ static int parse_cpuinfo (void)
int age;
// reread every second only
- age=hash_age(&CPUinfo, NULL, NULL);
- if (age>0 && age<=1000) return 0;
+ age = hash_age(&CPUinfo, NULL);
+ if (age > 0 && age <= 1000) return 0;
- if (stream == NULL) stream=fopen("/proc/cpuinfo", "r");
+ if (stream == NULL) stream = fopen("/proc/cpuinfo", "r");
if (stream == NULL) {
error ("fopen(/proc/cpuinfo) failed: %s", strerror(errno));
return -1;
@@ -112,21 +116,21 @@ static int parse_cpuinfo (void)
char buffer[256];
char *c, *key, *val;
fgets (buffer, sizeof(buffer), stream);
- c=strchr(buffer, ':');
- if (c==NULL) continue;
- key=buffer; val=c+1;
+ c = strchr(buffer, ':');
+ if (c == NULL) continue;
+ key = buffer; val = c+1;
// strip leading blanks from key
- while (isspace(*key)) *key++='\0';
+ while (isspace(*key)) *key++ = '\0';
// strip trailing blanks from key
- do *c='\0'; while (isspace(*--c));
+ do *c = '\0'; while (isspace(*--c));
// strip leading blanks from value
- while (isspace(*val)) *val++='\0';
+ while (isspace(*val)) *val++ = '\0';
// strip trailing blanks from value
- for (c=val; *c!='\0';c++);
- while (isspace(*--c)) *c='\0';
+ for (c = val; *c != '\0'; c++);
+ while (isspace(*--c)) *c = '\0';
// add entry to hash table
- hash_set (&CPUinfo, key, val);
+ hash_put (&CPUinfo, key, val);
}
return 0;
@@ -137,14 +141,14 @@ static void my_cpuinfo (RESULT *result, RESULT *arg1)
{
char *key, *val;
- if (parse_cpuinfo()<0) {
+ if (parse_cpuinfo() < 0) {
SetResult(&result, R_STRING, "");
return;
}
- key=R2S(arg1);
- val=hash_get(&CPUinfo, key);
- if (val==NULL) val="";
+ key = R2S(arg1);
+ val = hash_get(&CPUinfo, key, NULL);
+ if (val == NULL) val = "";
SetResult(&result, R_STRING, val);
}
@@ -152,6 +156,7 @@ static void my_cpuinfo (RESULT *result, RESULT *arg1)
int plugin_init_cpuinfo (void)
{
+ hash_create (&CPUinfo);
AddFunction ("cpuinfo", 1, my_cpuinfo);
return 0;
}