Error handling was added to fputs()/fgets() functions.
Signed-off-by: Stanislaw Wadas <[email protected]>
---
Changes since v3:
- fixed code indentation
Changes since v2:
- fixed code indentation
- removed unused variable ret
Changes since v1:
- fixed typos in MAX_LENGTH throughout
src/gadget.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/gadget.c b/src/gadget.c
index fb86e7e..d226d32 100644
--- a/src/gadget.c
+++ b/src/gadget.c
@@ -93,6 +93,11 @@ static char *gadget_read_buf(char *path, char *name, char
*file, char *buf)
goto out;
ret = fgets(buf, MAX_LENGTH, fp);
+ if (ret == NULL) {
+ ERROR("read error");
+ fclose(fp);
+ return ret;
+ }
fclose(fp);
@@ -136,7 +141,11 @@ static void gadget_write_buf(char *path, char *name, char
*file, char *buf)
return;
}
- fputs(buf, fp);
+ if (fputs(buf, fp) == EOF) {
+ ERROR("write error");
+ fclose(fp);
+ return;
+ }
fclose(fp);
}
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html