slstatus

Fork of suckless' slstatus with my personal patches
git clone https://git.instinctive.eu/slstatus.git
Log | Files | Refs | README | LICENSE

cat.c (652B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <stdio.h>
      3 #include <string.h>
      4 
      5 #include "../slstatus.h"
      6 #include "../util.h"
      7 
      8 const char *
      9 cat(const char *path)
     10 {
     11         char *f;
     12         FILE *fp;
     13 
     14         if (!(fp = fopen(path, "r"))) {
     15                 warn("fopen '%s':", path);
     16                 return NULL;
     17         }
     18 
     19         f = fgets(buf, sizeof(buf) - 1, fp);
     20         if (fclose(fp) < 0) {
     21                 warn("fclose '%s':", path);
     22                 return NULL;
     23         }
     24         if (!f)
     25                 return NULL;
     26 
     27         if ((f = strrchr(buf, '\n')))
     28                 f[0] = '\0';
     29 
     30         return buf[0] ? buf : NULL;
     31 }
     32