summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-27 01:55:39 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-27 01:55:39 +0100
commitbaab9f4402421cb72ec664cd77fdb5aa600b2f25 (patch)
tree2e62bdb56fde409ae19995e6c37668279f6920b6
parent2a858719be2ddc85d71184aff719312a4f3b2f25 (diff)
downloadserenity-baab9f4402421cb72ec664cd77fdb5aa600b2f25.zip
LibC: Implement atexit() and strtoul().
-rw-r--r--LibC/stdlib.cpp30
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;
}
}