Xinqi Bao's Git

Add the percent sign to *_perc functions
[slstatus.git] / components / run_command.c
1 /* See LICENSE file for copyright and license details. */
2 #include <errno.h>
3 #include <stdio.h>
4 #include <string.h>
5
6 #include "../util.h"
7
8 const char *
9 run_command(const char *cmd)
10 {
11 char *p;
12 FILE *fp;
13
14 if (!(fp = popen(cmd, "r"))) {
15 warn("popen '%s':", cmd);
16 return NULL;
17 }
18 p = fgets(buf, sizeof(buf) - 1, fp);
19 pclose(fp);
20 if (!p) {
21 return NULL;
22 }
23 if ((p = strrchr(buf, '\n'))) {
24 p[0] = '\0';
25 }
26
27 return buf[0] ? buf : NULL;
28 }