You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2019/03/25 14:16:40 UTC
svn commit: r1856196 - /apr/apr/trunk/file_io/unix/dir.c
Author: ylavic
Date: Mon Mar 25 14:16:40 2019
New Revision: 1856196
URL: http://svn.apache.org/viewvc?rev=1856196&view=rev
Log:
apr_dir: no need to allocate our dir entry if readdir{,64}_r() is not used.
Modified:
apr/apr/trunk/file_io/unix/dir.c
Modified: apr/apr/trunk/file_io/unix/dir.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/dir.c?rev=1856196&r1=1856195&r2=1856196&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/dir.c (original)
+++ apr/apr/trunk/file_io/unix/dir.c Mon Mar 25 14:16:40 2019
@@ -75,14 +75,6 @@ static char *path_remove_last_component
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 : NAME_MAX);
DIR *dir = opendir(dirname);
if (!dir) {
@@ -94,7 +86,20 @@ apr_status_t apr_dir_open(apr_dir_t **ne
(*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);