summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2019-03-25 13:08:44 +0000
committerylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2019-03-25 13:08:44 +0000
commita673893504c38f3cc97373bf0d909a015c530401 (patch)
treed1551768538cfccd0445a3c1a58f228490db5a0d
parent13b17fd38bbe12d3b8653a9c50fea70999ec7656 (diff)
downloadlibapr-a673893504c38f3cc97373bf0d909a015c530401.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: http://svn.apache.org/repos/asf/apr/apr/trunk@1856189 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--configure.in24
-rw-r--r--file_io/unix/dir.c4
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;