[PATCH 1/6] lib: fwts_set: fix API for fwts_set, add fwts_set_int
Colin King
colin.king at canonical.com
Thu Jun 7 14:05:51 UTC 2018
From: Colin Ian King <colin.king at canonical.com>
The fwts_set API has the args the wrong way around compared to
fwts_get, so swap these; fortunately it is not being used yet
in fwts, so this won't break anything. Also add fwts_set_int
to set integer values in /sys or /proc files. Finally, add
error checking in case the writes to the file fails.
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/include/fwts_set.h | 3 ++-
src/lib/src/fwts_set.c | 26 +++++++++++++++++++++++---
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/lib/include/fwts_set.h b/src/lib/include/fwts_set.h
index 3182fc23..c74fd4c0 100644
--- a/src/lib/include/fwts_set.h
+++ b/src/lib/include/fwts_set.h
@@ -22,6 +22,7 @@
#include <stdio.h>
-int fwts_set(const char *text, const char *file);
+int fwts_set(const char *file, const char *text);
+int fwts_set_int(const char *file, const int value);
#endif
diff --git a/src/lib/src/fwts_set.c b/src/lib/src/fwts_set.c
index 08b26663..5e90b239 100644
--- a/src/lib/src/fwts_set.c
+++ b/src/lib/src/fwts_set.c
@@ -27,15 +27,35 @@
* write text to a given file, used to set
* values in /sys or /proc
*/
-int fwts_set(const char *text, const char *file)
+int fwts_set(const char *file, const char *text)
{
FILE *fp;
+ int ret;
if ((fp = fopen(file, "w")) == NULL)
return FWTS_ERROR;
- fprintf(fp, "%s\n", text);
+ ret = fprintf(fp, "%s\n", text);
(void)fclose(fp);
- return FWTS_OK;
+ return (ret < 0) ? FWTS_ERROR : FWTS_OK;
+}
+
+/*
+ * fwts_set_int()
+ * write an int to a given file, used to set
+ * values in /sys or /proc
+ */
+int fwts_set_int(const char *file, const int value)
+{
+ FILE *fp;
+ int ret;
+
+ if ((fp = fopen(file, "w")) == NULL)
+ return FWTS_ERROR;
+
+ ret = fprintf(fp, "%d\n", value);
+ (void)fclose(fp);
+
+ return (ret < 0) ? FWTS_ERROR : FWTS_OK;
}
--
2.17.0
More information about the fwts-devel
mailing list