diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-10-29 15:31:24 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-10-29 15:31:24 +0000 |
commit | ca98c544ab7a26bfc840d1470f467a7dea06238c (patch) | |
tree | 0dc1ab956962335bc2677563e496a459e6d8d004 /src/pulsecore | |
parent | 1c0690776d45c50b90df037669b4dbfe0467ca8a (diff) |
add new pa_readlink() API
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1974 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/pulsecore')
-rw-r--r-- | src/pulsecore/core-util.c | 24 | ||||
-rw-r--r-- | src/pulsecore/core-util.h | 2 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index a644b664..4962112b 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1507,3 +1507,27 @@ void pa_close_pipe(int fds[2]) { fds[0] = fds[1] = -1; } + +char *pa_readlink(const char *p) { + size_t l = 100; + + for (;;) { + char *c; + ssize_t n; + + c = pa_xnew(char, l); + + if ((n = readlink(p, c, l-1)) < 0) { + pa_xfree(c); + return NULL; + } + + if (n < l-1) { + c[l-1] = 0; + return c; + } + + pa_xfree(c); + l *= 2; + } +} diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 0fe865ec..d26cf241 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -122,4 +122,6 @@ static inline unsigned pa_make_power_of_two(unsigned n) { void pa_close_pipe(int fds[2]); +char *pa_readlink(const char *p); + #endif |