2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1997-2004 The PHP Group |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 3.0 of the PHP license, |
8
| that is bundled with this package in the file LICENSE, and is |
9
| available through the world-wide-web at the following url: |
10
| http://www.php.net/license/3_0.txt. |
11
| If you did not receive a copy of the PHP license and are unable to |
12
| obtain it through the world-wide-web, please send a note to |
13
| license@php.net so we can mail you a copy immediately. |
14
+----------------------------------------------------------------------+
15
| Author: Shane Caraveo <shane@caraveo.com> |
16
| Ilia Alshanetsky <ilia@prohost.org> |
17
+----------------------------------------------------------------------+
20
/* $Id: php_scandir.c,v 1.9.2.2 2005/03/11 07:02:32 hyanantha Exp $ */
23
#include "config.w32.h"
25
#include <php_config.h>
28
#include "php_scandir.h"
30
#ifdef HAVE_SYS_TYPES_H
31
#include <sys/types.h>
41
#include "win32/readdir.h"
50
#endif /* HAVE_SCANDIR */
52
#ifndef HAVE_ALPHASORT
58
int php_alphasort(const struct dirent **a, const struct dirent **b)
60
return strcoll((*a)->d_name,(*b)->d_name);
62
#endif /* HAVE_ALPHASORT */
65
int php_scandir(const char *dirname, struct dirent **namelist[], int (*selector) (const struct dirent *entry), int (*compare) (const struct dirent **a, const struct dirent **b))
68
struct dirent **vector = NULL;
69
struct dirent *dp = NULL;
73
if (namelist == NULL) {
77
if (!(dirp = opendir(dirname))) {
81
while ((dp = readdir(dirp)) != NULL) {
83
struct dirent *newdp = NULL;
85
if (selector && (*selector)(dp) == 0) {
89
if (nfiles == vector_size) {
91
if (vector_size == 0) {
97
newv = (struct dirent **) realloc (vector, vector_size * sizeof (struct dirent *));
104
dsize = sizeof (struct dirent) + ((strlen(dp->d_name) + 1) * sizeof(char));
105
newdp = (struct dirent *) malloc(dsize);
111
vector[nfiles++] = (struct dirent *) memcpy(newdp, dp, dsize);
119
qsort (*namelist, nfiles, sizeof(struct dirent *), compare);
125
while (nfiles-- > 0) {
126
free(vector[nfiles]);
138
* vim600: sw=4 ts=4 fdm=marker