diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2003-01-27 20:39:31 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2003-01-27 20:39:31 +0000 |
commit | d59d500af7204cf419d91553dccfc2ff0069ca65 (patch) | |
tree | 4a7db0482e34008067657447c3e5c1cc19e34215 /win32/readdir.c | |
parent | e4ec7372e951f11c1d5696605858e404434782a9 (diff) | |
download | php-git-d59d500af7204cf419d91553dccfc2ff0069ca65.tar.gz |
Moved the scandir code into it's own files so that it can be used by other
OSes where libc does not have a native scandir() implementation.
Diffstat (limited to 'win32/readdir.c')
-rw-r--r-- | win32/readdir.c | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/win32/readdir.c b/win32/readdir.c index 78db689b29..e33d19bde5 100644 --- a/win32/readdir.c +++ b/win32/readdir.c @@ -141,83 +141,3 @@ int rewinddir(DIR *dp) return 0; } - -int alphasort(const struct dirent **a, const struct dirent **b) -{ - return strcoll((*a)->d_name,(*b)->d_name); -} - -int scandir(const char *dirname, - struct dirent **namelist[], - int (*selector) (const struct dirent *entry), - int (*compare) (const struct dirent **a, const struct dirent **b)) -{ - DIR *dirp = NULL; - struct dirent **vector = NULL; - struct dirent *dp = NULL; - int vector_size = 0; - - int nfiles = 0; - int fail = 0; - - if (namelist == NULL) - return -1; - - dirp = opendir(dirname); - if (dirp == NULL) - return -1; - - for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) - { - int dsize = 0; - struct dirent *newdp = NULL; - - if (selector && (*selector)(dp) == 0) - continue; - - if (nfiles == vector_size) - { - struct dirent **newv; - if (vector_size == 0) - vector_size = 10; - else - vector_size *= 2; - - newv = (struct dirent **) realloc (vector, vector_size * sizeof (struct dirent *)); - if (newv == NULL) - { - fail = 1; - break; - } - vector = newv; - } - - dsize = sizeof (struct dirent) + ((strlen(dp->d_name) + 1) * sizeof(char)); - newdp = (struct dirent *) malloc(dsize); - - if (newdp == NULL) - { - fail = 1; - break; - } - - vector[nfiles++] = (struct dirent *) memcpy(newdp, dp, dsize); - } - - closedir(dirp); - - if (fail) - { - while (nfiles-- > 0) free(vector[nfiles]); - free(vector); - return -1; - } - - - *namelist = vector; - - if (compare) - qsort (*namelist,nfiles,sizeof (struct dirent *),compare); - - return nfiles; -} |