X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/bc38677f4734e9239d6f2dc3df8e4c56c330167a..ad03218fd54e01d612b19a0a569f440131cd5800:/slstatus.c?ds=inline diff --git a/slstatus.c b/slstatus.c index ea8fc20..a13bf3b 100644 --- a/slstatus.c +++ b/slstatus.c @@ -272,9 +272,7 @@ hostname(void) } fgets(hostname, sizeof(hostname), fp); - /* FIXME: needs improvement */ - memset(&hostname[strlen(hostname)], '\0', - sizeof(hostname) - strlen(hostname)); + hostname[strlen(hostname)-1] = '\0'; fclose(fp); return smprintf("%s", hostname); @@ -408,26 +406,18 @@ ram_used(void) static char * run_command(const char* command) { - int good; FILE *fp = popen(command, "r"); - char buffer[64] = ""; + char buffer[64] = '\0'; if (fp == NULL) { warn("Could not get command output for: %s", command); return smprintf(UNKNOWN_STR); } - fgets(buffer, sizeof(buffer)-1, fp); - pclose(fp); - for (int i = 0 ; i != sizeof(buffer); i++) { - if (buffer[i] == '\0') { - good = 1; - break; - } - } - if (good) - buffer[strlen(buffer)-1] = '\0'; + fgets(buffer, sizeof(buffer), fp); + buffer[sizeof(buffer)-1] = '\0'; + pclose(fp); return smprintf("%s", buffer); }