summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/target/hosted/agptek/sysfs.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/firmware/target/hosted/agptek/sysfs.c b/firmware/target/hosted/agptek/sysfs.c
index ad4635ac57..177f338911 100644
--- a/firmware/target/hosted/agptek/sysfs.c
+++ b/firmware/target/hosted/agptek/sysfs.c
@@ -85,7 +85,7 @@ bool sysfs_set_int(const char *path, int value)
85 } 85 }
86 86
87 bool success = true; 87 bool success = true;
88 if(fprintf(f, "%d", value) < 1) 88 if(fprintf(f, "%d", value) < 0)
89 { 89 {
90 DEBUGF("ERROR %s: Write failed for %s.", __func__, path); 90 DEBUGF("ERROR %s: Write failed for %s.", __func__, path);
91 success = false; 91 success = false;
@@ -98,7 +98,7 @@ bool sysfs_set_int(const char *path, int value)
98 98
99bool sysfs_get_char(const char *path, char *value) 99bool sysfs_get_char(const char *path, char *value)
100{ 100{
101 *value = '\0'; 101 int c;
102 FILE *f = open_read(path); 102 FILE *f = open_read(path);
103 if(f == NULL) 103 if(f == NULL)
104 { 104 {
@@ -106,11 +106,17 @@ bool sysfs_get_char(const char *path, char *value)
106 } 106 }
107 107
108 bool success = true; 108 bool success = true;
109 if(fscanf(f, "%c", value) == EOF) 109 c = fgetc(f);
110
111 if(c == EOF)
110 { 112 {
111 DEBUGF("ERROR %s: Read failed for %s.", __func__, path); 113 DEBUGF("ERROR %s: Read failed for %s.", __func__, path);
112 success = false; 114 success = false;
113 } 115 }
116 else
117 {
118 *value = c;
119 }
114 120
115 fclose(f); 121 fclose(f);
116 return success; 122 return success;
@@ -147,7 +153,13 @@ bool sysfs_get_string(const char *path, char *value, int size)
147 } 153 }
148 154
149 bool success = true; 155 bool success = true;
150 if(fgets(value, size, f) == NULL) 156
157 /* fgets returns NULL if en error occured OR
158 * when EOF occurs while no characters have been read.
159 *
160 * Empty string is not an error for us.
161 */
162 if(fgets(value, size, f) == NULL && value[0] != '\0')
151 { 163 {
152 DEBUGF("ERROR %s: Read failed for %s.", __func__, path); 164 DEBUGF("ERROR %s: Read failed for %s.", __func__, path);
153 success = false; 165 success = false;
@@ -175,7 +187,9 @@ bool sysfs_set_string(const char *path, char *value)
175 } 187 }
176 188
177 bool success = true; 189 bool success = true;
178 if(fprintf(f, "%s", value) < 1) 190
191 /* If an output error is encountered, a negative value is returned */
192 if(fprintf(f, "%s", value) < 0)
179 { 193 {
180 DEBUGF("ERROR %s: Write failed for %s.", __func__, path); 194 DEBUGF("ERROR %s: Write failed for %s.", __func__, path);
181 success = false; 195 success = false;