summaryrefslogtreecommitdiff
path: root/statuses/tools.c
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2012-02-14 01:27:32 +0000
committernorly <ny-git@enpas.org>2012-02-14 01:27:32 +0000
commit504ab94abcd8209ce96bcb747db7536f9d49c083 (patch)
treed8ddffea203769f5460348f74ac85c63c33c3f7e /statuses/tools.c
parent38a130597b1f52028f7df79ab5f348dc306afa85 (diff)
Cleaned up 'netif'.
Replaced 'netif' with 'netif_named'. Fixed memory leak in new 'netif'. Outsourced raw file reading to tools.c.
Diffstat (limited to 'statuses/tools.c')
-rw-r--r--statuses/tools.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/statuses/tools.c b/statuses/tools.c
index 1e0385d..7a4a677 100644
--- a/statuses/tools.c
+++ b/statuses/tools.c
@@ -1,6 +1,9 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "tools.h"
-char powertochar(int power)
+char powerToChar(int power)
{
switch(power)
{
@@ -19,6 +22,36 @@ char powertochar(int power)
case 6:
return 'E';
}
-
+
return '?';
}
+
+
+void statusError(char *where, char *what, char *extra)
+{
+ fprintf(stderr, "%s: %s", where, what);
+ if (extra)
+ fprintf(stderr, " -- %s", extra);
+ fputs("\n", stderr);
+}
+
+
+ssize_t fileRead(char *buf, size_t bufsize, char *file)
+{
+ int fd;
+ int readbytes;
+
+ fd = open(file, 0);
+ if (fd < 0)
+ return -1;
+
+ readbytes = read(fd, buf, bufsize - 1);
+ close(fd);
+
+ if (readbytes > 0)
+ buf[readbytes] = '\0';
+ else
+ buf[0] = '\0';
+
+ return readbytes;
+} \ No newline at end of file