Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/scandir-compat11.c
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
#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 freebsd11_alphasort_thunk(void *thunk, const void *p1, | static int freebsd11_alphasort_thunk(const void *p1, const void *p2, | ||||
const void *p2); | void *thunk); | ||||
int | int | ||||
#ifdef I_AM_SCANDIR_B | #ifdef I_AM_SCANDIR_B | ||||
freebsd11_scandir_b(const char *dirname, struct freebsd11_dirent ***namelist, | freebsd11_scandir_b(const char *dirname, struct freebsd11_dirent ***namelist, | ||||
DECLARE_BLOCK(int, select, const struct freebsd11_dirent *), | DECLARE_BLOCK(int, select, const struct freebsd11_dirent *), | ||||
DECLARE_BLOCK(int, dcomp, const struct freebsd11_dirent **, | DECLARE_BLOCK(int, dcomp, const struct freebsd11_dirent **, | ||||
const struct freebsd11_dirent **)) | const struct freebsd11_dirent **)) | ||||
#else | #else | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if (numitems >= arraysz) { | ||||
goto fail; | goto fail; | ||||
} | } | ||||
names = names2; | names = names2; | ||||
arraysz *= 2; | arraysz *= 2; | ||||
} | } | ||||
names[numitems++] = p; | names[numitems++] = p; | ||||
} | } | ||||
closedir(dirp); | closedir(dirp); | ||||
if (numitems && dcomp != NULL) | if (numitems && dcomp != NULL) | ||||
#ifdef I_AM_SCANDIR_B | #ifdef I_AM_SCANDIR_B | ||||
qsort_b(names, numitems, sizeof(struct freebsd11_dirent *), | qsort_b(names, numitems, sizeof(struct freebsd11_dirent *), | ||||
(void*)dcomp); | (void*)dcomp); | ||||
#else | #else | ||||
emaste: what happens to old sw passing its own comparison routine in dcomp? | |||||
Done Inline ActionsThey are unaffected. The use of freebsd11_alphasort_thunk is an implementation detail, dcomp itself doesn't do anything with the thunk (as seen below, the typical dcomp, freebsd11_alphasort was not modified). delphij: They are unaffected. The use of `freebsd11_alphasort_thunk` is an implementation detail… | |||||
qsort_r(names, numitems, sizeof(struct freebsd11_dirent *), | qsort_r(names, numitems, sizeof(struct freebsd11_dirent *), | ||||
&dcomp, freebsd11_alphasort_thunk); | freebsd11_alphasort_thunk, &dcomp); | ||||
#endif | #endif | ||||
*namelist = names; | *namelist = names; | ||||
return (numitems); | return (numitems); | ||||
fail: | fail: | ||||
while (numitems > 0) | while (numitems > 0) | ||||
free(names[--numitems]); | free(names[--numitems]); | ||||
free(names); | free(names); | ||||
Show All 9 Lines | |||||
freebsd11_alphasort(const struct freebsd11_dirent **d1, | freebsd11_alphasort(const struct freebsd11_dirent **d1, | ||||
const struct freebsd11_dirent **d2) | const struct freebsd11_dirent **d2) | ||||
{ | { | ||||
return (strcoll((*d1)->d_name, (*d2)->d_name)); | return (strcoll((*d1)->d_name, (*d2)->d_name)); | ||||
} | } | ||||
static int | static int | ||||
freebsd11_alphasort_thunk(void *thunk, const void *p1, const void *p2) | freebsd11_alphasort_thunk(const void *p1, const void *p2, void *thunk) | ||||
Done Inline Actionsthis should just be freebsd11_sort_thunk, no? it's not specific to alphasort? emaste: this should just be `freebsd11_sort_thunk`, no? it's not specific to alphasort? | |||||
Done Inline ActionsYes (but it's somewhat beyond the scope of this change). I'll leave this open for now and take a look in the weekend. delphij: Yes (but it's somewhat beyond the scope of this change). I'll leave this open for now and take… | |||||
Done Inline ActionsYeah it would be a separate change emaste: Yeah it would be a separate change | |||||
{ | { | ||||
int (*dc)(const struct freebsd11_dirent **, const struct | int (*dc)(const struct freebsd11_dirent **, const struct | ||||
freebsd11_dirent **); | freebsd11_dirent **); | ||||
dc = *(int (**)(const struct freebsd11_dirent **, | dc = *(int (**)(const struct freebsd11_dirent **, | ||||
const struct freebsd11_dirent **))thunk; | const struct freebsd11_dirent **))thunk; | ||||
return (dc((const struct freebsd11_dirent **)p1, | return (dc((const struct freebsd11_dirent **)p1, | ||||
(const struct freebsd11_dirent **)p2)); | (const struct freebsd11_dirent **)p2)); | ||||
} | } | ||||
__sym_compat(alphasort, freebsd11_alphasort, FBSD_1.0); | __sym_compat(alphasort, freebsd11_alphasort, FBSD_1.0); | ||||
__sym_compat(scandir, freebsd11_scandir, FBSD_1.0); | __sym_compat(scandir, freebsd11_scandir, FBSD_1.0); | ||||
__sym_compat(scandir_b, freebsd11_scandir_b, FBSD_1.4); | __sym_compat(scandir_b, freebsd11_scandir_b, FBSD_1.4); |
what happens to old sw passing its own comparison routine in dcomp?