diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-10-29 15:32:22 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-10-29 15:32:22 +0000 |
commit | 27d6b7b4732f3678ecb6f1e5e53d440f1e8b2547 (patch) | |
tree | 1bfa866016cbd172bf92d494ae443f1dffd91fc3 | |
parent | ca98c544ab7a26bfc840d1470f467a7dea06238c (diff) |
make use of new pa_readlink() where applicable
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1975 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r-- | src/modules/oss-util.c | 32 | ||||
-rw-r--r-- | src/pulse/util.c | 11 |
2 files changed, 27 insertions, 16 deletions
diff --git a/src/modules/oss-util.c b/src/modules/oss-util.c index 25e45a35..015db4ca 100644 --- a/src/modules/oss-util.c +++ b/src/modules/oss-util.c @@ -293,29 +293,39 @@ int pa_oss_set_volume(int fd, long mixer, const pa_sample_spec *ss, const pa_cvo } static int get_device_number(const char *dev) { - char buf[PATH_MAX]; const char *p, *e; + char *rp = NULL; + int r; - if (readlink(dev, buf, sizeof(buf)) < 0) { - if (errno != EINVAL && errno != ENOLINK) - return -1; + if (!(p = rp = pa_readlink(dev))) { + if (errno != EINVAL && errno != ENOLINK) { + r = -1; + goto finish; + } p = dev; - } else - p = buf; + } if ((e = strrchr(p, '/'))) p = e+1; - if (p == 0) - return 0; + if (p == 0) { + r = 0; + goto finish; + } p = strchr(p, 0) -1; - if (*p >= '0' && *p <= '9') - return *p - '0'; + if (*p >= '0' && *p <= '9') { + r = *p - '0'; + goto finish; + } - return -1; + r = -1; + +finish: + pa_xfree(rp); + return r; } int pa_oss_get_hw_description(const char *dev, char *name, size_t l) { diff --git a/src/pulse/util.c b/src/pulse/util.c index 5dbb670b..d3ac9f66 100644 --- a/src/pulse/util.c +++ b/src/pulse/util.c @@ -55,6 +55,7 @@ #include <sys/prctl.h> #endif +#include <pulse/xmalloc.h> #include <pulsecore/winsock.h> #include <pulsecore/core-error.h> #include <pulsecore/log.h> @@ -172,13 +173,13 @@ char *pa_get_binary_name(char *s, size_t l) { #ifdef __linux__ { - int i; - char path[PATH_MAX]; + char *rp; /* This works on Linux only */ - if ((i = readlink("/proc/self/exe", path, sizeof(path)-1)) >= 0) { - path[i] = 0; - return pa_strlcpy(s, pa_path_get_filename(path), l); + if ((rp = pa_readlink("/proc/self/exe"))) { + pa_strlcpy(s, pa_path_get_filename(rp), l); + pa_xfree(rp); + return s; } } |