From: Sascha Schumann Date: Tue, 23 May 2000 14:58:43 +0000 (+0000) Subject: Add POSIX-like readdir_r for Win32 X-Git-Tag: PRE_EIGHT_BYTE_ALLOC_PATCH~312 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be6afb3fccd20f2b0fab5816bc05362fb7e0326f;p=php Add POSIX-like readdir_r for Win32 --- diff --git a/main/config.w32.h b/main/config.w32.h index 1e0e46f5fd..d7361ce8b2 100644 --- a/main/config.w32.h +++ b/main/config.w32.h @@ -96,6 +96,7 @@ #define HAVE_GETCWD 1 +#define HAVE_POSIX_READDIR_R 1 #define NEED_ISBLANK 1 /* ---------------------------------------------------------------- diff --git a/win32/readdir.c b/win32/readdir.c index 5a680ff5a7..a9cfa3a513 100644 --- a/win32/readdir.c +++ b/win32/readdir.c @@ -50,7 +50,7 @@ DIR *opendir(const char *dir) return dp; } -struct dirent *readdir(DIR * dp) +struct dirent *readdir(DIR *dp) { if (!dp || dp->finished) return NULL; @@ -71,7 +71,39 @@ struct dirent *readdir(DIR * dp) return &(dp->dent); } -int closedir(DIR * dp) +int readdir_r(DIR *dp, struct dirent *entry, struct dirent **result) +{ + if (!dp || dp->finished) { + if (result) + *result = NULL; + return 0; + } + + if (dp->offset != 0) { + if (_findnext(dp->handle, &(dp->fileinfo)) < 0) { + dp->finished = 1; + if (result) + *result = NULL; + return 0; + } + } + dp->offset++; + + strlcpy(dp->dent.d_name, dp->fileinfo.name, _MAX_FNAME+1); + dp->dent.d_ino = 1; + dp->dent.d_reclen = strlen(dp->dent.d_name); + dp->dent.d_off = dp->offset; + + if (entry) + memcpy(entry, &dp->dent, sizeof(*entry)); + + if (result) + *result = &dp->dent; + + return 0; +} + +int closedir(DIR *dp) { if (!dp) return 0; diff --git a/win32/readdir.h b/win32/readdir.h index d7edb586f5..c2c969842a 100644 --- a/win32/readdir.h +++ b/win32/readdir.h @@ -32,6 +32,7 @@ typedef struct { /* Function prototypes */ DIR *opendir(const char *); struct dirent *readdir(DIR *); +int readdir_r(DIR *, struct dirent *, struct dirent **); int closedir(DIR *); void rewinddir(DIR *);