OSDN Git Service

A bunch of updates, part from Manuel Novoa III (such as more long long
[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_MIN
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 #ifndef __HAS_NO_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
62
63 /* Memory management functions */
64 extern __ptr_t calloc __P ((size_t, size_t));
65 extern __ptr_t malloc __P ((size_t));
66 extern __ptr_t realloc __P ((__ptr_t, size_t));
67 extern void free __P ((__ptr_t));
68
69 #ifdef DEBUG_MALLOC
70 extern __ptr_t calloc_dbg __P ((size_t, size_t, char* func, char* file, int line));
71 extern __ptr_t malloc_dbg __P ((size_t, char* func, char* file, int line));
72 extern __ptr_t realloc_dbg __P ((__ptr_t, size_t, char* func, char* file, int line));
73 extern void free_dbg __P ((__ptr_t, char* func, char* file, int line));
74 #define calloc(x,y) calloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
75 #define malloc(x) malloc_dbg((x),__FUNCTION__,__FILE__,__LINE__)
76 #define realloc(x) realloc((x),__FUNCTION__,__FILE__,__LINE__)
77 #define free(x) free_dbg((x),__FUNCTION__,__FILE__,__LINE__)
78 #endif
79
80
81
82 /* System and environment functions */
83 extern void abort __P ((void)) __attribute__ ((__noreturn__));
84 extern int atexit __P ((void (*__func) (void)));
85 extern void exit __P ((int __status)) __attribute__ ((__noreturn__));
86 extern void _exit __P ((int __status)) __attribute__ ((__noreturn__));
87 extern char *getenv __P ((__const char *__name));
88 extern int putenv __P ((__const char *__string));
89 extern char *realpath __P ((__const char *__restrict __name,
90             char *__restrict __resolved));
91 extern int setenv __P ((__const char *__name, __const char *__value,
92                         int __replace));
93 extern int system __P ((__const char *__command));
94 extern void unsetenv __P ((__const char *__name));
95
96
97
98 /* Search and sort functions */
99 extern __ptr_t bsearch __P ((__const __ptr_t __key, __const __ptr_t __base,
100                            size_t __nmemb, size_t __size, __compar_fn_t __compar));
101 extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size,
102                           __compar_fn_t __compar));
103
104
105
106 /* Integer math functions */
107 extern int abs __P ((int __x)) __attribute__ ((__const__));
108 extern div_t div __P ((int __numer, int __denom)) __attribute__ ((__const__));
109 extern long int labs __P ((long int __x)) __attribute__ ((__const__));
110 extern ldiv_t ldiv __P ((long int __numer, long int __denom)) __attribute__ ((__const__));
111
112 /* Generate a unique temporary file name from TEMPLATE. */
113 extern char *mktemp __P ((char *__template));
114 extern int mkstemp __P ((char *__template));
115
116
117 #endif /* __STDLIB_H */