introduce pa_realpath()
authorLennart Poettering <lennart@poettering.net>
Wed, 18 Feb 2009 20:57:57 +0000 (21:57 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 18 Feb 2009 20:57:57 +0000 (21:57 +0100)
src/pulsecore/core-util.c
src/pulsecore/core-util.h

index d0ff751..61f9a65 100644 (file)
@@ -2604,3 +2604,28 @@ char *pa_unescape(char *p) {
 
     return p;
 }
+
+char *pa_realpath(const char *path) {
+    char *r, *t;
+    pa_assert(path);
+
+    /* We want only abolsute paths */
+    if (path[0] != '/') {
+        errno = EINVAL;
+        return NULL;
+    }
+
+#ifndef __GLIBC__
+#error "It's not clear whether this system supports realpath(..., NULL) like GNU libc does. If it doesn't we need a private version of realpath() here."
+#endif
+
+    if (!(r = realpath(path, NULL)))
+        return NULL;
+
+    /* We copy this here in case our pa_xmalloc() is not implemented
+     * on top of libc malloc() */
+    t = pa_xstrdup(r);
+    pa_xfree(r);
+
+    return t;
+}
index 8fd521b..0ba33f3 100644 (file)
@@ -221,4 +221,6 @@ char *pa_replace(const char*s, const char*a, const char *b);
 
 char *pa_unescape(char *p);
 
+char *pa_realpath(const char *path);
+
 #endif