Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/scandir-compat11.c
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
* scandir_b@FBSD_1.4 was never exported from libc.so.7 due to a | * scandir_b@FBSD_1.4 was never exported from libc.so.7 due to a | ||||
* mistake, so there is no use of exporting it now with some earlier | * mistake, so there is no use of exporting it now with some earlier | ||||
* symbol version. As result, we do not need to implement compat | * symbol version. As result, we do not need to implement compat | ||||
* function freebsd11_scandir_b(). | * function freebsd11_scandir_b(). | ||||
*/ | */ | ||||
#define SELECT(x) select(x) | #define SELECT(x) select(x) | ||||
static int freebsd11_scandir_thunk_cmp(void *thunk, const void *p1, | static int freebsd11_scandir_thunk_cmp(const void *p1, const void *p2, | ||||
const void *p2); | void *thunk); | ||||
int | int | ||||
freebsd11_scandir(const char *dirname, struct freebsd11_dirent ***namelist, | freebsd11_scandir(const char *dirname, struct freebsd11_dirent ***namelist, | ||||
int (*select)(const struct freebsd11_dirent *), | int (*select)(const struct freebsd11_dirent *), | ||||
int (*dcomp)(const struct freebsd11_dirent **, | int (*dcomp)(const struct freebsd11_dirent **, | ||||
const struct freebsd11_dirent **)) | const struct freebsd11_dirent **)) | ||||
{ | { | ||||
struct freebsd11_dirent *d, *p, **names = NULL; | struct freebsd11_dirent *d, *p, **names = NULL; | ||||
Show All 38 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) | ||||
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_scandir_thunk_cmp); | freebsd11_scandir_thunk_cmp, &dcomp); | ||||
*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); | ||||
closedir(dirp); | closedir(dirp); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
/* | /* | ||||
* 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 | ||||
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_scandir_thunk_cmp(void *thunk, const void *p1, const void *p2) | freebsd11_scandir_thunk_cmp(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); |
what happens to old sw passing its own comparison routine in dcomp?