3 Copyright 1998, 1999, 2000, 2001 Red Hat, Inc.
5 Written by Corinna Vinschen <corinna.vinschen@cityweb.de>
7 This file is part of Cygwin.
9 This software is a copyrighted work licensed under the terms of the
10 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
21 int scandir(const char *dir
,
22 struct dirent
***namelist
,
23 int (*select
)(const struct dirent
*),
24 int (*compar
)(const struct dirent
**, const struct dirent
**)) {
26 struct dirent
*ent
, *etmp
, **nl
= NULL
, **ntmp
;
31 if (!(dirp
= opendir(dir
)))
34 while ((ent
= readdir(dirp
))) {
35 if (!select
|| select(ent
)) {
39 if (count
== allocated
) {
45 ntmp
= (struct dirent
**) realloc(nl
, allocated
* sizeof * nl
);
53 etmp
= (struct dirent
*) calloc(sizeof * ent
, sizeof(char));
76 qsort(nl
, count
, sizeof * nl
, (int (*)(const void *, const void *)) compar
);
88 int alphasort(const struct dirent
**a
, const struct dirent
**b
) {
89 return strcoll((*a
)->d_name
, (*b
)->d_name
);