diff options
author | David Robillard <d@drobilla.net> | 2015-10-07 18:25:01 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2015-10-07 18:25:01 +0000 |
commit | 2849229ebfb818fb867cd2fb327a8fb66be30723 (patch) | |
tree | 91093ef1a46aaf3ea331e8a07376aa716ac30ca9 | |
parent | 27c4df1b72eca00ec9519e9fbdc2110dfa07a07b (diff) | |
download | lilv-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
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/util.c | 13 |
2 files changed, 12 insertions, 4 deletions
@@ -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; @@ -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 |