From 1c18b0ba64be0e03867b95dff80bed3b4568c57b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 8 Jan 2012 04:18:00 +0000 Subject: Move all non-portable stuff to util.c. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3921 a436a847-0d15-0410-975c-d299462d15a1 --- src/util.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index 86300a1..526bf9b 100644 --- a/src/util.c +++ b/src/util.c @@ -15,6 +15,7 @@ */ #define _POSIX_SOURCE 1 /* for wordexp, fileno */ +#define _BSD_SOURCE 1 /* for realpath, symlink */ #include #include @@ -27,12 +28,12 @@ #include #include +#include "lilv_internal.h" + #if defined(HAVE_FLOCK) && defined(HAVE_FILENO) # include #endif -#include "lilv_internal.h" - #ifdef HAVE_WORDEXP # include #endif @@ -305,6 +306,18 @@ lilv_get_latest_copy(const char* path) return latest.latest; } +char* +lilv_realpath(const char* path) +{ + return realpath(path, NULL); +} + +int +lilv_symlink(const char* oldpath, const char* newpath) +{ + return symlink(oldpath, newpath); +} + char* lilv_path_relative_to(const char* path, const char* base) { @@ -378,3 +391,25 @@ lilv_dir_for_each(const char* path, closedir(dir); } } + +int +lilv_mkdir_p(const char* dir_path) +{ + char* path = lilv_strdup(dir_path); + const size_t path_len = strlen(path); + for (size_t i = 1; i <= path_len; ++i) { + if (path[i] == LILV_DIR_SEP[0] || path[i] == '\0') { + path[i] = '\0'; + if (mkdir(path, 0755) && errno != EEXIST) { + LILV_ERRORF("Failed to create %s (%s)\n", + path, strerror(errno)); + free(path); + return 1; + } + path[i] = LILV_DIR_SEP[0]; + } + } + + free(path); + return 0; +} -- cgit v1.2.1