Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdlib/qsort.c
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
) | ) | ||||
{ | { | ||||
return CMP(thunk, a, b) < 0 ? | return CMP(thunk, a, b) < 0 ? | ||||
(CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) | (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) | ||||
:(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); | :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); | ||||
} | } | ||||
#if defined(I_AM_QSORT_R) | #if defined(I_AM_QSORT_R) | ||||
void | void __attribute__((__visibility__("protected"))) | ||||
qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) | qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) | ||||
#elif defined(I_AM_QSORT_S) | #elif defined(I_AM_QSORT_S) | ||||
errno_t | errno_t __attribute__((__visibility__("protected"))) | ||||
qsort_s(void *a, rsize_t n, rsize_t es, cmp_t *cmp, void *thunk) | qsort_s(void *a, rsize_t n, rsize_t es, cmp_t *cmp, void *thunk) | ||||
#else | #else | ||||
#define thunk NULL | #define thunk NULL | ||||
void | void __attribute__((__visibility__("protected"))) | ||||
qsort(void *a, size_t n, size_t es, cmp_t *cmp) | qsort(void *a, size_t n, size_t es, cmp_t *cmp) | ||||
#endif | #endif | ||||
{ | { | ||||
char *pa, *pb, *pc, *pd, *pl, *pm, *pn; | char *pa, *pb, *pc, *pd, *pl, *pm, *pn; | ||||
size_t d1, d2; | size_t d1, d2; | ||||
int cmp_result; | int cmp_result; | ||||
kib: Do you ever return non-zero from local_qsort()? If not, why not make it void?
qsort_s would… | |||||
Done Inline Actionsgood catch, I forgot to change that after moving the qsort_s checks. arichardson: good catch, I forgot to change that after moving the qsort_s checks. | |||||
int swap_cnt; | int swap_cnt; | ||||
Done Inline ActionsI think it would be useful for debugging to name these local_qsort() functions differently for each I_AM_QSORT_X kib: I think it would be useful for debugging to name these local_qsort() functions differently for… | |||||
Done Inline ActionsYes that makes sense, will update. arichardson: Yes that makes sense, will update. | |||||
#ifdef I_AM_QSORT_S | #ifdef I_AM_QSORT_S | ||||
if (n > RSIZE_MAX) { | if (n > RSIZE_MAX) { | ||||
__throw_constraint_handler_s("qsort_s : n > RSIZE_MAX", EINVAL); | __throw_constraint_handler_s("qsort_s : n > RSIZE_MAX", EINVAL); | ||||
return (EINVAL); | return (EINVAL); | ||||
} else if (es > RSIZE_MAX) { | } else if (es > RSIZE_MAX) { | ||||
__throw_constraint_handler_s("qsort_s : es > RSIZE_MAX", EINVAL); | __throw_constraint_handler_s("qsort_s : es > RSIZE_MAX", EINVAL); | ||||
return (EINVAL); | return (EINVAL); | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | #endif | ||||
if (d1 > es) { | if (d1 > es) { | ||||
/* Iterate rather than recurse to save stack space */ | /* Iterate rather than recurse to save stack space */ | ||||
/* qsort(a, d1 / es, es, cmp); */ | /* qsort(a, d1 / es, es, cmp); */ | ||||
n = d1 / es; | n = d1 / es; | ||||
goto loop; | goto loop; | ||||
} | } | ||||
} | } | ||||
#ifdef I_AM_QSORT_S | #ifdef I_AM_QSORT_S | ||||
Not Done Inline ActionsNo need. kib: No need. | |||||
return (0); | return (0); | ||||
#endif | #endif | ||||
} | } |
Do you ever return non-zero from local_qsort()? If not, why not make it void?
qsort_s would return (0) then.