summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools.c b/tools.c
new file mode 100644
index 0000000..45d9f12
--- /dev/null
+++ b/tools.c
@@ -0,0 +1,43 @@
+/*
+ * See the README file for copyright information and how to reach the author.
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "tools.h"
+
+bool cSysFs::Write(const char *path, const char *value)
+{
+ int fd = open(path, O_RDWR, 0644);
+ if (fd >= 0)
+ {
+ int ret = write(fd, value, strlen(value));
+ if (ret < 0)
+ ELOG("failed to write %s to %s (-%d)", value, path, errno);
+ close(fd);
+ return true;
+ }
+ return false;
+}
+
+bool cSysFs::Write(const char *path, int value)
+{
+ int fd = open(path, O_RDWR, 0644);
+ if (fd >= 0)
+ {
+ char cmd[64];
+ snprintf(cmd, sizeof(cmd), "%d", value);
+
+ int ret = write(fd, cmd, strlen(cmd));
+ if (ret < 0)
+ ELOG("failed to write %d to %s (-%d)", value, path, errno);
+ close(fd);
+ return true;
+ }
+ return false;
+}