diff options
author | Sascha Schumann <sas@php.net> | 2000-05-23 14:58:43 +0000 |
---|---|---|
committer | Sascha Schumann <sas@php.net> | 2000-05-23 14:58:43 +0000 |
commit | be6afb3fccd20f2b0fab5816bc05362fb7e0326f (patch) | |
tree | 0c8da2594fd0a96b2de561b0c50f94646d75a152 /win32 | |
parent | 22dba603f5f113c8fce1c253e7754eebc564d7ab (diff) | |
download | php-git-be6afb3fccd20f2b0fab5816bc05362fb7e0326f.tar.gz |
Add POSIX-like readdir_r for Win32
Diffstat (limited to 'win32')
-rw-r--r-- | win32/readdir.c | 36 | ||||
-rw-r--r-- | win32/readdir.h | 1 |
2 files changed, 35 insertions, 2 deletions
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 *); |