]> git.sur5r.net Git - i3/i3status/blobdiff - src/general.c
removing Yoda-Style
[i3/i3status] / src / general.c
index 2ae90f135ed2dad3f6ff788e2905af0b345aa3f1..c5b33b46f652142dbfad53fdd7a73463c217fd37 100644 (file)
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/fcntl.h>
+#include <sys/stat.h>
 
 #include "i3status.h"
 
@@ -19,7 +20,10 @@ bool slurp(const char *filename, char *destination, int size) {
         if ((fd = open(filename, O_RDONLY)) == -1)
                 return false;
 
-        (void)read(fd, destination, size);
+        /* We need one byte for the trailing 0 byte */
+        int n = read(fd, destination, size-1);
+        if (n != -1)
+                destination[n] = '\0';
         (void)close(fd);
 
         return true;