1 /* Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 #if defined(WIN32) && !defined(__CYGWIN__)
20 # include "scandir_win32.c"
23 # include "flstring.h"
27 # include <sys/types.h>
32 # define NAMLEN(dirent) strlen((dirent)->d_name)
34 # define dirent direct
35 # define NAMLEN(dirent) (dirent)->d_namlen
37 # include <sys/ndir.h>
48 fl_scandir(const char *dir
, struct dirent
***namelist
,
49 int (*select
)(struct dirent
*),
50 int (*compar
)(struct dirent
**, struct dirent
**))
52 DIR *dp
= opendir (dir
);
53 struct dirent
**v
= NULL
;
65 while ((d
= readdir (dp
)) != NULL
)
66 if (select
== NULL
|| (*select
) (d
))
77 newv
= (struct dirent
**) realloc (v
, vsize
* sizeof (*v
));
87 # define _D_EXACT_NAMLEN(d) (strlen ((d)->d_name))
88 # define _D_ALLOC_NAMLEN(d) (sizeof (d)->d_name > 1 ? sizeof (d)->d_name : \
89 _D_EXACT_NAMLEN (d) + 1)
91 dsize
= &d
->d_name
[_D_ALLOC_NAMLEN (d
)] - (char *) d
;
92 v
[i
] = (struct dirent
*) malloc (dsize
);
96 memcpy (v
[i
++], d
, dsize
);
102 (void) closedir (dp
);
110 (void) closedir (dp
);
113 /* Sort the list if we have a comparison function to sort with. */
114 if (compar
) qsort (v
, i
, sizeof (*v
), (int (*)(const void *, const void *))compar
);
123 * End of "$Id: scandir.c 8192 2011-01-05 16:50:10Z manolo $".