OSDN Git Service

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