summaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/_Exit.c4
-rw-r--r--src/stdlib/__stdlib.c3
-rw-r--r--src/stdlib/_rand.h4
-rw-r--r--src/stdlib/_stdlib.h22
-rw-r--r--src/stdlib/atexit.c4
-rw-r--r--src/stdlib/exit.c7
-rw-r--r--src/stdlib/rand.c5
-rw-r--r--src/stdlib/srand.c4
-rw-r--r--src/stdlib/strtod.c8
9 files changed, 45 insertions, 16 deletions
diff --git a/src/stdlib/_Exit.c b/src/stdlib/_Exit.c
index a199b457..b4f6f1a8 100644
--- a/src/stdlib/_Exit.c
+++ b/src/stdlib/_Exit.c
@@ -1,10 +1,10 @@
#include <stdlib.h>
-#include "nonstd/syscall.h"
+#include "../_syscall.h"
/** cause normal program termination without handlers **/
_Noreturn void _Exit(int status)
{
- long scno = __lookup("exit");
+ SYCALL_NUMBER(scno, "exit");
for (;;) {
__syscall(scno, status);
}
diff --git a/src/stdlib/__stdlib.c b/src/stdlib/__stdlib.c
new file mode 100644
index 00000000..bfc601d9
--- /dev/null
+++ b/src/stdlib/__stdlib.c
@@ -0,0 +1,3 @@
+#include "_stdlib.h"
+
+struct __stdlib __stdlib;
diff --git a/src/stdlib/_rand.h b/src/stdlib/_rand.h
deleted file mode 100644
index 7f7102ef..00000000
--- a/src/stdlib/_rand.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#include <limits.h>
-
-#define _rand(_n) \
- (((_n) = (_n) * 1103515245 + 12345) ? (_n) / UINT_MAX % RAND_MAX : 0)
diff --git a/src/stdlib/_stdlib.h b/src/stdlib/_stdlib.h
new file mode 100644
index 00000000..b0aa3cd2
--- /dev/null
+++ b/src/stdlib/_stdlib.h
@@ -0,0 +1,22 @@
+#ifndef ___STDLIB_H__
+#define ___STDLIB_H__
+
+#include <stdlib.h>
+#include <limits.h>
+
+#define _rand(_n) \
+ (((_n) = (_n) * 1103515245 + 12345) ? (_n) / UINT_MAX % RAND_MAX : 0)
+
+struct __stdlib {
+ struct atexit {
+ int nfns;
+ void (*fns[32])(void);
+ struct atexit *next;
+ struct atexit *prev;
+ } atexit;
+ unsigned int rand;
+};
+
+extern struct __stdlib __stdlib;
+
+#endif
diff --git a/src/stdlib/atexit.c b/src/stdlib/atexit.c
index aeb9172c..37f0ef72 100644
--- a/src/stdlib/atexit.c
+++ b/src/stdlib/atexit.c
@@ -1,12 +1,12 @@
#include <stdlib.h>
#include "errno.h"
-#include "nonstd/lib.h"
+#include "_stdlib.h"
/** register a function to run at program exit **/
int atexit(void (*func)(void))
{
- struct atexit *ae = __libc(ATEXIT);
+ struct atexit *ae = &(__stdlib.atexit);
while (ae->nfns == sizeof(ae->fns) / sizeof(ae->fns[0])) {
if (ae->next == NULL) {
ae->next = calloc(1, sizeof(*ae->next));
diff --git a/src/stdlib/exit.c b/src/stdlib/exit.c
index 501131e4..5fc1f2fc 100644
--- a/src/stdlib/exit.c
+++ b/src/stdlib/exit.c
@@ -1,13 +1,14 @@
#include <stdlib.h>
#include "limits.h"
#include "stddef.h"
-#include "nonstd/syscall.h"
+#include "../_syscall.h"
+#include "_stdlib.h"
/** cause normal program termination **/
_Noreturn void exit(int status)
{
- long scno = __lookup("exit");
- struct atexit *ae = __libc(ATEXIT);
+ long scno = __syscall_lookup(exit);
+ struct atexit *ae = &(__stdlib.atexit);
/* execute all atexit() registered functions in reverse order */
while (ae) {
diff --git a/src/stdlib/rand.c b/src/stdlib/rand.c
index f1a3e3e1..d8f3fcff 100644
--- a/src/stdlib/rand.c
+++ b/src/stdlib/rand.c
@@ -1,11 +1,10 @@
#include <stdlib.h>
-#include "nonstd/lib.h"
-#include "_rand.h"
+#include "_stdlib.h"
/** get a pseudo-random number **/
int rand(void)
{
- return _rand(*(unsigned*)__libc(RAND));
+ return (int)_rand(__stdlib.rand);
}
/***
diff --git a/src/stdlib/srand.c b/src/stdlib/srand.c
index 97ed2fec..af61570b 100644
--- a/src/stdlib/srand.c
+++ b/src/stdlib/srand.c
@@ -1,11 +1,11 @@
#include <stdlib.h>
-#include "nonstd/lib.h"
+#include "_stdlib.h"
/** seed the pseudo-random number generator **/
void srand(unsigned int seed)
{
- *((int*)__libc(RAND)) = seed;
+ __stdlib.rand = seed;
}
/***
diff --git a/src/stdlib/strtod.c b/src/stdlib/strtod.c
index ba6c9636..b866f47c 100644
--- a/src/stdlib/strtod.c
+++ b/src/stdlib/strtod.c
@@ -4,6 +4,14 @@
#include "float.h"
#include "math.h"
+#ifndef INFINITY
+#include "../math/INFINITY.c"
+#endif
+
+#ifndef NAN
+#include "../math/NAN.c"
+#endif
+
/** convert string to floating-point **/
double strtod(const char * restrict nptr, char ** restrict endptr)