X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc.so_src%2Fstdlib.c;h=6e81c654ea82b905e50c70f56e40ed23486837da;hb=36b950d17b828c7cd2e5e9dbe5fb4cbded89889c;hp=733cb919a8cfadd09f217301b3940e5a5ee899c6;hpb=7941d6b368acb0abc17e6a77ffaf7b4c306b67ab;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc.so_src/stdlib.c b/Usermode/Libraries/libc.so_src/stdlib.c index 733cb919..6e81c654 100644 --- a/Usermode/Libraries/libc.so_src/stdlib.c +++ b/Usermode/Libraries/libc.so_src/stdlib.c @@ -2,16 +2,12 @@ * AcessOS Basic C Library * stdlib.c */ -/** - * \todo Move half of these to stdio - */ #include #include #include #include "lib.h" -#define _stdout 1 -#define _stdin 0 +extern void *_crt0_exit_handler; // === PROTOTYPES === EXPORT int atoi(const char *str); @@ -24,6 +20,8 @@ void (*g_stdlib_exithandler)(void); void atexit(void (*__func)(void)) { g_stdlib_exithandler = __func; + // TODO: Replace with meta-function to allow multiple atexit() handlers + _crt0_exit_handler = __func; } /** @@ -32,6 +30,8 @@ void atexit(void (*__func)(void)) */ EXPORT void exit(int status) { + if( g_stdlib_exithandler ) + g_stdlib_exithandler(); _exit(status); } @@ -42,7 +42,7 @@ 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; + size_t i, j, min; // With 0 items, there's nothing to do and with 1 its already sorted if(nmemb == 0 || nmemb == 1) return; @@ -65,66 +65,7 @@ EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void } } -/** - * \fn EXPORT int atoi(const char *str) - * \brief Convert a string to an integer - */ -EXPORT int atoi(const char *str) -{ - int neg = 0; - int ret = 0; - - // NULL Check - if(!str) return 0; - - while(*str == ' ' || *str == '\t') str++; - - // Check for negative - if(*str == '-') { - neg = 1; - str++; - } - - if(*str == '0') { - str ++; - if(*str == 'x') { - str++; - // Hex - while( ('0' <= *str && *str <= '9') - || ('A' <= *str && *str <= 'F' ) - || ('a' <= *str && *str <= 'f' ) - ) - { - ret *= 16; - if(*str <= '9') { - ret += *str - '0'; - } else if (*str <= 'F') { - ret += *str - 'A' + 10; - } else { - ret += *str - 'a' + 10; - } - str++; - } - } else { - // Octal - while( '0' <= *str && *str <= '7' ) - { - ret *= 8; - ret += *str - '0'; - str++; - } - } - } else { - // Decimal - while( '0' <= *str && *str <= '9' ) - { - ret *= 10; - ret += *str - '0'; - str++; - } - } - - // Negate if needed - if(neg) ret = -ret; - return ret; -} + +int abs(int j) { return j < 0 ? -j : j; } +long int labs(long int j) { return j < 0 ? -j : j; } +