]> git.sur5r.net Git - i3/i3status/blobdiff - src/general.c
battery info: output errors in JSON in every case
[i3/i3status] / src / general.c
index a093c160d73eb874645f5a1702eda143f6859cea..bf7afd1ec25b24c972a1db531a179e6a4f98a4ba 100644 (file)
  * Reads size bytes into the destination buffer from filename.
  *
  */
-bool slurp(char *filename, char *destination, int size) {
+bool slurp(const char *filename, char *destination, int size) {
         int fd;
 
         if ((fd = open(filename, O_RDONLY)) == -1)
                 return false;
 
-        (void)read(fd, destination, size);
+        int n = read(fd, destination, size);
+        if (n != -1)
+                destination[n] = '\0';
         (void)close(fd);
 
         return true;