remove newline character from run_command() output accurately
raiz raiz@firemail.cc
Tue, 27 Dec 2016 18:57:27 +0300
1 files changed,
5 insertions(+),
1 deletions(-)
jump to
M
slstatus.c
→
slstatus.c
@@ -405,6 +405,7 @@
static char * run_command(const char *cmd) { + char *nlptr; FILE *fp; char buf[1024] = "n/a";@@ -415,8 +416,11 @@ return smprintf(UNKNOWN_STR);
} fgets(buf, sizeof(buf), fp); pclose(fp); + buf[strlen(buf)] = '\0'; - buf[strlen(buf)] = '\0'; + if ((nlptr = strstr(buf, "\n")) != NULL) { + nlptr[0] = '\0'; + } return smprintf("%s", buf); }