mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-21 11:39:31 +00:00
Change the prototype of sensors_get_label(). Errors can be reported
with a NULL pointer. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4694 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
12655c1d85
commit
8bcdc331a0
8 files changed
+29
-38
No files matched your search
+11
-11
@@ -139,27 +139,27 @@ int sensors_chip_name_has_wildcards(const sensors_chip_name *chip)
|
||||
}
|
||||
|
||||
/* Look up the label which belongs to this chip. Note that chip should not
|
||||
contain wildcard values! *result is newly allocated (free it yourself).
|
||||
This function will return 0 on success, and <0 on failure.
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself. */
|
||||
int sensors_get_label(const sensors_chip_name *name, int feature, char **result)
|
||||
char *sensors_get_label(const sensors_chip_name *name, int feature)
|
||||
{
|
||||
char *label;
|
||||
const sensors_chip *chip;
|
||||
const sensors_chip_feature *featureptr;
|
||||
char buf[128], path[PATH_MAX];
|
||||
FILE *f;
|
||||
int i;
|
||||
|
||||
*result = NULL;
|
||||
if (sensors_chip_name_has_wildcards(name))
|
||||
return -SENSORS_ERR_WILDCARDS;
|
||||
return NULL;
|
||||
if (!(featureptr = sensors_lookup_feature_nr(name, feature)))
|
||||
return -SENSORS_ERR_NO_ENTRY;
|
||||
return NULL;
|
||||
|
||||
for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
|
||||
for (i = 0; i < chip->labels_count; i++)
|
||||
if (!strcasecmp(featureptr->data.name,chip->labels[i].name)){
|
||||
*result = strdup(chip->labels[i].value);
|
||||
label = strdup(chip->labels[i].value);
|
||||
goto sensors_get_label_exit;
|
||||
}
|
||||
|
||||
@@ -173,19 +173,19 @@ int sensors_get_label(const sensors_chip_name *name, int feature, char **result)
|
||||
if (i > 0) {
|
||||
/* i - 1 to strip the '\n' at the end */
|
||||
buf[i - 1] = 0;
|
||||
*result = strdup(buf);
|
||||
label = strdup(buf);
|
||||
goto sensors_get_label_exit;
|
||||
}
|
||||
}
|
||||
|
||||
/* No label, return the feature name instead */
|
||||
*result = strdup(featureptr->data.name);
|
||||
label = strdup(featureptr->data.name);
|
||||
|
||||
sensors_get_label_exit:
|
||||
if (*result == NULL)
|
||||
if (!label)
|
||||
sensors_fatal_error("sensors_get_label",
|
||||
"Allocating label text");
|
||||
return 0;
|
||||
return label;
|
||||
}
|
||||
|
||||
/* Looks up whether a feature should be ignored. Returns
|
||||
|
||||
+6
-5
@@ -38,8 +38,7 @@ libsensors \- publicly accessible functions provided by the sensors library
|
||||
.B int sensors_match_chip(const sensors_chip_name *chip1,
|
||||
\fBconst sensors_chip_name *chip2);\fP
|
||||
.B const char *sensors_get_adapter_name(int bus_nr);
|
||||
.B int sensors_get_label(const sensors_chip_name *name, int feature,
|
||||
\fBchar **result);\fP
|
||||
.B char *sensors_get_label(const sensors_chip_name *name, int feature);\fP
|
||||
.B int sensors_get_feature(const sensors_chip_name *name, int feature,
|
||||
\fBdouble *result);\fP
|
||||
.B int sensors_set_feature(const sensors_chip_name *name, int feature,
|
||||
@@ -78,10 +77,12 @@ Compare two chips name descriptions, to see whether they could match. Return 0 i
|
||||
This function returns the adapter name of a bus number, as used within the
|
||||
sensors_chip_name structure. If it could not be found, it returns NULL.
|
||||
|
||||
\fBint sensors_get_label(const sensors_chip_name *name, int feature,
|
||||
char **result);\fP
|
||||
\fBchar *sensors_get_label(const sensors_chip_name *name, int feature);\fP
|
||||
.br
|
||||
Look up the label which belongs to this chip. Note that chip should not contain wildcard values! *result is newly allocated (free it yourself). This function will return 0 on success, and <0 on failure.
|
||||
Look up the label which belongs to this chip. Note that chip should not
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself.
|
||||
|
||||
\fBint sensors_get_feature(const sensors_chip_name *name,
|
||||
int feature, double *result);\fP
|
||||
|
||||
+3
-4
@@ -88,11 +88,10 @@ int sensors_match_chip(const sensors_chip_name *chip1,
|
||||
const char *sensors_get_adapter_name(const sensors_bus_id *bus);
|
||||
|
||||
/* Look up the label which belongs to this chip. Note that chip should not
|
||||
contain wildcard values! *result is newly allocated (free it yourself).
|
||||
This function will return 0 on success, and <0 on failure.
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself. */
|
||||
int sensors_get_label(const sensors_chip_name *name, int feature,
|
||||
char **result);
|
||||
char *sensors_get_label(const sensors_chip_name *name, int feature);
|
||||
|
||||
/* Read the value of a feature of a certain chip. Note that chip should not
|
||||
contain wildcard values! This function will return 0 on success, and <0
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ applyToFeatures
|
||||
} else if (getRawLabel (chip, labelNumber, &rawLabel)) {
|
||||
sensorLog (LOG_ERR, "Error getting raw sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = -1;
|
||||
} else if (getLabel (chip, labelNumber, &label)) {
|
||||
} else if (!(label = sensors_get_label (chip, labelNumber))) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = -1;
|
||||
} else if (valid) {
|
||||
|
||||
+2
-10
@@ -45,14 +45,6 @@ getValid
|
||||
return err;
|
||||
}
|
||||
|
||||
int
|
||||
getLabel
|
||||
(const sensors_chip_name *name, int feature, char **label) {
|
||||
int err;
|
||||
err = sensors_get_label (name, feature, label);
|
||||
return err;
|
||||
}
|
||||
|
||||
int
|
||||
getRawLabel
|
||||
(const sensors_chip_name *name, int feature, const char **label) {
|
||||
@@ -109,7 +101,7 @@ readUnknownChip
|
||||
if (getValid (chip, sensor->number, &valid)) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor validity: %s/%s", chip->prefix, sensor->name);
|
||||
ret = 20;
|
||||
} else if (getLabel (chip, sensor->number, &label)) {
|
||||
} else if (!(label = sensors_get_label (chip, sensor->number))) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor label: %s/%s", chip->prefix, sensor->name);
|
||||
ret = 21;
|
||||
} else if (!valid) {
|
||||
@@ -169,7 +161,7 @@ doKnownChip
|
||||
} else if (getValid (chip, labelNumber, &valid)) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor validity: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = 22;
|
||||
} else if (getLabel (chip, labelNumber, &label)) {
|
||||
} else if (!(label = sensors_get_label (chip, labelNumber))) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = 22;
|
||||
} else if (valid) {
|
||||
|
||||
@@ -59,7 +59,6 @@ extern int unloadLib (void);
|
||||
/* from sense.c */
|
||||
|
||||
extern int getValid (const sensors_chip_name *name, int feature, int *valid);
|
||||
extern int getLabel (const sensors_chip_name *name, int feature, char **label);
|
||||
extern int getRawLabel (const sensors_chip_name *name, int feature, const char **label);
|
||||
|
||||
extern int readChips (void);
|
||||
|
||||
@@ -91,7 +91,7 @@ void print_vid_info(const sensors_chip_name *name, int f_vid, int label_size)
|
||||
char *label;
|
||||
double vid;
|
||||
|
||||
if (!sensors_get_label(name, f_vid, &label)
|
||||
if ((label = sensors_get_label(name, f_vid))
|
||||
&& !sensors_get_feature(name, f_vid, &vid)) {
|
||||
print_label(label, label_size);
|
||||
printf("%+6.3f V\n", vid);
|
||||
@@ -108,7 +108,7 @@ void print_unknown_chip(const sensors_chip_name *name)
|
||||
|
||||
a = 0;
|
||||
while((data=sensors_get_all_features(name, &a))) {
|
||||
if (sensors_get_label(name, data->number, &label)) {
|
||||
if (!(label = sensors_get_label(name, data->number))) {
|
||||
printf("ERROR: Can't get feature `%s' data!\n",data->name);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ static int sensors_get_label_size(const sensors_chip_name *name)
|
||||
|
||||
i = 0;
|
||||
while((iter = sensors_get_all_features(name, &i))) {
|
||||
if (!sensors_get_label(name, iter->number, &label) &&
|
||||
if ((label = sensors_get_label(name, iter->number)) &&
|
||||
strlen(label) > max_size)
|
||||
max_size = strlen(label);
|
||||
free(label);
|
||||
@@ -98,7 +98,7 @@ static void print_generic_chip_temp(const sensors_chip_name *name,
|
||||
short has_features[SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP] = {0, };
|
||||
double feature_vals[SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP] = {0.0, };
|
||||
|
||||
if (sensors_get_label(name, feature->number, &label)) {
|
||||
if (!(label = sensors_get_label(name, feature->number))) {
|
||||
printf("ERROR: Can't get temperature label!\n");
|
||||
return;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ static void print_generic_chip_in(const sensors_chip_name *name,
|
||||
double val, alarm_max, alarm_min;
|
||||
char *label;
|
||||
|
||||
if (sensors_get_label(name, feature->number, &label)) {
|
||||
if (!(label = sensors_get_label(name, feature->number))) {
|
||||
printf("ERROR: Can't get in label!\n");
|
||||
return;
|
||||
}
|
||||
@@ -273,7 +273,7 @@ static void print_generic_chip_fan(const sensors_chip_name *name,
|
||||
double feature_vals[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN] = {0.0, };
|
||||
double val;
|
||||
|
||||
if (sensors_get_label(name, feature->number, &label)) {
|
||||
if (!(label = sensors_get_label(name, feature->number))) {
|
||||
printf("ERROR: Can't get fan label!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user