check in work in progress on the arm port
[newos.git] / include / libc / stdlib.h
blobcfafe074deca3b87714961a3239eadae77239067
1 /*
2 ** Copyright 2002-2003, Travis Geiselbrecht. All rights reserved.
3 ** Copyright 2002, Manuel J. Petit. All rights reserved.
4 ** Distributed under the terms of the NewOS License.
5 */
7 #ifndef __newos__libc_stdlib__hh__
8 # define __newos__libc_stdlib__hh__
11 # include <stddef.h>
13 # ifdef __cplusplus
14 # include <new>
15 # endif
17 # ifdef __cplusplus
18 namespace std
19 {extern "C" {
20 # endif
23 int atoi(char const *);
24 unsigned int atoui(const char *num);
25 long atol(const char *num);
26 unsigned long atoul(const char *num);
28 long strtol(const char *nptr, char **endptr, int base);
29 unsigned long strtoul(const char *nptr, char **endptr, int base);
31 void * malloc(size_t);
32 void free(void *);
33 void * realloc(void *, size_t);
34 void * calloc(size_t, size_t);
36 char *getenv(char const *);
38 void *bsearch(void const *, void const *, size_t, size_t, int (*) (void const *, void const *));
39 void qsort(void *, size_t, size_t, int (*)(void const *, void const *));
41 # define RAND_MAX 0x7fffffff
42 int rand(void);
43 void srand(unsigned);
45 # if !_KERNEL
46 void abort(void);
47 void exit(int);
48 void _Exit(int);
49 # endif
51 # ifdef __cplusplus
52 }} /* extern "C" */
53 # endif
55 /* terrible hack to get around the different kernel name for malloc and free */
56 # if _KERNEL
57 # define malloc kmalloc
58 # define free kfree
59 # include <kernel/heap.h>
60 # endif
62 # define max(a, b) ((a) > (b) ? (a) : (b))
63 # define min(a, b) ((a) < (b) ? (a) : (b))
65 // non (C++) standard stuff goes here
66 # ifdef __cplusplus
67 extern "C"
69 // define size_t to be correct in C++
70 # define size_t ::std::size_t
71 # endif
73 int setenv(char const *, char const *, int);
74 int putenv(char const *);
75 void unsetenv(char const *);
77 int heapsort(void *, size_t , size_t , int (*)(void const *, void const *));
78 int mergesort(void *, size_t, size_t, int (*)(void const *, void const *));
79 int radixsort(unsigned char const **, int, unsigned char const *, unsigned int);
80 int sradixsort(unsigned char const **, int, unsigned char const *, unsigned int);
82 void * reallocf(void *, size_t);
83 void * memalign(size_t, size_t);
84 void * valloc(size_t);
86 long long strtoll(const char *nptr, char **endptr, int base);
87 unsigned long long strtoull(const char *nptr, char **endptr, int base);
89 /* getopt related items */
90 extern char *optarg;
91 extern int optind;
92 extern int optopt;
93 extern int opterr;
94 extern int optreset;
96 int getopt(int argc, char * const *argv, const char *optstring);
98 int rand_r(unsigned int *ctx);
99 long random(void);
100 void srandom(unsigned long);
102 # if !_KERNEL
103 void _exit(int);
104 # endif
106 # ifdef __cplusplus
107 # undef size_t
109 # endif
111 #endif // end of include gaurd
113 #if defined(__cplusplus) && !defined(_NEWOS_NO_LIBC_COMPAT)
114 using ::std::abort;
115 //using ::std::atexit;
116 using ::std::exit;
118 using ::std::getenv;
119 //using ::std::system;
121 using ::std::calloc;
122 using ::std::malloc;
123 using ::std::realloc;
124 using ::std::free;
126 using ::std::atol;
127 //using ::std::atof;
128 using ::std::atoi;
129 //using ::std::mblen;
130 //using ::std::mbstowcs;
131 //using ::std::mbtowc;
132 //using ::std::strtod;
133 using ::std::strtol;
134 using ::std::strtoul;
135 //using ::std::wctomb;
136 //using ::std::wcstombs;
138 using ::std::bsearch;
139 using ::std::qsort;
141 //using ::std::abs;
142 //using ::std::div;
143 //using ::std::labs;
144 //using ::std::ldiv;
145 using ::std::srand;
146 using ::std::rand;
147 #endif