From 73da506ee04ec490c5959b45c216a1f8508bec5b Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sun, 16 Aug 2020 20:00:37 -0400 Subject: consistently use <> for standardized headers --- src/stdlib/abort_handler_s.c | 2 +- src/stdlib/bsearch_s.c | 8 +++----- src/stdlib/exit.c | 4 +--- src/stdlib/getenv_s.c | 2 +- src/stdlib/ignore_handler_s.c | 2 +- src/stdlib/llabs.c | 2 +- src/stdlib/mbstowcs_s.c | 2 +- src/stdlib/qsort_s.c | 2 +- src/stdlib/quick_exit.c | 2 -- src/stdlib/realloc.c | 30 ++++++++++++++++-------------- src/stdlib/set_constraint_handler_s.c | 2 +- src/stdlib/strtof.c | 8 ++++---- src/stdlib/strtold.c | 8 ++++---- src/stdlib/strtoll.c | 6 +++--- src/stdlib/strtoull.c | 6 +++--- src/stdlib/wcstombs_s.c | 2 +- src/stdlib/wctomb_s.c | 2 +- 17 files changed, 43 insertions(+), 47 deletions(-) (limited to 'src/stdlib') diff --git a/src/stdlib/abort_handler_s.c b/src/stdlib/abort_handler_s.c index 8f7ef71a..2405cd79 100644 --- a/src/stdlib/abort_handler_s.c +++ b/src/stdlib/abort_handler_s.c @@ -1,4 +1,4 @@ -#include "stdlib.h" +#include void abort_handler_s(const char * restrict msg, void * restrict ptr, errno_t error) { diff --git a/src/stdlib/bsearch_s.c b/src/stdlib/bsearch_s.c index 12a19c25..0f2cee63 100644 --- a/src/stdlib/bsearch_s.c +++ b/src/stdlib/bsearch_s.c @@ -1,12 +1,9 @@ #include /** binary search **/ -void *bsearch_s(const void * key, const void * base, - rsize_t nmemb, rsize_t size, - int (*compar)(const void *x, const void *y, void * context), - void *context) + +void *bsearch_s(const void * key, const void * base, rsize_t nmemb, rsize_t size, int (*compar)(const void *x, const void *y, void * context), void *context) { - __C_EXT(1, 201112L); /* TODO: testing */ void *ret = NULL; size_t i = nmemb / 2; @@ -22,6 +19,7 @@ void *bsearch_s(const void * key, const void * base, i += (nmemb >> trip); } } + return NULL; } diff --git a/src/stdlib/exit.c b/src/stdlib/exit.c index c9deba7a..557ad2cf 100644 --- a/src/stdlib/exit.c +++ b/src/stdlib/exit.c @@ -1,9 +1,7 @@ #include -#include -#include #include -#include "_syscall.h" #include "_stdlib.h" +#include "_syscall.h" /** cause normal program termination **/ _Noreturn void exit(int status) diff --git a/src/stdlib/getenv_s.c b/src/stdlib/getenv_s.c index 88156c1e..8760678b 100644 --- a/src/stdlib/getenv_s.c +++ b/src/stdlib/getenv_s.c @@ -1,5 +1,5 @@ #include -#include "stdlib.h" +#include /** get an environment variable **/ errno_t getenv_s(size_t * restrict len, char * restrict value, rsize_t maxsize, const char * restrict name) diff --git a/src/stdlib/ignore_handler_s.c b/src/stdlib/ignore_handler_s.c index 0a4ef62c..ec8c77ff 100644 --- a/src/stdlib/ignore_handler_s.c +++ b/src/stdlib/ignore_handler_s.c @@ -1,4 +1,4 @@ -#include "stdlib.h" +#include /** ignore constraint violations **/ void ignore_handler_s(const char * restrict msg, void * restrict ptr, errno_t error) diff --git a/src/stdlib/llabs.c b/src/stdlib/llabs.c index 9fc00ab6..a2a6cfbe 100644 --- a/src/stdlib/llabs.c +++ b/src/stdlib/llabs.c @@ -1,5 +1,5 @@ #include -#include "limits.h" +#include /** absolute value **/ diff --git a/src/stdlib/mbstowcs_s.c b/src/stdlib/mbstowcs_s.c index 70ef0433..fb60a896 100644 --- a/src/stdlib/mbstowcs_s.c +++ b/src/stdlib/mbstowcs_s.c @@ -1,4 +1,4 @@ -#include "stdlib.h" +#include /** convert multibyte string to wide character string **/ errno_t mbstowcs_s(size_t * restrict retval, wchar_t * restrict dst, rsize_t dstmax, const char * restrict src, rsize_t len) diff --git a/src/stdlib/qsort_s.c b/src/stdlib/qsort_s.c index da12d505..99afe7f0 100644 --- a/src/stdlib/qsort_s.c +++ b/src/stdlib/qsort_s.c @@ -1,4 +1,4 @@ -#include "stdlib.h" +#include /** sort an array **/ errno_t qsort_s(void *base, rsize_t nmemb, rsize_t size, diff --git a/src/stdlib/quick_exit.c b/src/stdlib/quick_exit.c index 25937325..3ff50e4e 100644 --- a/src/stdlib/quick_exit.c +++ b/src/stdlib/quick_exit.c @@ -1,6 +1,4 @@ #include -#include -#include #include "_stdlib.h" /** cause normal quick program termination **/ diff --git a/src/stdlib/realloc.c b/src/stdlib/realloc.c index 9b4d28ee..c1008457 100644 --- a/src/stdlib/realloc.c +++ b/src/stdlib/realloc.c @@ -1,19 +1,18 @@ -#include +#if ((!defined _POSIX_C_SOURCE) || (_POSIX_C_SOURCE < 199309L)) +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199309L +#define POSIX_FORCED +#endif -#if defined _POSIX_C_SOURCE && 199305L <= _POSIX_C_SOURCE -#include "sys/types.h" -#include "fcntl.h" -#include "sys/mman.h" +#include +#include +#include +#include -#else +#ifdef POSIX_FORCED #include "_syscall.h" -#define PROT_READ 0x1 -#define PROT_WRITE 0x2 -#define MAP_PRIVATE 0x2 -#define O_RDWR 0x2 -#define mmap(_a, _l, _p, _fl, _fd, _o) __syscall(__syscall_lookup(mmap), _a, _l, _p, _fl, _fd, _o) -#define open(_p, _a, _m) __syscall(__syscall_lookup(open), _p, _a, _m) - +#define mmap(_a, _l, _p, _fl, _fd, _o) __scall6(mmap, _a, _l, _p, _fl, _fd, _o) +#define open(_p, _a, _m) __scall3(open, _p, _a, _m) #endif /** change the amount of memory allocated **/ @@ -29,8 +28,11 @@ void * realloc(void * ptr, size_t size) if (ptr == NULL) { /* malloc() */ - return (void*)(long)mmap(NULL, size, PROT_READ | PROT_WRITE, + ptr = (void*)(long)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, backing, 0); + if (ptr == MAP_FAILED) { + return NULL; + } } else if (size == 0) { /* free() */ } diff --git a/src/stdlib/set_constraint_handler_s.c b/src/stdlib/set_constraint_handler_s.c index b32c9860..3e3200bd 100644 --- a/src/stdlib/set_constraint_handler_s.c +++ b/src/stdlib/set_constraint_handler_s.c @@ -1,4 +1,4 @@ -#include "stdlib.h" +#include constraint_handler_t set_constraint_handler_s(constraint_handler_t handler) { diff --git a/src/stdlib/strtof.c b/src/stdlib/strtof.c index 2c8fc115..c88a7c3f 100644 --- a/src/stdlib/strtof.c +++ b/src/stdlib/strtof.c @@ -1,8 +1,8 @@ #include -#include "float.h" -#include "errno.h" -#include "ctype.h" -#include "math.h" +#include +#include +#include +#include /** convert string to floating-point **/ diff --git a/src/stdlib/strtold.c b/src/stdlib/strtold.c index eb19fcc0..1c0ce7b8 100644 --- a/src/stdlib/strtold.c +++ b/src/stdlib/strtold.c @@ -1,8 +1,8 @@ #include -#include "float.h" -#include "ctype.h" -#include "errno.h" -#include "math.h" +#include +#include +#include +#include /** convert string to floating-point **/ diff --git a/src/stdlib/strtoll.c b/src/stdlib/strtoll.c index 87a338ec..00b763c9 100644 --- a/src/stdlib/strtoll.c +++ b/src/stdlib/strtoll.c @@ -1,7 +1,7 @@ #include -#include "ctype.h" -#include "limits.h" -#include "errno.h" +#include +#include +#include long long int strtoll(const char * restrict nptr, char ** restrict endptr, int base) { diff --git a/src/stdlib/strtoull.c b/src/stdlib/strtoull.c index 6f9bfe46..f4d1d248 100644 --- a/src/stdlib/strtoull.c +++ b/src/stdlib/strtoull.c @@ -1,7 +1,7 @@ #include -#include "ctype.h" -#include "limits.h" -#include "errno.h" +#include +#include +#include unsigned long long int strtoull(const char * restrict nptr, char ** restrict endptr, int base) { diff --git a/src/stdlib/wcstombs_s.c b/src/stdlib/wcstombs_s.c index b0a8980b..a0713638 100644 --- a/src/stdlib/wcstombs_s.c +++ b/src/stdlib/wcstombs_s.c @@ -1,4 +1,4 @@ -#include "stdlib.h" +#include /** convert wide character string to multibyte string **/ errno_t wcstombs_s(size_t * restrict retval, char * restrict dst, rsize_t dstmax, const wchar_t * restrict src, rsize_t len) diff --git a/src/stdlib/wctomb_s.c b/src/stdlib/wctomb_s.c index 0a3f510e..161b3504 100644 --- a/src/stdlib/wctomb_s.c +++ b/src/stdlib/wctomb_s.c @@ -1,4 +1,4 @@ -#include "stdlib.h" +#include /** convert wide character to multibyte character **/ errno_t wctomb_s(int * restrict status, char * restrict s, rsize_t smax, wchar_t wc) -- cgit v1.2.1