diff options
author | Aaron Marcher <info@nulltime.net> | 2016-10-09 13:50:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-09 13:50:02 +0200 |
commit | 5e7aa2a321c0a60c03021b0f25bec1c15a713dab (patch) | |
tree | 7682621299bd9d35dea516882208b1b36487b629 /slstatus.c | |
parent | 6239e5de17cd1e008f5dfc532d4549642217101c (diff) | |
parent | 4339c8330a3a9ac2a4000201a286cdda3808b4f6 (diff) |
Merge pull request #20 from R41z/master
fix division by zero in vol_perc, and hostname() rewrite
Diffstat (limited to 'slstatus.c')
-rw-r--r-- | slstatus.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -271,14 +271,10 @@ hostname(void) char buf[HOST_NAME_MAX]; FILE *fp; - fp = fopen("/proc/sys/kernel/hostname", "r"); - if (fp == NULL) { - warn("Failed to open file /proc/sys/kernel/hostname"); + if (gethostname(buf, sizeof(buf)) == -1) { + warn(1, "hostname"); return smprintf(UNKNOWN_STR); } - fgets(buf, sizeof(buf), fp); - buf[strlen(buf)-1] = '\0'; - fclose(fp); return smprintf("%s", buf); } @@ -501,7 +497,10 @@ vol_perc(const char *card) snd_mixer_selem_id_free(s_elem); snd_mixer_close(handle); - return smprintf("%d%%", ((uint_fast16_t)(vol * 100) / max)); + if (max == 0) + return smprintf("%d%%", 0); + else + return smprintf("%d%%", ((uint_fast16_t)(vol * 100) / max)); } static char * |