diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-05-31 20:56:05 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-05-31 20:56:05 +0000 |
commit | a6c43c64d9419dfa888b1c478e658e3e20a4af11 (patch) | |
tree | c44233797692f5a1878dfd1d614e5674a3c0e0a6 /file_io | |
parent | f7eb533f85d0941dbf6edb3081f065e4c010b8cc (diff) |
Notes
Diffstat (limited to 'file_io')
-rw-r--r-- | file_io/unix/dir.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/file_io/unix/dir.c b/file_io/unix/dir.c index 28d9e0699288..d9b344f3085b 100644 --- a/file_io/unix/dir.c +++ b/file_io/unix/dir.c @@ -24,6 +24,10 @@ #include <limits.h> #endif +#ifndef NAME_MAX +#define NAME_MAX 255 +#endif + static apr_status_t dir_cleanup(void *thedir) { apr_dir_t *dir = thedir; @@ -71,14 +75,6 @@ static char *path_remove_last_component (const char *path, apr_pool_t *pool) apr_status_t apr_dir_open(apr_dir_t **new, const char *dirname, apr_pool_t *pool) { - /* On some platforms (e.g., Linux+GNU libc), d_name[] in struct - * dirent is declared with enough storage for the name. On other - * platforms (e.g., Solaris 8 for Intel), d_name is declared as a - * one-byte array. Note: gcc evaluates this at compile time. - */ - apr_size_t dirent_size = - sizeof(*(*new)->entry) + - (sizeof((*new)->entry->d_name) > 1 ? 0 : 255); DIR *dir = opendir(dirname); if (!dir) { @@ -90,7 +86,20 @@ apr_status_t apr_dir_open(apr_dir_t **new, const char *dirname, (*new)->pool = pool; (*new)->dirname = apr_pstrdup(pool, dirname); (*new)->dirstruct = dir; - (*new)->entry = apr_pcalloc(pool, dirent_size); + +#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) \ + && !defined(READDIR_IS_THREAD_SAFE) + /* On some platforms (e.g., Linux+GNU libc), d_name[] in struct + * dirent is declared with enough storage for the name. On other + * platforms (e.g., Solaris 8 for Intel), d_name is declared as a + * one-byte array. Note: gcc evaluates this at compile time. + */ + (*new)->entry = apr_pcalloc(pool, sizeof(*(*new)->entry) + + (sizeof((*new)->entry->d_name) > 1 + ? 0 : NAME_MAX)); +#else + (*new)->entry = NULL; +#endif apr_pool_cleanup_register((*new)->pool, *new, dir_cleanup, apr_pool_cleanup_null); |