X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc.so_src%2Fstdlib.c;h=191f5261bd7d588e5e711670941b59fe39ccf682;hb=4bd23d4ae51bd5cb92b449bcd66e0d2de88c7fc9;hp=850d2695d7ce45e02a7bb3ac6340f59098c31675;hpb=71127582530c214c99852fda37f7e5296774a26f;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc.so_src/stdlib.c b/Usermode/Libraries/libc.so_src/stdlib.c index 850d2695..191f5261 100644 --- a/Usermode/Libraries/libc.so_src/stdlib.c +++ b/Usermode/Libraries/libc.so_src/stdlib.c @@ -13,17 +13,31 @@ #define _stdout 1 #define _stdin 0 +extern void *_crt0_exit_handler; + // === PROTOTYPES === EXPORT int atoi(const char *str); EXPORT void exit(int status); +// === GLOBALS === +void (*g_stdlib_exithandler)(void); + // === CODE === +void atexit(void (*__func)(void)) +{ + g_stdlib_exithandler = __func; + // TODO: Replace with meta-function to allow multiple atexit() handlers + _crt0_exit_handler = __func; +} + /** * \fn EXPORT void exit(int status) * \brief Exit */ EXPORT void exit(int status) { + if( g_stdlib_exithandler ) + g_stdlib_exithandler(); _exit(status); } @@ -35,6 +49,10 @@ EXPORT void exit(int status) EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) { int i, j, min; + // With 0 items, there's nothing to do and with 1 its already sorted + if(nmemb == 0 || nmemb == 1) return; + + // SORT! for( i = 0; i < (nmemb-1); i++ ) { min = i;