aboutsummaryrefslogtreecommitdiffstats
path: root/src/volume.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-14 18:15:33 +0100
committerMax Kellermann <max@duempel.org>2008-11-14 18:15:33 +0100
commit7720a1195ae9e90a427e0fc5d14023405d224b6a (patch)
tree7b327319f55c57eaf55b1ade7b4a61ee4aa5628e /src/volume.c
parent19131f1eda36594b748747b88568e70c5d356aa5 (diff)
downloadmpd-7720a1195ae9e90a427e0fc5d14023405d224b6a.tar.gz
mpd-7720a1195ae9e90a427e0fc5d14023405d224b6a.tar.xz
mpd-7720a1195ae9e90a427e0fc5d14023405d224b6a.zip
volume: eliminate alloca() usage
alloca() is not a portable function. Don't use it. Using strncasecmp() is much more efficient anyway, because no memory needs to be allocated and copied.
Diffstat (limited to 'src/volume.c')
-rw-r--r--src/volume.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/volume.c b/src/volume.c
index b1f7f186b..9fd33f010 100644
--- a/src/volume.c
+++ b/src/volume.c
@@ -79,8 +79,6 @@ static int volume_alsaSet = -1;
#ifdef HAVE_OSS
-#include <alloca.h> /* only alloca user in mpd atm, may change ... */
-
static void closeOssMixer(void)
{
while (close(volume_ossFd) && errno == EINTR) ;
@@ -91,17 +89,12 @@ static int
oss_find_mixer(const char *name)
{
const char *labels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS;
+ size_t name_length = strlen(name);
for (unsigned i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
- ssize_t len = strlen(labels[i]);
- char *duplicated = alloca(len + 1);
-
- /* eliminate spaces at the end */
- memcpy(duplicated, labels[i], len + 1);
- len -= 2;
- while (len >= 0 && duplicated[len] == ' ')
- duplicated[len--] = '\0';
- if (strcasecmp(duplicated, name) == 0)
+ if (strncasecmp(name, labels[i], name_length) == 0 &&
+ (labels[i][name_length] == 0 ||
+ labels[i][name_length] == ' '))
return i;
}