OSDN Git Service

A patch from Matthias Kilian <kili@outback.escape.de> to fix -DDEBUG_MALLOC
[uclinux-h8/uClibc.git] / include / stdlib.h
1 /* stdlib.h  */
2 #ifndef __STDLIB_H
3 #define __STDLIB_H
4
5 #include <features.h>
6 #include <sys/types.h>
7 #include <limits.h>
8
9 /* Don't overwrite user definitions of NULL */
10 #ifndef NULL
11 #define NULL ((void *) 0)
12 #endif
13
14 /* We define these the same for all machines.
15  * Changes from this to the outside world should be done in `_exit'.  */
16 #define EXIT_FAILURE    1       /* Failing exit status.  */
17 #define EXIT_SUCCESS    0       /* Successful exit status.  */
18
19 /* The largest number rand will return */
20 #define RAND_MAX        INT_MAX
21
22 /* Maximum length of a multibyte character in the current locale.  */
23 #define MB_CUR_MAX  1
24
25 typedef struct
26 {
27     int quot;                   /* Quotient.  */
28     int rem;                    /* Remainder.  */
29 } div_t;
30
31 typedef struct
32 {
33     long int quot;              /* Quotient.  */
34     long int rem;               /* Remainder.  */
35 } ldiv_t;
36
37 /*  comparison function used by bsearch() and qsort() */
38 typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
39 typedef __compar_fn_t comparison_fn_t;
40
41
42 /* String to number conversion functions */
43 #define atof(x) strtod((x),(char**)0)
44 #define atoi(x) (int)strtol((x),(char**)0,10)
45 #define atol(x) strtol((x),(char**)0,10)
46 #define atoll(x) strtoll((x),(char**)0,10)
47 extern long strtol __P ((const char * nptr, char ** endptr, int base));
48 extern unsigned long strtoul __P ((const char * nptr, char ** endptr, int base));
49 extern long long strtoll __P ((const char * nptr, char ** endptr, int base));
50 extern unsigned long long strtoull __P ((const char * nptr, char ** endptr, int base));
51 #ifdef __UCLIBC_HAS_FLOATS__
52 /*TODO: extern char * gcvt __P ((double number, size_t ndigit, char * buf)); */
53 extern double strtod __P ((const char * nptr, char ** endptr));
54 #endif
55
56
57
58 /* Random number functions */
59 extern int rand __P ((void));
60 extern void srand __P ((unsigned int seed));
61 extern long int random(void);
62 extern void srandom(unsigned int seed);
63
64 /* Memory management functions */
65 extern __ptr_t calloc __P ((size_t, size_t));
66 extern __ptr_t malloc __P ((size_t));
67 extern __ptr_t realloc __P ((__ptr_t, size_t));
68 extern void free __P ((__ptr_t));
69 /* Allocate a block on the stack that will be freed 
70  * when the calling function exits.  We use gcc's
71  * version to make life better... */
72 #undef  alloca
73 extern __ptr_t alloca __P ((size_t __size));
74 #define alloca(size)    __builtin_alloca (size)
75
76 #ifdef DEBUG_MALLOC
77 extern __ptr_t calloc_dbg __P ((size_t, size_t, char* func, char* file, int line));
78 extern __ptr_t malloc_dbg __P ((size_t, char* func, char* file, int line));
79 extern __ptr_t realloc_dbg __P ((__ptr_t, size_t, char* func, char* file, int line));
80 extern void free_dbg __P ((__ptr_t, char* func, char* file, int line));
81 #define calloc(x,y) calloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
82 #define malloc(x) malloc_dbg((x),__FUNCTION__,__FILE__,__LINE__)
83 #define realloc(x,y) realloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
84 #define free(x) free_dbg((x),__FUNCTION__,__FILE__,__LINE__)
85 #endif
86
87
88
89 /* System and environment functions */
90 extern void abort __P ((void)) __attribute__ ((__noreturn__));
91 extern int atexit __P ((void (*__func) (void)));
92 extern void exit __P ((int __status)) __attribute__ ((__noreturn__));
93 extern void _exit __P ((int __status)) __attribute__ ((__noreturn__));
94 extern char *getenv __P ((__const char *__name));
95 extern int putenv __P ((__const char *__string));
96 extern char *realpath __P ((__const char *__restrict __name,
97             char *__restrict __resolved));
98 extern int setenv __P ((__const char *__name, __const char *__value,
99                         int __replace));
100 extern int system __P ((__const char *__command));
101 extern void unsetenv __P ((__const char *__name));
102
103 /* The following is used by uClibc in atexit.c and sysconf.c */
104 #define __UCLIBC_MAX_ATEXIT     20
105
106 /* Search and sort functions */
107 extern __ptr_t bsearch __P ((__const __ptr_t __key, __const __ptr_t __base,
108                            size_t __nmemb, size_t __size, __compar_fn_t __compar));
109 extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size,
110                           __compar_fn_t __compar));
111
112
113
114 /* Integer math functions */
115 extern int abs __P ((int __x)) __attribute__ ((__const__));
116 extern div_t div __P ((int __numer, int __denom)) __attribute__ ((__const__));
117 extern long int labs __P ((long int __x)) __attribute__ ((__const__));
118 extern ldiv_t ldiv __P ((long int __numer, long int __denom)) __attribute__ ((__const__));
119
120 /* Generate a unique temporary file name from TEMPLATE. */
121 extern char *mktemp __P ((char *__template));
122 extern int mkstemp __P ((char *__template));
123
124
125 #endif /* __STDLIB_H */