summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-01-08 04:18:00 +0000
committerDavid Robillard <d@drobilla.net>2012-01-08 04:18:00 +0000
commit1c18b0ba64be0e03867b95dff80bed3b4568c57b (patch)
tree6f626222a021dc64cb4803dca91793b4f63befd9 /src/util.c
parentc8d1e0d49e2808e225e496cff0cfc8d0de72adc9 (diff)
downloadlilv-1c18b0ba64be0e03867b95dff80bed3b4568c57b.tar.gz
lilv-1c18b0ba64be0e03867b95dff80bed3b4568c57b.tar.bz2
lilv-1c18b0ba64be0e03867b95dff80bed3b4568c57b.zip
Move all non-portable stuff to util.c.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3921 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c39
1 files changed, 37 insertions, 2 deletions
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 <assert.h>
#include <errno.h>
@@ -27,12 +28,12 @@
#include <sys/types.h>
#include <unistd.h>
+#include "lilv_internal.h"
+
#if defined(HAVE_FLOCK) && defined(HAVE_FILENO)
# include <sys/file.h>
#endif
-#include "lilv_internal.h"
-
#ifdef HAVE_WORDEXP
# include <wordexp.h>
#endif
@@ -306,6 +307,18 @@ lilv_get_latest_copy(const char* path)
}
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)
{
const size_t path_len = strlen(path);
@@ -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;
+}