2 * AcessOS Basic C Library
\r
6 * \todo Move half of these to stdio
\r
8 #include <acess/sys.h>
\r
16 // === PROTOTYPES ===
\r
17 EXPORT int atoi(const char *str);
\r
18 EXPORT void exit(int status);
\r
21 void (*g_stdlib_exithandler)(void);
\r
24 void atexit(void (*__func)(void))
\r
26 g_stdlib_exithandler = __func;
\r
30 * \fn EXPORT void exit(int status)
\r
33 EXPORT void exit(int status)
\r
35 if( g_stdlib_exithandler )
\r
36 g_stdlib_exithandler();
\r
41 * \fn EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
\r
42 * \brief Sort an array
\r
43 * \note Uses a selection sort
\r
45 EXPORT void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
\r
48 // With 0 items, there's nothing to do and with 1 its already sorted
\r
49 if(nmemb == 0 || nmemb == 1) return;
\r
52 for( i = 0; i < (nmemb-1); i++ )
\r
55 for( j = i+1; j < nmemb; j++ )
\r
57 if(compar(base+size*j, base + size*min) < 0) {
\r
63 memcpy(swap, base+size*i, size);
\r
64 memcpy(base+size*i, base+size*min, size);
\r
65 memcpy(base+size*i, swap, size);
\r
71 * \fn EXPORT int atoi(const char *str)
\r
72 * \brief Convert a string to an integer
\r
74 EXPORT int atoi(const char *str)
\r
82 while(*str == ' ' || *str == '\t') str++;
\r
84 // Check for negative
\r
95 while( ('0' <= *str && *str <= '9')
\r
96 || ('A' <= *str && *str <= 'F' )
\r
97 || ('a' <= *str && *str <= 'f' )
\r
103 } else if (*str <= 'F') {
\r
104 ret += *str - 'A' + 10;
\r
106 ret += *str - 'a' + 10;
\r
112 while( '0' <= *str && *str <= '7' )
\r
121 while( '0' <= *str && *str <= '9' )
\r
129 // Negate if needed
\r
130 if(neg) ret = -ret;
\r