diff options
author | Sascha Schumann <sas@php.net> | 2000-05-23 15:13:16 +0000 |
---|---|---|
committer | Sascha Schumann <sas@php.net> | 2000-05-23 15:13:16 +0000 |
commit | 2aaa538aef24cd8140ff6aa80e544978dd7035fd (patch) | |
tree | 1aa8491f80a1d81bb80ca0f118b19f98e5b21163 /main/reentrancy.c | |
parent | be6afb3fccd20f2b0fab5816bc05362fb7e0326f (diff) | |
download | php-git-2aaa538aef24cd8140ff6aa80e544978dd7035fd.tar.gz |
Use reentrant version of readdir. If the target platform does not support
the POSIX-like readdir_r, we fall back to readdir. In ZTS mode, this will
cause php_readdir_r calls to be serialized.
Diffstat (limited to 'main/reentrancy.c')
-rw-r--r-- | main/reentrancy.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/main/reentrancy.c b/main/reentrancy.c index 77529feb5a..8a135508a5 100644 --- a/main/reentrancy.c +++ b/main/reentrancy.c @@ -17,7 +17,17 @@ */ +#include <sys/types.h> #include <string.h> +#include <errno.h> +#ifdef HAVE_DIRENT_H +#include <dirent.h> +#endif + +#ifdef PHP_WIN32 +#define NEEDRDH 1 +#include "win32/readdir.h" +#endif #include "php_reentrancy.h" #include "ext/standard/php_rand.h" /* for RAND_MAX */ @@ -27,6 +37,7 @@ enum { CTIME_R, ASCTIME_R, GMTIME_R, + READDIR_R, NUMBER_OF_LOCKS }; @@ -77,7 +88,37 @@ PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm) } #endif + +#if !defined(HAVE_POSIX_READDIR_R) + +PHPAPI int php_readdir_r(DIR *dirp, struct dirent *entry, + struct dirent **result) +{ + struct dirent *ptr; + int ret = 0; + + local_lock(READDIR_R); + + errno = 0; + ptr = readdir(dirp); + + if (!ptr && errno != 0) + ret = errno; + + if (entry && ptr) + memcpy(entry, ptr, sizeof(*ptr)); + + if (result) + *result = ptr; + + local_unlock(READDIR_R); + + return ret; +} + +#endif + #if !defined(HAVE_LOCALTIME_R) && defined(HAVE_LOCALTIME) PHPAPI struct tm *php_localtime_r(const time_t *const timep, struct tm *p_tm) |