diff options
| author | jvoisin | 2023-12-06 21:45:57 +0100 |
|---|---|---|
| committer | jvoisin | 2023-12-07 17:29:06 +0100 |
| commit | b5d5cebc2b4218ca2c04c52546849df7625a53a0 (patch) | |
| tree | 096dfaebcf9306a9e955fd44e4aa18d2865f3733 /include | |
| parent | 9064a508d5f1ed3514d3e5b4734576e80f7048ae (diff) | |
Add qsort
Diffstat (limited to 'include')
| -rw-r--r-- | include/stdlib.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/stdlib.h b/include/stdlib.h index 5d89c9c..4a5cfde 100644 --- a/include/stdlib.h +++ b/include/stdlib.h | |||
| @@ -37,6 +37,23 @@ __extension__ | |||
| 37 | extern "C" { | 37 | extern "C" { |
| 38 | #endif | 38 | #endif |
| 39 | 39 | ||
| 40 | #undef qsort | ||
| 41 | #if __has_builtin(__builtin_qsort) | ||
| 42 | __diagnose_as_builtin(__builtin_qsort, 1, 2, 3, 4) | ||
| 43 | #endif | ||
| 44 | __access(read_write, 1) | ||
| 45 | _FORTIFY_FN(qsort) void qsort(void * _FORTIFY_POS0 base, size_t nmemb, size_t size, | ||
| 46 | int (*compar)(const void *, const void *)) | ||
| 47 | { | ||
| 48 | size_t __b = __bos(base, 0); | ||
| 49 | |||
| 50 | if (__bmo(nmemb, size)) | ||
| 51 | __builtin_trap(); | ||
| 52 | if (nmemb * size> __b) | ||
| 53 | __builtin_trap(); | ||
| 54 | |||
| 55 | return __orig_qsort(base, nmemb, size, compar); | ||
| 56 | } | ||
| 40 | 57 | ||
| 41 | /* FIXME clang */ | 58 | /* FIXME clang */ |
| 42 | #if !defined(__clang__) | 59 | #if !defined(__clang__) |
