diff options
Diffstat (limited to 'lib/libc/stdlib')
36 files changed, 242 insertions, 210 deletions
diff --git a/lib/libc/stdlib/_Exit.c b/lib/libc/stdlib/_Exit.c index beb53e34..5a4d36e9 100644 --- a/lib/libc/stdlib/_Exit.c +++ b/lib/libc/stdlib/_Exit.c @@ -1,4 +1,4 @@ -#include <unistd.h> +#include <unistd.h> // for _exit _Noreturn void _Exit(int status) { diff --git a/lib/libc/stdlib/abort.c b/lib/libc/stdlib/abort.c index 3d022e70..99001570 100644 --- a/lib/libc/stdlib/abort.c +++ b/lib/libc/stdlib/abort.c @@ -1,11 +1,11 @@ -#include <atomic.h> -#include <stdlib.h> -#include <syscall.h> -#include <asm-generic/signal.h> -#include <thread.h> -#include <threads.h> -#include <unistd.h> -#include <libc.h> +#include <__thread.h> // for __thread_self +#include <atomic.h> // for LIBC_LOCK +#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous) +#include <signal.h> // for SIGABRT, sigaction, SIGKILL, SIG_DFL +#include <stdlib.h> // for abort +#include <syscall.h> // for __syscall, __syscall_2, __syscall_4 +#include <threads.h> // for thrd_current +#include <unistd.h> // for _exit int raise(int); @@ -18,8 +18,9 @@ _Noreturn void abort(void) LIBC_LOCK(libc.lock.abort); sa.sa_handler = SIG_DFL; - __syscall(rt_sigaction, SIGABRT, &sa, NULL, _NSIG / 8); - __syscall(tkill, thrd_current()->tid, SIGABRT); + __syscall(rt_sigaction, SIGABRT, &sa, 0, 64 / 8); + __syscall(tkill, ((struct __thread_self *)thrd_current())->tid, + SIGABRT); // This point should never be reached raise(SIGKILL); diff --git a/lib/libc/stdlib/abs.c b/lib/libc/stdlib/abs.c index ac2bc605..5c510567 100644 --- a/lib/libc/stdlib/abs.c +++ b/lib/libc/stdlib/abs.c @@ -1,3 +1,5 @@ +#include <stdlib.h> // for abs + int abs(int i) { return (i < 0) ? -i : i; diff --git a/lib/libc/stdlib/aligned_alloc.c b/lib/libc/stdlib/aligned_alloc.c index f978dfa9..f8ab24db 100644 --- a/lib/libc/stdlib/aligned_alloc.c +++ b/lib/libc/stdlib/aligned_alloc.c @@ -1,8 +1,8 @@ -#include <errno.h> -#include <stdlib.h> -#include <stdint.h> -#include <sys/mman.h> -#include <unistd.h> +#include "stddef.h" // for NULL + +#include <errno.h> // for errno, EINVAL, ENOMEM +#include <stdint.h> // for uintptr_t +#include <stdlib.h> // for size_t, aligned_alloc, malloc void *aligned_alloc(size_t alignment, size_t size) { diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c index 6c84fd4a..cf1f91e5 100644 --- a/lib/libc/stdlib/atexit.c +++ b/lib/libc/stdlib/atexit.c @@ -1,4 +1,6 @@ -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <stdlib.h> // for atexit static void (*__atexit_fvec[32])(void) = { NULL }; diff --git a/lib/libc/stdlib/atof.c b/lib/libc/stdlib/atof.c index 5f5fc91f..aff6634b 100644 --- a/lib/libc/stdlib/atof.c +++ b/lib/libc/stdlib/atof.c @@ -1,4 +1,6 @@ -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <stdlib.h> // for strtod, atof double atof(const char *str) { diff --git a/lib/libc/stdlib/atoi.c b/lib/libc/stdlib/atoi.c index 97b663d1..614bd75c 100644 --- a/lib/libc/stdlib/atoi.c +++ b/lib/libc/stdlib/atoi.c @@ -1,4 +1,6 @@ -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <stdlib.h> // for strtol, atoi int atoi(const char *str) { diff --git a/lib/libc/stdlib/atol.c b/lib/libc/stdlib/atol.c index 976f9997..81bbbf82 100644 --- a/lib/libc/stdlib/atol.c +++ b/lib/libc/stdlib/atol.c @@ -1,4 +1,6 @@ -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <stdlib.h> // for strtol, atol long atol(const char *nptr) { diff --git a/lib/libc/stdlib/atoll.c b/lib/libc/stdlib/atoll.c index bea1a031..c830e4df 100644 --- a/lib/libc/stdlib/atoll.c +++ b/lib/libc/stdlib/atoll.c @@ -1,4 +1,6 @@ -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <stdlib.h> // for strtoll, atoll long long atoll(const char *nptr) { diff --git a/lib/libc/stdlib/bsearch.c b/lib/libc/stdlib/bsearch.c index a2793b0d..b4f83d55 100644 --- a/lib/libc/stdlib/bsearch.c +++ b/lib/libc/stdlib/bsearch.c @@ -47,8 +47,9 @@ is respectively less than, matching, or greater than the array member. */ -#include <sys/types.h> /* size_t */ -#include <stdio.h> +#include "stddef.h" // for NULL + +#include <stdio.h> // for size_t /* * Perform a binary search. diff --git a/lib/libc/stdlib/btowc.c b/lib/libc/stdlib/btowc.c index f16865b7..36f392bf 100644 --- a/lib/libc/stdlib/btowc.c +++ b/lib/libc/stdlib/btowc.c @@ -1,6 +1,6 @@ -#include <wchar.h> #include <stdio.h> #include <stdlib.h> +#include <wchar.h> #define CODEUNIT(c) (0xdfff & (signed char)(c)) diff --git a/lib/libc/stdlib/calloc.c b/lib/libc/stdlib/calloc.c index 408eef5e..89e16f80 100644 --- a/lib/libc/stdlib/calloc.c +++ b/lib/libc/stdlib/calloc.c @@ -1,6 +1,8 @@ -#include <errno.h> -#include <string.h> -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <errno.h> // for errno, EINVAL, ENOMEM +#include <stdlib.h> // for calloc, malloc +#include <string.h> // for size_t, memset void *calloc(size_t nelem, size_t elsize) { diff --git a/lib/libc/stdlib/div.c b/lib/libc/stdlib/div.c index cadc292e..e7a290a9 100644 --- a/lib/libc/stdlib/div.c +++ b/lib/libc/stdlib/div.c @@ -1,4 +1,4 @@ -#include <stdlib.h> +#include <stdlib.h> // for div_t, div div_t div(int numer, int denom) { diff --git a/lib/libc/stdlib/exit.c b/lib/libc/stdlib/exit.c index 5fea520e..7fc96f28 100644 --- a/lib/libc/stdlib/exit.c +++ b/lib/libc/stdlib/exit.c @@ -1,7 +1,10 @@ -#include <libc.h> -#include <libc.h> -#include <unistd.h> -#include <stdio.h> +#include "__stdio.h" // for __FILE +#include "stddef.h" // for NULL + +#include <libc.h> // for weak_reference +#include <stdio.h> // for fflush, stdout, FILE, stderr, stdin +#include <stdlib.h> // for free, exit +#include <unistd.h> // for _exit, close, write, STDERR_FILENO void (*__dummy_atexit_fvec)(void); weak_reference(__dummy_atexit_fvec, __atexit_fvec); @@ -15,16 +18,16 @@ static void __fclose(FILE *stream) return; } - if (__IMPL(stream)->buf_len > 0) { + if (__FILE(stream)->buf_len > 0) { fflush(stream); } - if (__IMPL(stream)->fd > STDERR_FILENO) { - close(__IMPL(stream)->fd); + if (__FILE(stream)->fd > STDERR_FILENO) { + close(__FILE(stream)->fd); } - if (__IMPL(stream)->buf) { - free(__IMPL(stream)->buf); + if (__FILE(stream)->buf) { + free(__FILE(stream)->buf); } if (stream != stdout && stream != stderr && stream != stdin) { diff --git a/lib/libc/stdlib/free.c b/lib/libc/stdlib/free.c index 40320dc7..e08b0170 100644 --- a/lib/libc/stdlib/free.c +++ b/lib/libc/stdlib/free.c @@ -1,9 +1,10 @@ -#include <libc.h> -#include <sys/mman.h> -#include <atomic.h> -#include <malloc.h> -#include <stdint.h> -#include <stdbool.h> +#include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK +#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous) +#include <malloc.h> // for page, page::(anonymous), __malloc_pvec, LARGE_... +#include <stddef.h> // for NULL +#include <stdint.h> // for uintptr_t +#include <stdlib.h> // for free +#include <sys/mman.h> // for size_t, munmap void free(void *ptr) { diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c index deb2b5f7..17975574 100644 --- a/lib/libc/stdlib/getenv.c +++ b/lib/libc/stdlib/getenv.c @@ -1,6 +1,7 @@ -#include <libc.h> -#include <stddef.h> -#include <atomic.h> +#include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK +#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous), libc +#include <stddef.h> // for NULL +#include <stdlib.h> // for getenv, secure_getenv extern char **environ; diff --git a/lib/libc/stdlib/heapsort.c b/lib/libc/stdlib/heapsort.c index 101720bb..20922f12 100644 --- a/lib/libc/stdlib/heapsort.c +++ b/lib/libc/stdlib/heapsort.c @@ -30,8 +30,8 @@ * SUCH DAMAGE. */ -#include <stddef.h> -#include <stdlib.h> +#include <stddef.h> // for NULL +#include <stdlib.h> // for size_t, free, malloc /* * Swap two areas of size number of bytes. Although qsort(3) permits random @@ -40,25 +40,25 @@ * isn't worth optimizing; the SWAP's get sped up by the cache, and pointer * arithmetic gets lost in the time required for comparison function calls. */ -#define SWAP(a, b, count, size, tmp) \ - { \ - count = size; \ - do { \ - tmp = *a; \ - *a++ = *b; \ - *b++ = tmp; \ - } while (--count); \ +#define SWAP(a, b, count, size, tmp) \ + { \ + (count) = size; \ + do { \ + (tmp) = *(a); \ + *(a)++ = *(b); \ + *(b)++ = tmp; \ + } while (--(count)); \ } /* Copy one block of size size to another. */ -#define COPY(a, b, count, size, tmp1, tmp2) \ - { \ - count = size; \ - tmp1 = a; \ - tmp2 = b; \ - do { \ - *tmp1++ = *tmp2++; \ - } while (--count); \ +#define COPY(a, b, count, size, tmp1, tmp2) \ + { \ + (count) = size; \ + (tmp1) = a; \ + (tmp2) = b; \ + do { \ + *(tmp1)++ = *(tmp2)++; \ + } while (--(count)); \ } /* @@ -68,21 +68,21 @@ * There two cases. If j == nmemb, select largest of Ki and Kj. If * j < nmemb, select largest of Ki, Kj and Kj+1. */ -#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) \ - { \ - for (par_i = initval; (child_i = par_i * 2) <= nmemb; \ - par_i = child_i) { \ - child = base + child_i * size; \ - if (child_i < nmemb && \ - compar(child, child + size) < 0) { \ - child += size; \ - ++child_i; \ - } \ - par = base + par_i * size; \ - if (compar(child, par) <= 0) \ - break; \ - SWAP(par, child, count, size, tmp); \ - } \ +#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) \ + { \ + for ((par_i) = initval; ((child_i) = (par_i) * 2) <= (nmemb); \ + (par_i) = (child_i)) { \ + (child) = base + (child_i) * (size); \ + if ((child_i) < (nmemb) && \ + compar(child, (child) + (size)) < 0) { \ + (child) += (size); \ + ++(child_i); \ + } \ + (par) = base + (par_i) * (size); \ + if (compar(child, par) <= 0) \ + break; \ + SWAP(par, child, count, size, tmp); \ + } \ } /* @@ -104,23 +104,23 @@ */ #define SELECT(par_i, child_i, nmemb, par, child, size, k, count, tmp1, tmp2) \ { \ - for (par_i = 1; (child_i = par_i * 2) <= nmemb; \ - par_i = child_i) { \ - child = base + child_i * size; \ - if (child_i < nmemb && \ - compar(child, child + size) < 0) { \ - child += size; \ - ++child_i; \ + for ((par_i) = 1; ((child_i) = (par_i) * 2) <= (nmemb); \ + (par_i) = (child_i)) { \ + (child) = base + (child_i) * (size); \ + if ((child_i) < (nmemb) && \ + compar(child, (child) + (size)) < 0) { \ + (child) += (size); \ + ++(child_i); \ } \ - par = base + par_i * size; \ + (par) = base + (par_i) * (size); \ COPY(par, child, count, size, tmp1, tmp2); \ } \ for (;;) { \ - child_i = par_i; \ - par_i = child_i / 2; \ - child = base + child_i * size; \ - par = base + par_i * size; \ - if (child_i == 1 || compar(k, par) < 0) { \ + (child_i) = par_i; \ + (par_i) = (child_i) / 2; \ + (child) = base + (child_i) * (size); \ + (par) = base + (par_i) * (size); \ + if ((child_i) == 1 || compar(k, par) < 0) { \ COPY(child, k, count, size, tmp1, tmp2); \ break; \ } \ diff --git a/lib/libc/stdlib/heapsort_r.c b/lib/libc/stdlib/heapsort_r.c index 645f63b0..05c6e3ae 100644 --- a/lib/libc/stdlib/heapsort_r.c +++ b/lib/libc/stdlib/heapsort_r.c @@ -30,8 +30,8 @@ * SUCH DAMAGE. */ -#include <stddef.h> -#include <stdlib.h> +#include <stddef.h> // for NULL +#include <stdlib.h> // for size_t, free, malloc /* * Swap two areas of size number of bytes. Although qsort(3) permits random @@ -40,25 +40,25 @@ * isn't worth optimizing; the SWAP's get sped up by the cache, and pointer * arithmetic gets lost in the time required for comparison function calls. */ -#define SWAP(a, b, count, size, tmp) \ - { \ - count = size; \ - do { \ - tmp = *a; \ - *a++ = *b; \ - *b++ = tmp; \ - } while (--count); \ +#define SWAP(a, b, count, size, tmp) \ + { \ + (count) = size; \ + do { \ + (tmp) = *(a); \ + *(a)++ = *(b); \ + *(b)++ = tmp; \ + } while (--(count)); \ } /* Copy one block of size size to another. */ -#define COPY(a, b, count, size, tmp1, tmp2) \ - { \ - count = size; \ - tmp1 = a; \ - tmp2 = b; \ - do { \ - *tmp1++ = *tmp2++; \ - } while (--count); \ +#define COPY(a, b, count, size, tmp1, tmp2) \ + { \ + (count) = size; \ + (tmp1) = a; \ + (tmp2) = b; \ + do { \ + *(tmp1)++ = *(tmp2)++; \ + } while (--(count)); \ } /* @@ -68,21 +68,21 @@ * There two cases. If j == nmemb, select largest of Ki and Kj. If * j < nmemb, select largest of Ki, Kj and Kj+1. */ -#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) \ - { \ - for (par_i = initval; (child_i = par_i * 2) <= nmemb; \ - par_i = child_i) { \ - child = base + child_i * size; \ - if (child_i < nmemb && \ - compar(thunk, child, child + size) < 0) { \ - child += size; \ - ++child_i; \ - } \ - par = base + par_i * size; \ - if (compar(thunk, child, par) <= 0) \ - break; \ - SWAP(par, child, count, size, tmp); \ - } \ +#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) \ + { \ + for ((par_i) = initval; ((child_i) = (par_i) * 2) <= (nmemb); \ + (par_i) = (child_i)) { \ + (child) = base + (child_i) * (size); \ + if ((child_i) < (nmemb) && \ + compar(thunk, child, (child) + (size)) < 0) { \ + (child) += (size); \ + ++(child_i); \ + } \ + (par) = base + (par_i) * (size); \ + if (compar(thunk, child, par) <= 0) \ + break; \ + SWAP(par, child, count, size, tmp); \ + } \ } /* @@ -104,23 +104,23 @@ */ #define SELECT(par_i, child_i, nmemb, par, child, size, k, count, tmp1, tmp2) \ { \ - for (par_i = 1; (child_i = par_i * 2) <= nmemb; \ - par_i = child_i) { \ - child = base + child_i * size; \ - if (child_i < nmemb && \ - compar(thunk, child, child + size) < 0) { \ - child += size; \ - ++child_i; \ + for ((par_i) = 1; ((child_i) = (par_i) * 2) <= (nmemb); \ + (par_i) = (child_i)) { \ + (child) = base + (child_i) * (size); \ + if ((child_i) < (nmemb) && \ + compar(thunk, child, (child) + (size)) < 0) { \ + (child) += (size); \ + ++(child_i); \ } \ - par = base + par_i * size; \ + (par) = base + (par_i) * (size); \ COPY(par, child, count, size, tmp1, tmp2); \ } \ for (;;) { \ - child_i = par_i; \ - par_i = child_i / 2; \ - child = base + child_i * size; \ - par = base + par_i * size; \ - if (child_i == 1 || compar(thunk, k, par) < 0) { \ + (child_i) = par_i; \ + (par_i) = (child_i) / 2; \ + (child) = base + (child_i) * (size); \ + (par) = base + (par_i) * (size); \ + if ((child_i) == 1 || compar(thunk, k, par) < 0) { \ COPY(child, k, count, size, tmp1, tmp2); \ break; \ } \ diff --git a/lib/libc/stdlib/labs.c b/lib/libc/stdlib/labs.c index 1413af3a..3b34c7e1 100644 --- a/lib/libc/stdlib/labs.c +++ b/lib/libc/stdlib/labs.c @@ -1,4 +1,4 @@ -#include <stdlib.h> +#include <stdlib.h> // for labs long labs(long i) { diff --git a/lib/libc/stdlib/ldiv.c b/lib/libc/stdlib/ldiv.c index 9fc62b8d..e1fcdf50 100644 --- a/lib/libc/stdlib/ldiv.c +++ b/lib/libc/stdlib/ldiv.c @@ -1,4 +1,4 @@ -#include <stdlib.h> +#include <stdlib.h> // for ldiv_t, ldiv ldiv_t ldiv(long numer, long denom) { diff --git a/lib/libc/stdlib/llabs.c b/lib/libc/stdlib/llabs.c index 1fadcb98..8cd4cc66 100644 --- a/lib/libc/stdlib/llabs.c +++ b/lib/libc/stdlib/llabs.c @@ -1,4 +1,4 @@ -#include <stdlib.h> +#include <stdlib.h> // for llabs long long llabs(long long i) { diff --git a/lib/libc/stdlib/lldiv.c b/lib/libc/stdlib/lldiv.c index 6df419b3..0b962974 100644 --- a/lib/libc/stdlib/lldiv.c +++ b/lib/libc/stdlib/lldiv.c @@ -1,4 +1,4 @@ -#include <stdlib.h> +#include <stdlib.h> // for lldiv_t, lldiv lldiv_t lldiv(long long numer, long long denom) { diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 555a45bc..344c9623 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,13 +1,14 @@ -#include <atomic.h> -#include <features.h> -#include <libc.h> -#include <malloc.h> -#include <linux/errno.h> -#include <stdatomic.h> -#include <stdint.h> -#include <string.h> -#include <sys/mman.h> -#include <unistd.h> +#include "stddef.h" // for NULL + +#include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK +#include <features.h> // for __weak +#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous) +#include <malloc.h> // for page, page::(anonymous), class, global_size_c... +#include <stdatomic.h> // for atomic_flag_clear +#include <stdint.h> // for uint32_t, uint8_t, uintptr_t +#include <stdlib.h> // for malloc +#include <string.h> // for memset +#include <sys/mman.h> // for size_t, mmap, munmap, MAP_ANONYMOUS, MAP_FAILED struct page *__malloc_pvec = NULL; diff --git a/lib/libc/stdlib/posix_memalign.c b/lib/libc/stdlib/posix_memalign.c index a7cbd2a2..f76e63fe 100644 --- a/lib/libc/stdlib/posix_memalign.c +++ b/lib/libc/stdlib/posix_memalign.c @@ -1,5 +1,7 @@ -#include <errno.h> -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <errno.h> // for EINVAL, ENOMEM +#include <stdlib.h> // for size_t, aligned_alloc, posix_memalign int posix_memalign(void **memptr, size_t alignment, size_t size) { diff --git a/lib/libc/stdlib/putenv.c b/lib/libc/stdlib/putenv.c index b070cc4d..a3649982 100644 --- a/lib/libc/stdlib/putenv.c +++ b/lib/libc/stdlib/putenv.c @@ -1,5 +1,5 @@ -#include <stdlib.h> -#include <string.h> +#include <stdlib.h> // for setenv, unsetenv, putenv +#include <string.h> // for memcpy, strchr int putenv(char *string) { diff --git a/lib/libc/stdlib/qsort.c b/lib/libc/stdlib/qsort.c index 896c79a1..ab0256a5 100644 --- a/lib/libc/stdlib/qsort.c +++ b/lib/libc/stdlib/qsort.c @@ -1,4 +1,4 @@ -#include <stdlib.h> +#include <stdlib.h> // for qsort_r, size_t, qsort static int wrapper(const void *a, const void *b, void *compar) { diff --git a/lib/libc/stdlib/qsort_r.c b/lib/libc/stdlib/qsort_r.c index 646eeaff..25a3aa81 100644 --- a/lib/libc/stdlib/qsort_r.c +++ b/lib/libc/stdlib/qsort_r.c @@ -25,9 +25,11 @@ Run time: Worst case O(n log n), close to O(n) in the mostly-sorted case. */ +#include "stddef.h" // for NULL + #define _BSD_SOURCE -#include <stdlib.h> -#include <string.h> +#include <stdlib.h> // for qsort_r +#include <string.h> // for size_t, memcpy #define ntz(x) __builtin_ctzl((x)) diff --git a/lib/libc/stdlib/quick_exit.c b/lib/libc/stdlib/quick_exit.c index 15587d17..c940c20c 100644 --- a/lib/libc/stdlib/quick_exit.c +++ b/lib/libc/stdlib/quick_exit.c @@ -1,4 +1,4 @@ -#include <stdlib.h> +#include <stdlib.h> // for _Exit, quick_exit _Noreturn void quick_exit(int status) { diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c index 878aa0e2..2fa5a3d0 100644 --- a/lib/libc/stdlib/rand.c +++ b/lib/libc/stdlib/rand.c @@ -15,8 +15,8 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <stdlib.h> -#include <stdint.h> +#include <stdint.h> // for uint64_t +#include <stdlib.h> // for RAND_MAX, drand48, erand48, jrand48, lrand48 #define UINT64_C(c) ((uint64_t)(c##ULL)) diff --git a/lib/libc/stdlib/realloc.c b/lib/libc/stdlib/realloc.c index d90af70d..4722ac5e 100644 --- a/lib/libc/stdlib/realloc.c +++ b/lib/libc/stdlib/realloc.c @@ -1,10 +1,12 @@ -#include <errno.h> -#include <string.h> -#include <atomic.h> -#include <libc.h> -#include <malloc.h> -#include <linux/errno.h> -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <atomic.h> // for LIBC_UNLOCK, LIBC_LOCK +#include <errno.h> // for EINVAL, errno +#include <libc.h> // for (anonymous struct)::(anonymous), (anonymous), libc +#include <malloc.h> // for page, page::(anonymous), __malloc_pvec +#include <stdint.h> // for uintptr_t +#include <stdlib.h> // for free, malloc, realloc +#include <string.h> // for memcpy, size_t void *realloc(void *ptr, size_t size) { @@ -28,14 +30,13 @@ void *realloc(void *ptr, size_t size) if (size <= old_size) { return ptr; - } else { - void *new_ptr = malloc(size); - if (new_ptr) { - memcpy(new_ptr, ptr, old_size); - free(ptr); - } - return new_ptr; } + void *new_ptr = malloc(size); + if (new_ptr) { + memcpy(new_ptr, ptr, old_size); + free(ptr); + } + return new_ptr; } p = p->next; } diff --git a/lib/libc/stdlib/reallocarray.c b/lib/libc/stdlib/reallocarray.c index 4dd1a6c8..0626f8ac 100644 --- a/lib/libc/stdlib/reallocarray.c +++ b/lib/libc/stdlib/reallocarray.c @@ -1,7 +1,7 @@ -#include <stdlib.h> -#include <errno.h> -#include <linux/errno.h> -#include <malloc.h> +#include "stddef.h" // for NULL + +#include <errno.h> // for ENOMEM, errno +#include <stdlib.h> // for size_t, realloc, reallocarray void *reallocarray(void *ptr, size_t nmemb, size_t size) { diff --git a/lib/libc/stdlib/setenv.c b/lib/libc/stdlib/setenv.c index 1464fc1b..004a29bd 100644 --- a/lib/libc/stdlib/setenv.c +++ b/lib/libc/stdlib/setenv.c @@ -1,7 +1,9 @@ -#include <libc.h> -#include <atomic.h> -#include <stdlib.h> -#include <string.h> +#include "stddef.h" // for NULL + +#include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK +#include <libc.h> // for (anonymous), libc, (anonymous struct)::(anonymous) +#include <stdlib.h> // for malloc, realloc, setenv +#include <string.h> // for strlen, size_t, memcpy, strcpy, strchr, strncmp extern char **environ; @@ -20,7 +22,7 @@ int setenv(const char *var, const char *value, int overwrite) malloc(var_len + 1 + value_len + 1); if (!new_env) return -1; - memcpy(new_env, var, var_len); + strcpy(new_env, var); new_env[var_len] = '='; memcpy(new_env + var_len + 1, value, value_len + 1); @@ -34,7 +36,8 @@ int setenv(const char *var, const char *value, int overwrite) while (environ[env_count]) env_count++; - char **new_envp = realloc(environ, (env_count + 2) * sizeof(char *)); + char **new_envp = (char **)realloc((void *)environ, + (env_count + 2) * sizeof(char *)); if (!new_envp) return -1; @@ -43,7 +46,7 @@ int setenv(const char *var, const char *value, int overwrite) if (!new_var) return -1; - memcpy(new_var, var, var_len); + strcpy(new_var, var); new_var[var_len] = '='; memcpy(new_var + var_len + 1, value, value_len + 1); diff --git a/lib/libc/stdlib/strtox.c b/lib/libc/stdlib/strtox.c index e924e5e6..b50a77a1 100644 --- a/lib/libc/stdlib/strtox.c +++ b/lib/libc/stdlib/strtox.c @@ -1,10 +1,10 @@ -#include <ctype.h> -#include <float.h> -#include <errno.h> -#include <strings.h> -#include <limits.h> -#include <math.h> -#include <stdlib.h> +#include <ctype.h> // for isdigit, isspace, isalnum, isalpha, toupper +#include <errno.h> // for errno, ERANGE, EINVAL +#include <float.h> // for LDBL_MAX, FLT_MAX +#include <limits.h> // for LLONG_MAX, LONG_MAX, ULLONG_MAX, ULONG_MAX, LLO... +#include <math.h> // for HUGE_VALF, powl, INFINITY, NAN +#include <stdlib.h> // for strtof, strtol, strtold, strtoll, strtoul, strt... +#include <strings.h> // for strncasecmp static unsigned long long __scanint(const char *s, int base, unsigned long long lim, int *neg, char **end) @@ -163,8 +163,7 @@ long strtol(const char *restrict nptr, char **restrict endptr, int base) if (neg) return (v == lim) ? LONG_MIN : -(long)v; - else - return (v > LONG_MAX) ? (errno = ERANGE, LONG_MAX) : (long)v; + return (v > LONG_MAX) ? (errno = ERANGE, LONG_MAX) : (long)v; } long long strtoll(const char *restrict nptr, char **restrict endptr, int base) @@ -185,15 +184,13 @@ long long strtoll(const char *restrict nptr, char **restrict endptr, int base) if (neg) { if (v == lim) return LLONG_MIN; - else - return -(long long)v; - } else { - if (v > LLONG_MAX) { - errno = ERANGE; - return LLONG_MAX; - } else - return (long long)v; + return -(long long)v; + } + if (v > LLONG_MAX) { + errno = ERANGE; + return LLONG_MAX; } + return (long long)v; } unsigned long strtoul(const char *restrict nptr, char **restrict endptr, @@ -245,7 +242,8 @@ float strtof(const char *restrict nptr, char **restrict endptr) if (val > FLT_MAX) { errno = ERANGE; return HUGE_VALF; - } else if (val < -FLT_MAX) { + } + if (val < -FLT_MAX) { errno = ERANGE; return -HUGE_VALF; } @@ -260,7 +258,8 @@ long double strtold(const char *restrict nptr, char **restrict endptr) if (val > LDBL_MAX) { errno = ERANGE; return LDBL_MAX; - } else if (val < -LDBL_MAX) { + } + if (val < -LDBL_MAX) { errno = ERANGE; return -LDBL_MAX; } diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c index 95f8d732..224493dc 100644 --- a/lib/libc/stdlib/system.c +++ b/lib/libc/stdlib/system.c @@ -1,4 +1,4 @@ -#include <stdlib.h> +#include <stdlib.h> // for system int system(const char *command) { diff --git a/lib/libc/stdlib/unsetenv.c b/lib/libc/stdlib/unsetenv.c index 4eb11d57..bce55e97 100644 --- a/lib/libc/stdlib/unsetenv.c +++ b/lib/libc/stdlib/unsetenv.c @@ -1,6 +1,8 @@ -#include <errno.h> -#include <string.h> -#include <stdlib.h> +#include "stddef.h" // for NULL + +#include <errno.h> // for EINVAL, errno +#include <stdlib.h> // for setenv, unsetenv +#include <string.h> // for strchr int unsetenv(const char *name) { diff --git a/lib/libc/stdlib/wctomb.c b/lib/libc/stdlib/wctomb.c index d971ffae..8c66b2c2 100644 --- a/lib/libc/stdlib/wctomb.c +++ b/lib/libc/stdlib/wctomb.c @@ -1,3 +1,4 @@ +#include "stddef.h" #include <stdlib.h> #include <wchar.h> |
