Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/scandir.c
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "un-namespace.h" | #include "un-namespace.h" | ||||
#ifdef I_AM_SCANDIR_B | #ifdef I_AM_SCANDIR_B | ||||
#include "block_abi.h" | #include "block_abi.h" | ||||
#define SELECT(x) CALL_BLOCK(select, x) | #define SELECT(x) CALL_BLOCK(select, x) | ||||
#ifndef __BLOCKS__ | #ifndef __BLOCKS__ | ||||
void | void qsort_b(void *, size_t, size_t, void *); | ||||
qsort_b(void *, size_t, size_t, void*); | |||||
#endif | #endif | ||||
#else | #else | ||||
#define SELECT(x) select(x) | #define SELECT(x) select(x) | ||||
#endif | #endif | ||||
static int alphasort_thunk(void *thunk, const void *p1, const void *p2); | static int alphasort_thunk(void *thunk, const void *p1, const void *p2); | ||||
int | int | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
fail: | fail: | ||||
while (numitems > 0) | while (numitems > 0) | ||||
free(names[--numitems]); | free(names[--numitems]); | ||||
free(names); | free(names); | ||||
closedir(dirp); | closedir(dirp); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
#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)); | ||||
} | } | ||||
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 |