diff options
author | Yann Ylavic <ylavic@apache.org> | 2019-03-25 13:08:44 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2019-03-25 13:08:44 +0000 |
commit | e0114bf183e1550becd8c152c964cecadd4c14c3 (patch) | |
tree | d1551768538cfccd0445a3c1a58f228490db5a0d | |
parent | 97601b05c47214f931613fbb8823812b76568fd4 (diff) | |
download | apr-e0114bf183e1550becd8c152c964cecadd4c14c3.tar.gz |
Follow up to r1789258: configure to detect whether readdir() is thread-safe.
On platforms where readdir_r() is available but deprecated, readdir() is to
be used although it's not in libc_r (e.g. Linux has no libc_r).
In this case we can APR_TRY_COMPILE_NO_WARNING readdir_r() and, if it's
deprecated, define READDIR_IS_THREAD_SAFE.
With this we don't need user-defined APR_USE_READDIR{,64}_R from r1789258.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1856189 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | configure.in | 24 | ||||
-rw-r--r-- | file_io/unix/dir.c | 4 |
2 files changed, 24 insertions, 4 deletions
diff --git a/configure.in b/configure.in index a55106977..a7ae4ceaf 100644 --- a/configure.in +++ b/configure.in @@ -845,8 +845,30 @@ ac_cv_define_GETSERVBYNAME_IS_THREAD_SAFE=no if test "$threads" = "1"; then AC_MSG_NOTICE([APR will use threads]) AC_CHECK_LIB(c_r, readdir, + apr_readdir_is_thread_safe=yes) + if test "x$apr_readdir_is_thread_safe" = "x"; then + AC_CHECK_HEADERS(dirent.h) + AC_CHECK_FUNCS(readdir_r) + APR_IFALLYES(header:dirent.h func:readdir_r, + apr_has_readdir_r="1", apr_has_readdir_r="0") + if test "$apr_has_readdir_r" = "1"; then + dnl readdir_r() may exist but be deprecated, meaning + dnl the readdir() itself is thread-safe + APR_TRY_COMPILE_NO_WARNING([ + #include <dirent.h> + ], + [ + DIR *dir = opendir("/tmp"); + struct dirent entry, *result; + return readdir_r(dir, &entry, &result) != 0; + ], apr_readdir_is_thread_safe=no, apr_readdir_is_thread_safe=yes) + fi + fi + if test "$apr_readdir_is_thread_safe" = "yes"; then + AC_MSG_NOTICE([APR will use thread-safe readdir()]) AC_DEFINE(READDIR_IS_THREAD_SAFE, 1, - [Define if readdir is thread safe])) + [Define if readdir is thread safe]) + fi if test "x$apr_gethostbyname_is_thread_safe" = "x"; then AC_CHECK_LIB(c_r, gethostbyname, apr_gethostbyname_is_thread_safe=yes) fi diff --git a/file_io/unix/dir.c b/file_io/unix/dir.c index a94eb8e7f..9b2a6e0cd 100644 --- a/file_io/unix/dir.c +++ b/file_io/unix/dir.c @@ -138,9 +138,7 @@ apr_status_t apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted, apr_filetype_e type; #endif #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) \ - && !defined(READDIR_IS_THREAD_SAFE) \ - && (defined(APR_USE_READDIR64_R) \ - || defined(APR_USE_READDIR_R)) + && !defined(READDIR_IS_THREAD_SAFE) #ifdef APR_USE_READDIR64_R struct dirent64 *retent; |