2 * AcessOS Basic C Library
\r
5 #include <acess/sys.h>
\r
10 extern void _stdio_cleanup(void);
\r
12 #define MAX_ATEXIT_HANDLERS 64 // Standard defines >=32
\r
14 // === PROTOTYPES ===
\r
15 EXPORT int atoi(const char *str);
\r
16 EXPORT void exit(int status);
\r
19 typedef void (*stdlib_exithandler_t)(void);
\r
20 stdlib_exithandler_t g_stdlib_exithandlers[MAX_ATEXIT_HANDLERS];
\r
21 int g_stdlib_num_exithandlers;
\r
24 void _call_atexit_handlers(void)
\r
27 for( i = g_stdlib_num_exithandlers; i --; )
\r
28 g_stdlib_exithandlers[i]();
\r
32 EXPORT void atexit(void (*__func)(void))
\r
34 if( g_stdlib_num_exithandlers < MAX_ATEXIT_HANDLERS )
\r
36 g_stdlib_exithandlers[g_stdlib_num_exithandlers++] = __func;
\r
41 * \fn EXPORT void exit(int status)
\r
44 EXPORT void exit(int status)
\r
46 _call_atexit_handlers();
\r
51 * \fn EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
\r
52 * \brief Sort an array
\r
53 * \note Uses a selection sort
\r
55 EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
\r
58 // With 0 items, there's nothing to do and with 1 its already sorted
\r
59 if(nmemb == 0 || nmemb == 1) return;
\r
62 for( i = 0; i < (nmemb-1); i++ )
\r
65 for( j = i+1; j < nmemb; j++ )
\r
67 if(compar(base+size*j, base + size*min) < 0) {
\r
73 memcpy(swap, base+size*i, size);
\r
74 memcpy(base+size*i, base+size*min, size);
\r
75 memcpy(base+size*i, swap, size);
\r
81 int abs(int j) { return j < 0 ? -j : j; }
\r
82 long int labs(long int j) { return j < 0 ? -j : j; }
\r