summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--src/util.c13
2 files changed, 12 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 9b8567c..4dd6af7 100644
--- a/NEWS
+++ b/NEWS
@@ -18,11 +18,12 @@ lilv (0.21.5) unstable;
* Fix a few minor/unlikely memory errors
* Configure based on compiler target OS for cross-compilation
* Fix lilv_realpath() on pre-POSIX-2008 systems
+ * Fix directory walking on some systems (thanks Matt Fischer)
* Windows fixes (thanks John Emmas)
* Minor documentation improvements
* Upgrade to waf 1.8.14
- -- David Robillard <d@drobilla.net> Fri, 02 Oct 2015 20:55:32 -0400
+ -- David Robillard <d@drobilla.net> Wed, 07 Oct 2015 14:24:51 -0400
lilv (0.20.0) stable;
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