From b7f4541506aac11a92d947939f6e9da8af49dd26 Mon Sep 17 00:00:00 2001 From: raiz Date: Tue, 27 Dec 2016 18:57:27 +0300 Subject: remove newline character from run_command() output accurately --- slstatus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'slstatus.c') diff --git a/slstatus.c b/slstatus.c index 73e0f2c..329093f 100644 --- a/slstatus.c +++ b/slstatus.c @@ -405,6 +405,7 @@ ram_used(void) static char * run_command(const char *cmd) { + char *nlptr; FILE *fp; char buf[1024] = "n/a"; @@ -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); } -- cgit v1.2.3