diff options
author | Aaron Marcher <info@nulltime.net> | 2017-04-20 22:30:04 +0200 |
---|---|---|
committer | Aaron Marcher <info@nulltime.net> | 2017-04-20 22:30:04 +0200 |
commit | d144c8de3d1db270722c52a8d34727e38c69dc91 (patch) | |
tree | 03dd368c4c3027b52405f0caadd29fe0d3bb3e8b /slstatus.c | |
parent | c288663ebdeb78ef50a6378651bb14380ed4b20a (diff) |
simplified and improved vol_perc()
Diffstat (limited to 'slstatus.c')
-rw-r--r-- | slstatus.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -667,17 +667,23 @@ vol_perc(const char *card) int v, afd, devmask; char *vnames[] = SOUND_DEVICE_NAMES; - afd = open(card, O_RDONLY); - if (afd < 0) { + afd = open(card, O_RDONLY | O_NONBLOCK); + if (afd == -1) { warn("Cannot open %s", card); return smprintf(UNKNOWN_STR); } - ioctl(afd, MIXER_READ(SOUND_MIXER_DEVMASK), &devmask); + if (ioctl(afd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) { + warn("Cannot get volume for %s", card); + close(afd); + return smprintf("%s", UNKNOWN_STR); + } for (i = 0; i < (sizeof(vnames) / sizeof((vnames[0]))); i++) { - if (devmask & (1 << i)) { - if (!strcmp("vol", vnames[i])) { - ioctl(afd, MIXER_READ(i), &v); + if (devmask & (1 << i) && !strcmp("vol", vnames[i])) { + if (ioctl(afd, MIXER_READ(i), &v) == -1) { + warn("vol_perc: ioctl"); + close(afd); + return smprintf("%s", UNKNOWN_STR); } } } |