Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/scandir.c
Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | |||||
#ifndef I_AM_SCANDIR_B | #ifndef I_AM_SCANDIR_B | ||||
/* | /* | ||||
* Alphabetic order comparison routine for those who want it. | * Alphabetic order comparison routine for those who want it. | ||||
* POSIX 2008 requires that alphasort() uses strcoll(). | * POSIX 2008 requires that alphasort() uses strcoll(). | ||||
*/ | */ | ||||
int | int | ||||
alphasort(const struct dirent **d1, const struct dirent **d2) | alphasort(const struct dirent **d1, const struct dirent **d2) | ||||
{ | { | ||||
return (strcoll((*d1)->d_name, (*d2)->d_name)); | return (strcoll((*d1)->d_name, (*d2)->d_name)); | ||||
} | |||||
int | |||||
versionsort(const struct dirent **d1, const struct dirent **d2) | |||||
{ | |||||
return strverscmp((*d1)->d_name, (*d2)->d_name); | |||||
} | } | ||||
static int | static int | ||||
alphasort_thunk(void *thunk, const void *p1, const void *p2) | alphasort_thunk(void *thunk, const void *p1, const void *p2) | ||||
{ | { | ||||
int (*dc)(const struct dirent **, const struct dirent **); | int (*dc)(const struct dirent **, const struct dirent **); | ||||
dc = *(int (**)(const struct dirent **, const struct dirent **))thunk; | dc = *(int (**)(const struct dirent **, const struct dirent **))thunk; | ||||
return (dc((const struct dirent **)p1, (const struct dirent **)p2)); | return (dc((const struct dirent **)p1, (const struct dirent **)p2)); | ||||
} | } | ||||
#endif | #endif |