From 75859ca9dc12d3951c2baa0f11324cbb77686aa5 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 2 Sep 2007 11:09:16 +0000 Subject: [PATCH] Use the feature type rather than the feature name to figure out whether we need to add "_input" to get the correct sysfs file name. This is much faster. This is still a ugly hack I'd like to get rid of, but at least now the slowdown is acceptable. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4743 7894878c-1315-0410-8ee3-d5d059ff63e0 --- lib/sysfs.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/sysfs.c b/lib/sysfs.c index 5c712db6..ee854955 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -411,17 +411,15 @@ int sensors_read_sysfs_attr(const sensors_chip_name *name, int feature, int mag; char n[NAME_MAX]; FILE *f; - int dummy; - char check; const char *suffix = ""; if (!(the_feature = sensors_lookup_feature_nr(name, feature))) return -SENSORS_ERR_NO_ENTRY; /* REVISIT: this is a ugly hack */ - if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1 - || sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1 - || sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1) + if (the_feature->data.type == SENSORS_FEATURE_IN + || the_feature->data.type == SENSORS_FEATURE_FAN + || the_feature->data.type == SENSORS_FEATURE_TEMP) suffix = "_input"; snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->data.name, @@ -446,17 +444,15 @@ int sensors_write_sysfs_attr(const sensors_chip_name *name, int feature, int mag; char n[NAME_MAX]; FILE *f; - int dummy; - char check; const char *suffix = ""; if (!(the_feature = sensors_lookup_feature_nr(name, feature))) return -SENSORS_ERR_NO_ENTRY; /* REVISIT: this is a ugly hack */ - if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1 - || sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1 - || sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1) + if (the_feature->data.type == SENSORS_FEATURE_IN + || the_feature->data.type == SENSORS_FEATURE_FAN + || the_feature->data.type == SENSORS_FEATURE_TEMP) suffix = "_input"; snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->data.name,