[hackers] [scc] [libc] Add exit() and atexit() || Roberto E. Vargas Caballero
commit cae77758d639ac4ec3883dfebfc48641adf3d358
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Mar 1 16:56:08 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Mar 3 10:40:41 2017 +0100
[libc] Add exit() and atexit()
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index cf71bd2..4b64698 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
_AT_@ -8,6 +8,8 @@
#define NULL ((void *) 0)
#endif
+#define _ATEXIT_MAX 32
+
#define MB_CUR_MAX 1
#define RAND_MAX 32767
diff --git a/libc/src/Makefile b/libc/src/Makefile
index 28e7148..53facc2 100644
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
_AT_@ -10,7 +10,7 @@ LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \
isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \
isxdigit.o toupper.o tolower.o ctype.o setlocale.o \
- localeconv.o atoi.o
+ localeconv.o atoi.o atexit.o exit.o
all: libc.a
diff --git a/libc/src/atexit.c b/libc/src/atexit.c
new file mode 100644
index 0000000..705010a
--- /dev/null
+++ b/libc/src/atexit.c
_AT_@ -0,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+
+extern void (*_atexitf[_ATEXIT_MAX])(void);
+
+int
+atexit(void (*fun)(void))
+{
+ void (**bp)(void);
+
+ for (bp = _atexitf; bp < &_atexitf[_ATEXIT_MAX] && *bp; ++bp)
+ /* nothing */;
+ if (bp == &_atexitf[_ATEXIT_MAX])
+ return 0;
+ *bp = fun;
+ return 1;
+}
diff --git a/libc/src/exit.c b/libc/src/exit.c
new file mode 100644
index 0000000..00633d8
--- /dev/null
+++ b/libc/src/exit.c
_AT_@ -0,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+
+void (*_atexitf[_ATEXIT_MAX])(void);
+
+void
+exit(int status)
+{
+ void (**bp)(void);
+
+ for (bp = _atexitf; bp < &_atexitf[_ATEXIT_MAX] && *bp; ++bp)
+ (*bp)();
+ _Exit();
+}
Received on Fri Mar 03 2017 - 10:40:54 CET
This archive was generated by hypermail 2.3.0
: Fri Mar 03 2017 - 10:48:18 CET