iio: Allow "0.0" as an offset
0.0 is a valid offset. https://bugzilla.redhat.com/show_bug.cgi?id=1978419#c11
This commit is contained in:
@@ -167,10 +167,11 @@ iioutils_get_param_float (float *output,
|
|||||||
g_free (builtname);
|
g_free (builtname);
|
||||||
|
|
||||||
if (g_file_get_contents (filename, &contents, NULL, &error)) {
|
if (g_file_get_contents (filename, &contents, NULL, &error)) {
|
||||||
*output = g_ascii_strtod (contents, NULL);
|
char *endptr;
|
||||||
if (*output != 0.0)
|
*output = g_ascii_strtod (contents, &endptr);
|
||||||
|
if (*output != 0.0 || endptr != contents)
|
||||||
return 0;
|
return 0;
|
||||||
g_warning ("Couldn't convert '%s' to float", g_strchomp (contents));
|
g_warning ("Couldn't convert '%s' from %s to float", g_strchomp (contents), filename);
|
||||||
g_clear_pointer (&contents, g_free);
|
g_clear_pointer (&contents, g_free);
|
||||||
} else {
|
} else {
|
||||||
g_debug ("Failed to read float from %s: %s", filename, error->message);
|
g_debug ("Failed to read float from %s: %s", filename, error->message);
|
||||||
@@ -185,15 +186,16 @@ iioutils_get_param_float (float *output,
|
|||||||
g_free (builtname);
|
g_free (builtname);
|
||||||
|
|
||||||
if (g_file_get_contents (filename, &contents, NULL, &error)) {
|
if (g_file_get_contents (filename, &contents, NULL, &error)) {
|
||||||
*output = g_ascii_strtod (contents, NULL);
|
char *endptr;
|
||||||
if (*output == 0.0) {
|
*output = g_ascii_strtod (contents, &endptr);
|
||||||
g_debug ("Failed to read float from %s", filename);
|
if (*output == 0.0 && endptr == contents) {
|
||||||
|
g_warning ("Couldn't convert '%s' from %s to float", g_strchomp (contents), filename);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
|
if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
g_debug ("Failed to read float from %s: %s", filename, error->message);
|
g_debug ("Failed to read float from non-existent %s", filename);
|
||||||
} else {
|
} else {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
g_warning ("Failed to read float from %s: %s", filename, error->message);
|
g_warning ("Failed to read float from %s: %s", filename, error->message);
|
||||||
|
Reference in New Issue
Block a user