summaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-01-08 03:55:00 +0000
committerDavid Robillard <d@drobilla.net>2012-01-08 03:55:00 +0000
commitc8d1e0d49e2808e225e496cff0cfc8d0de72adc9 (patch)
tree88966c4aa03bee4d417085e060eb125838b750a1 /src/world.c
parent47bdfa160502acc78cb90f350258fe975e4f956f (diff)
downloadlilv-c8d1e0d49e2808e225e496cff0cfc8d0de72adc9.tar.gz
lilv-c8d1e0d49e2808e225e496cff0cfc8d0de72adc9.tar.bz2
lilv-c8d1e0d49e2808e225e496cff0cfc8d0de72adc9.zip
Localise directory traversal stuff.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3920 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/src/world.c b/src/world.c
index 32e4f63..6d223cb 100644
--- a/src/world.c
+++ b/src/world.c
@@ -14,15 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define _POSIX_SOURCE 1 /* for readdir_r */
-
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <dirent.h>
-
#include "lilv_internal.h"
LILV_API
@@ -549,6 +545,22 @@ lilv_world_load_bundle(LilvWorld* world, LilvNode* bundle_uri)
serd_node_free(&manifest_uri);
}
+static void
+load_dir_entry(const char* dir, const char* name, void* data)
+{
+ LilvWorld* world = (LilvWorld*)data;
+ if (!strcmp(name, ".") || !strcmp(name, ".."))
+ return;
+
+ const char* scheme = (dir[0] == '/') ? "file://" : "file:///";
+ char* uri = lilv_strjoin(scheme, dir, "/", name, "/", NULL);
+ LilvNode* uri_val = lilv_new_uri(world, uri);
+
+ lilv_world_load_bundle(world, uri_val);
+ lilv_node_free(uri_val);
+ free(uri);
+}
+
/** Load all bundles in the directory at @a dir_path. */
static void
lilv_world_load_directory(LilvWorld* world, const char* dir_path)
@@ -559,38 +571,7 @@ lilv_world_load_directory(LilvWorld* world, const char* dir_path)
return;
}
- DIR* pdir = opendir(path);
- if (!pdir) {
- free(path);
- return;
- }
-
-#ifdef __WIN32__
- static const char* const file_scheme = "file:///";
-#else
- static const char* const file_scheme = "file://";
-#endif
-
- struct dirent entry;
- struct dirent* result;
- while (!readdir_r(pdir, &entry, &result) && result) {
- if (!strcmp(entry.d_name, ".") || !strcmp(entry.d_name, ".."))
- continue;
-
- char* uri = lilv_strjoin(file_scheme,
- path, "/",
- entry.d_name, "/",
- NULL);
-
- LilvNode* uri_val = lilv_new_uri(world, uri);
- lilv_world_load_bundle(world, uri_val);
- lilv_node_free(uri_val);
-
- free(uri);
- }
-
- free(path);
- closedir(pdir);
+ lilv_dir_for_each(path, world, load_dir_entry);
}
static bool