From: Lennart Poettering Date: Fri, 31 Aug 2007 00:51:01 +0000 (+0000) Subject: add two new functions pa_make_path_absolute()/pa_getcwd() X-Git-Tag: 1.0_branch~2762^2~1^2~233 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6eb2f88c5dc4c74634774aa242961b1630c0419c;p=profile%2Fivi%2Fpulseaudio.git add two new functions pa_make_path_absolute()/pa_getcwd() git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1737 fefdeb5f-60dc-0310-8127-8f9354f1896f --- diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 2c5a32e..82c0ea3 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1208,3 +1208,36 @@ char *pa_truncate_utf8(char *c, size_t l) { return c; } + +char *pa_getcwd(void) { + size_t l = 128; + + for (;;) { + char *p = pa_xnew(char, l); + if (getcwd(p, l)) + return p; + + if (errno != ERANGE) + return NULL; + + pa_xfree(p); + l *= 2; + } +} + +char *pa_make_path_absolute(const char *p) { + char *r; + char *cwd; + + pa_assert(p); + + if (p[0] == '/') + return pa_xstrdup(p); + + if (!(cwd = pa_getcwd())) + return pa_xstrdup(p); + + r = pa_sprintf_malloc("%s/%s", cwd, p); + pa_xfree(cwd); + return r; +} diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index ea571e7..5474928 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -97,6 +97,9 @@ int pa_snprintf(char *str, size_t size, const char *format, ...); char *pa_truncate_utf8(char *c, size_t l); +char *pa_getcwd(void); +char *pa_make_path_absolute(const char *p); + static inline int pa_is_power_of_two(unsigned n) { return !(n & (n - 1)); }