X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/3bfc3bbcae41c58cc527ee074468afc83ef1a9ab..e1c5476291cf35693c072327cc5a0261983e1573:/slstatus.c diff --git a/slstatus.c b/slstatus.c index 73e0f2c..b593765 100644 --- a/slstatus.c +++ b/slstatus.c @@ -405,8 +405,9 @@ ram_used(void) static char * run_command(const char *cmd) { + char *nlptr; FILE *fp; - char buf[1024] = "n/a"; + char buf[1024] = UNKNOWN_STR; fp = popen(cmd, "r"); if (fp == NULL) { @@ -415,9 +416,12 @@ run_command(const char *cmd) } fgets(buf, sizeof(buf), fp); pclose(fp); - buf[strlen(buf)] = '\0'; + if ((nlptr = strstr(buf, "\n")) != NULL) { + nlptr[0] = '\0'; + } + return smprintf("%s", buf); }