diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-27 01:55:39 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-27 01:55:39 +0100 |
commit | baab9f4402421cb72ec664cd77fdb5aa600b2f25 (patch) | |
tree | 2e62bdb56fde409ae19995e6c37668279f6920b6 /LibC/stdlib.cpp | |
parent | 2a858719be2ddc85d71184aff719312a4f3b2f25 (diff) | |
download | serenity-baab9f4402421cb72ec664cd77fdb5aa600b2f25.zip |
LibC: Implement atexit() and strtoul().
Diffstat (limited to 'LibC/stdlib.cpp')
-rw-r--r-- | LibC/stdlib.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/LibC/stdlib.cpp b/LibC/stdlib.cpp index 1a8de12ec5..8bd49ed5ee 100644 --- a/LibC/stdlib.cpp +++ b/LibC/stdlib.cpp @@ -201,12 +201,28 @@ void* realloc(void *ptr, size_t size) return new_ptr; } +typedef void(*__atexit_handler)(); +static int __atexit_handler_count = 0; +static __atexit_handler __atexit_handlers[32]; + void exit(int status) { + for (int i = 0; i < __atexit_handler_count; ++i) + __atexit_handlers[i](); + extern void _fini(); + _fini(); _exit(status); assert(false); } +int atexit(void (*handler)()) +{ + ASSERT(__atexit_handler_count < 32); + __atexit_handlers[__atexit_handler_count++] = handler; + return 0; +} + + void abort() { // FIXME: Implement proper abort(). @@ -425,12 +441,6 @@ size_t mbstowcs(wchar_t*, const char*, size_t) assert(false); } -int atexit(void (*function)()) -{ - (void)function; - assert(false); -} - long strtol(const char* str, char** endptr, int base) { const char* s = str; @@ -488,11 +498,11 @@ long strtol(const char* str, char** endptr, int base) return acc; } -unsigned long strtoul(const char*, char** endptr, int base) +unsigned long strtoul(const char* str, char** endptr, int base) { - (void)endptr; - (void)base; - assert(false); + auto value = strtol(str, endptr, base); + ASSERT(value >= 0); + return value; } } |