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 /src | |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/util.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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 |