]> granicus.if.org Git - php/commitdiff
Add POSIX-like readdir_r for Win32
authorSascha Schumann <sas@php.net>
Tue, 23 May 2000 14:58:43 +0000 (14:58 +0000)
committerSascha Schumann <sas@php.net>
Tue, 23 May 2000 14:58:43 +0000 (14:58 +0000)
main/config.w32.h
win32/readdir.c
win32/readdir.h

index 1e0e46f5fd99235b42bb7d0b11870b889b58aaa5..d7361ce8b285818f1132018c3e8872a5b01d08a8 100644 (file)
@@ -96,6 +96,7 @@
 
 
 #define HAVE_GETCWD 1
+#define HAVE_POSIX_READDIR_R 1
 
 #define NEED_ISBLANK 1
 /* ----------------------------------------------------------------
index 5a680ff5a7445ad1e063d472c1e79643984e031f..a9cfa3a5133a33369edbff92727c336c6fc7a387 100644 (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;
index d7edb586f5361d2f0cda90e2606456fbaeb6b066..c2c969842aab5b88e9878cac4d663329d46f9f2e 100644 (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 *);