3 Written by Corinna Vinschen <corinna.vinschen@cityweb.de>
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
17 alphasort (const struct dirent
**a
, const struct dirent
**b
)
19 return strcoll ((*a
)->d_name
, (*b
)->d_name
);
23 versionsort (const struct dirent
**a
, const struct dirent
**b
)
25 return strverscmp ((*a
)->d_name
, (*b
)->d_name
);
29 scandir (const char *dir
,
30 struct dirent
***namelist
,
31 int (*select
) (const struct dirent
*),
32 int (*compar
) (const struct dirent
**, const struct dirent
**))
35 struct dirent
*ent
, *etmp
, **nl
= NULL
, **ntmp
;
40 if (!(dirp
= opendir (dir
)))
46 while ((ent
= readdir (dirp
)))
48 if (!select
|| select (ent
))
50 if (count
== allocated
)
58 ntmp
= (struct dirent
**) realloc (nl
, allocated
* sizeof *nl
);
67 if (!(etmp
= (struct dirent
*) malloc (sizeof *ent
)))
86 /* Ignore errors from closedir() and what not else. */
93 qsort (nl
, count
, sizeof *nl
, (int (*)(const void *, const void *)) compar
);