mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
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
This commit is contained in:
parent
c627871fdb
commit
6eb2f88c5d
2 changed files with 36 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue