summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-10-07 18:25:01 +0000
committerDavid Robillard <d@drobilla.net>2015-10-07 18:25:01 +0000
commit2849229ebfb818fb867cd2fb327a8fb66be30723 (patch)
tree91093ef1a46aaf3ea331e8a07376aa716ac30ca9 /src
parent27c4df1b72eca00ec9519e9fbdc2110dfa07a07b (diff)
downloadlilv-2849229ebfb818fb867cd2fb327a8fb66be30723.tar.gz
lilv-2849229ebfb818fb867cd2fb327a8fb66be30723.tar.bz2
lilv-2849229ebfb818fb867cd2fb327a8fb66be30723.zip
Fix directory walking on some systems
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@5750 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/util.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/util.c b/src/util.c
index 6c03a94..f9aed2d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -553,11 +553,18 @@ lilv_dir_for_each(const char* path,
#else
DIR* dir = opendir(path);
if (dir) {
- struct dirent entry;
+ long name_max = pathconf(path, _PC_NAME_MAX);
+ if (name_max == -1) {
+ name_max = 255; // Limit not defined, or error
+ }
+
+ const size_t len = offsetof(struct dirent, d_name) + name_max + 1;
+ struct dirent* entry = (struct dirent*)malloc(len);
struct dirent* result;
- while (!readdir_r(dir, &entry, &result) && result) {
- f(path, entry.d_name, data);
+ while (!readdir_r(dir, entry, &result) && result) {
+ f(path, entry->d_name, data);
}
+ free(entry);
closedir(dir);
}
#endif