2 * AcessOS Basic C Library
\r
5 #include <acess/sys.h>
\r
10 extern void *_crt0_exit_handler;
\r
12 // === PROTOTYPES ===
\r
13 EXPORT int atoi(const char *str);
\r
14 EXPORT void exit(int status);
\r
17 void (*g_stdlib_exithandler)(void);
\r
20 void atexit(void (*__func)(void))
\r
22 g_stdlib_exithandler = __func;
\r
23 // TODO: Replace with meta-function to allow multiple atexit() handlers
\r
24 _crt0_exit_handler = __func;
\r
28 * \fn EXPORT void exit(int status)
\r
31 EXPORT void exit(int status)
\r
33 if( g_stdlib_exithandler )
\r
34 g_stdlib_exithandler();
\r
39 * \fn EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
\r
40 * \brief Sort an array
\r
41 * \note Uses a selection sort
\r
43 EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
\r
46 // With 0 items, there's nothing to do and with 1 its already sorted
\r
47 if(nmemb == 0 || nmemb == 1) return;
\r
50 for( i = 0; i < (nmemb-1); i++ )
\r
53 for( j = i+1; j < nmemb; j++ )
\r
55 if(compar(base+size*j, base + size*min) < 0) {
\r
61 memcpy(swap, base+size*i, size);
\r
62 memcpy(base+size*i, base+size*min, size);
\r
63 memcpy(base+size*i, swap, size);
\r
69 int abs(int j) { return j < 0 ? -j : j; }
\r
70 long int labs(long int j) { return j < 0 ? -j : j; }
\r