summaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/abort_handler_s.c2
-rw-r--r--src/stdlib/bsearch_s.c8
-rw-r--r--src/stdlib/exit.c4
-rw-r--r--src/stdlib/getenv_s.c2
-rw-r--r--src/stdlib/ignore_handler_s.c2
-rw-r--r--src/stdlib/llabs.c2
-rw-r--r--src/stdlib/mbstowcs_s.c2
-rw-r--r--src/stdlib/qsort_s.c2
-rw-r--r--src/stdlib/quick_exit.c2
-rw-r--r--src/stdlib/realloc.c30
-rw-r--r--src/stdlib/set_constraint_handler_s.c2
-rw-r--r--src/stdlib/strtof.c8
-rw-r--r--src/stdlib/strtold.c8
-rw-r--r--src/stdlib/strtoll.c6
-rw-r--r--src/stdlib/strtoull.c6
-rw-r--r--src/stdlib/wcstombs_s.c2
-rw-r--r--src/stdlib/wctomb_s.c2
17 files changed, 43 insertions, 47 deletions
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 <stdlib.h>
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 <stddef.h>
/** 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 <stdlib.h>
-#include <limits.h>
-#include <stddef.h>
#include <stdio.h>
-#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 <string.h>
-#include "stdlib.h"
+#include <stdlib.h>
/** 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 <stdlib.h>
/** 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 <stdlib.h>
-#include "limits.h"
+#include <limits.h>
/** 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 <stdlib.h>
/** 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 <stdlib.h>
/** 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 <stdlib.h>
-#include <limits.h>
-#include <stddef.h>
#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 <stdlib.h>
+#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 <stdlib.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/mman.h>
-#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 <stdlib.h>
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 <stdlib.h>
-#include "float.h"
-#include "errno.h"
-#include "ctype.h"
-#include "math.h"
+#include <float.h>
+#include <errno.h>
+#include <ctype.h>
+#include <math.h>
/** 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 <stdlib.h>
-#include "float.h"
-#include "ctype.h"
-#include "errno.h"
-#include "math.h"
+#include <float.h>
+#include <ctype.h>
+#include <errno.h>
+#include <math.h>
/** 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 <stdlib.h>
-#include "ctype.h"
-#include "limits.h"
-#include "errno.h"
+#include <ctype.h>
+#include <limits.h>
+#include <errno.h>
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 <stdlib.h>
-#include "ctype.h"
-#include "limits.h"
-#include "errno.h"
+#include <ctype.h>
+#include <limits.h>
+#include <errno.h>
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 <stdlib.h>
/** 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 <stdlib.h>
/** convert wide character to multibyte character **/
errno_t wctomb_s(int * restrict status, char * restrict s, rsize_t smax, wchar_t wc)