summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-04-22 20:05:01 +0000
committerLennart Poettering <lennart@poettering.net>2006-04-22 20:05:01 +0000
commita4fedcf2dc67a946354ea003424deb3c2489f7fc (patch)
tree5bda03ccc23607ac52419e1dae2ae19e16c7876e /src
parent513df3b9f8af35d11bbdc44d0dcbc9ab35fd1465 (diff)
add new function pa_parent_dir()
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@773 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src')
-rw-r--r--src/polypcore/util.c19
-rw-r--r--src/polypcore/util.h2
2 files changed, 16 insertions, 5 deletions
diff --git a/src/polypcore/util.c b/src/polypcore/util.c
index 8418a692..615ea881 100644
--- a/src/polypcore/util.c
+++ b/src/polypcore/util.c
@@ -164,15 +164,25 @@ fail:
return -1;
}
-/* Creates a the parent directory of the specified path securely */
-int pa_make_secure_parent_dir(const char *fn) {
- int ret = -1;
+/* Return a newly allocated sting containing the parent directory of the specified file */
+char *pa_parent_dir(const char *fn) {
char *slash, *dir = pa_xstrdup(fn);
slash = (char*) pa_path_get_filename(dir);
if (slash == fn)
- goto finish;
+ return NULL;
+
*(slash-1) = 0;
+ return dir;
+}
+
+/* Creates a the parent directory of the specified path securely */
+int pa_make_secure_parent_dir(const char *fn) {
+ int ret = -1;
+ char *dir;
+
+ if (!(dir = pa_parent_dir(fn)))
+ goto finish;
if (pa_make_secure_dir(dir) < 0)
goto finish;
@@ -184,7 +194,6 @@ finish:
return ret;
}
-
/** Calls read() in a loop. Makes sure that as much as 'size' bytes,
* unless EOF is reached or an error occured */
ssize_t pa_loop_read(int fd, void*data, size_t size) {
diff --git a/src/polypcore/util.h b/src/polypcore/util.h
index f05339c4..ca81b229 100644
--- a/src/polypcore/util.h
+++ b/src/polypcore/util.h
@@ -55,6 +55,8 @@ char *pa_get_home_dir(char *s, size_t l);
const char *pa_path_get_filename(const char *p);
+char *pa_parent_dir(const char *fn);
+
struct timeval *pa_gettimeofday(struct timeval *tv);
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);