1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Add POSIX-like readdir_r for Win32

This commit is contained in:
Sascha Schumann
2000-05-23 14:58:43 +00:00
parent 22dba603f5
commit be6afb3fcc
3 changed files with 36 additions and 2 deletions

View File

@@ -96,6 +96,7 @@
#define HAVE_GETCWD 1
#define HAVE_POSIX_READDIR_R 1
#define NEED_ISBLANK 1
/* ----------------------------------------------------------------

View File

@@ -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;

View File

@@ -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 *);