mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 13:12:37 -05:00
Agptek: Fix support for empty strings in sysfs helper functions
Change-Id: Id5573059da2b454f5336b3cebce7c09a83a7826f
This commit is contained in:
parent
d64ff86fb6
commit
971001d141
1 changed files with 19 additions and 5 deletions
|
|
@ -85,7 +85,7 @@ bool sysfs_set_int(const char *path, int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
if(fprintf(f, "%d", value) < 1)
|
if(fprintf(f, "%d", value) < 0)
|
||||||
{
|
{
|
||||||
DEBUGF("ERROR %s: Write failed for %s.", __func__, path);
|
DEBUGF("ERROR %s: Write failed for %s.", __func__, path);
|
||||||
success = false;
|
success = false;
|
||||||
|
|
@ -98,7 +98,7 @@ bool sysfs_set_int(const char *path, int value)
|
||||||
|
|
||||||
bool sysfs_get_char(const char *path, char *value)
|
bool sysfs_get_char(const char *path, char *value)
|
||||||
{
|
{
|
||||||
*value = '\0';
|
int c;
|
||||||
FILE *f = open_read(path);
|
FILE *f = open_read(path);
|
||||||
if(f == NULL)
|
if(f == NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -106,11 +106,17 @@ bool sysfs_get_char(const char *path, char *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
if(fscanf(f, "%c", value) == EOF)
|
c = fgetc(f);
|
||||||
|
|
||||||
|
if(c == EOF)
|
||||||
{
|
{
|
||||||
DEBUGF("ERROR %s: Read failed for %s.", __func__, path);
|
DEBUGF("ERROR %s: Read failed for %s.", __func__, path);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*value = c;
|
||||||
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return success;
|
return success;
|
||||||
|
|
@ -147,7 +153,13 @@ bool sysfs_get_string(const char *path, char *value, int size)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
if(fgets(value, size, f) == NULL)
|
|
||||||
|
/* fgets returns NULL if en error occured OR
|
||||||
|
* when EOF occurs while no characters have been read.
|
||||||
|
*
|
||||||
|
* Empty string is not an error for us.
|
||||||
|
*/
|
||||||
|
if(fgets(value, size, f) == NULL && value[0] != '\0')
|
||||||
{
|
{
|
||||||
DEBUGF("ERROR %s: Read failed for %s.", __func__, path);
|
DEBUGF("ERROR %s: Read failed for %s.", __func__, path);
|
||||||
success = false;
|
success = false;
|
||||||
|
|
@ -175,7 +187,9 @@ bool sysfs_set_string(const char *path, char *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
if(fprintf(f, "%s", value) < 1)
|
|
||||||
|
/* If an output error is encountered, a negative value is returned */
|
||||||
|
if(fprintf(f, "%s", value) < 0)
|
||||||
{
|
{
|
||||||
DEBUGF("ERROR %s: Write failed for %s.", __func__, path);
|
DEBUGF("ERROR %s: Write failed for %s.", __func__, path);
|
||||||
success = false;
|
success = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue