X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/5e7aa2a321c0a60c03021b0f25bec1c15a713dab..6890a27a3a4b0ac5f57d1fe554db0dbb90909072:/slstatus.c?ds=sidebyside diff --git a/slstatus.c b/slstatus.c index 6417305..57ef9a9 100644 --- a/slstatus.c +++ b/slstatus.c @@ -269,10 +269,9 @@ static char * hostname(void) { char buf[HOST_NAME_MAX]; - FILE *fp; if (gethostname(buf, sizeof(buf)) == -1) { - warn(1, "hostname"); + warn("hostname"); return smprintf(UNKNOWN_STR); } @@ -401,17 +400,19 @@ static char * run_command(const char *cmd) { FILE *fp; - char buf[64] = "n/a"; + char buf[1024] = "n/a"; fp = popen(cmd, "r"); if (fp == NULL) { warn("Failed to get command output for %s", cmd); return smprintf(UNKNOWN_STR); } - fgets(buf, sizeof(buf), fp); - buf[sizeof(buf)-1] = '\0'; + fgets(buf, sizeof(buf)-1, fp); pclose(fp); + buf[strlen(buf)] = '\0'; + strtok(buf, "\n"); + return smprintf("%s", buf); } @@ -498,9 +499,9 @@ vol_perc(const char *card) snd_mixer_close(handle); if (max == 0) - return smprintf("%d%%", 0); + return smprintf("0%%"); else - return smprintf("%d%%", ((uint_fast16_t)(vol * 100) / max)); + return smprintf("%lu%%", ((uint_fast16_t)(vol * 100) / max)); } static char *