xref: /illumos-gate/usr/src/head/iso/stdlib_iso.h (revision b55148877d473978f0b46d593fd6213fa526fcc5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 /*
32  * An application should not include this header directly.  Instead it
33  * should be included only through the inclusion of other Sun headers.
34  *
35  * The contents of this header is limited to identifiers specified in the
36  * C Standard.  Any new identifiers specified in future amendments to the
37  * C Standard must be placed in this header.  If these new identifiers
38  * are required to also be in the C++ Standard "std" namespace, then for
39  * anything other than macro definitions, corresponding "using" directives
40  * must also be added to <locale.h>.
41  */
42 
43 #ifndef _ISO_STDLIB_ISO_H
44 #define	_ISO_STDLIB_ISO_H
45 
46 #pragma ident	"%Z%%M%	%I%	%E% SMI"
47 
48 #include <sys/feature_tests.h>
49 
50 #ifdef	__cplusplus
51 extern "C" {
52 #endif
53 
54 #if defined(__STDC__)
55 extern unsigned char	__ctype[];
56 #define	MB_CUR_MAX	__ctype[520]
57 #else
58 extern unsigned char	_ctype[];
59 #define	MB_CUR_MAX	_ctype[520]
60 #endif
61 
62 #if __cplusplus >= 199711L
63 namespace std {
64 #endif
65 
66 typedef	struct {
67 	int	quot;
68 	int	rem;
69 } div_t;
70 
71 typedef struct {
72 	long	quot;
73 	long	rem;
74 } ldiv_t;
75 
76 #if !defined(_SIZE_T) || __cplusplus >= 199711L
77 #define	_SIZE_T
78 #if defined(_LP64) || defined(_I32LPx)
79 typedef unsigned long	size_t;		/* size of something in bytes */
80 #else
81 typedef unsigned int    size_t;		/* (historical version) */
82 #endif
83 #endif	/* !_SIZE_T */
84 
85 #ifndef	NULL
86 #if defined(_LP64)
87 #define	NULL	0L
88 #else
89 #define	NULL	0
90 #endif
91 #endif
92 
93 #define	EXIT_FAILURE	1
94 #define	EXIT_SUCCESS    0
95 #define	RAND_MAX	32767
96 
97 /*
98  * wchar_t is a built-in type in standard C++ and as such is not
99  * defined here when using standard C++. However, the GNU compiler
100  * fixincludes utility nonetheless creates its own version of this
101  * header for use by gcc and g++. In that version it adds a redundant
102  * guard for __cplusplus. To avoid the creation of a gcc/g++ specific
103  * header we need to include the following magic comment:
104  *
105  * we must use the C++ compiler's type
106  *
107  * The above comment should not be removed or changed until GNU
108  * gcc/fixinc/inclhack.def is updated to bypass this header.
109  */
110 #if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__))
111 #ifndef _WCHAR_T
112 #define	_WCHAR_T
113 #if defined(_LP64)
114 typedef	int	wchar_t;
115 #else
116 typedef long	wchar_t;
117 #endif
118 #endif	/* !_WCHAR_T */
119 #endif	/* !defined(__cplusplus) ... */
120 
121 #if defined(__STDC__)
122 
123 extern void abort(void) __NORETURN;
124 extern int abs(int);
125 extern int atexit(void (*)(void));
126 extern double atof(const char *);
127 extern int atoi(const char *);
128 extern long int atol(const char *);
129 extern void *bsearch(const void *, const void *, size_t, size_t,
130 	int (*)(const void *, const void *));
131 #if __cplusplus >= 199711L
132 extern "C++" {
133 	void *bsearch(const void *, const void *, size_t, size_t,
134 		int (*)(const void *, const void *));
135 }
136 #endif /* __cplusplus >= 199711L */
137 extern void *calloc(size_t, size_t);
138 extern div_t div(int, int);
139 extern void exit(int)
140 	__NORETURN;
141 extern void free(void *);
142 extern char *getenv(const char *);
143 extern long int labs(long);
144 extern ldiv_t ldiv(long, long);
145 extern void *malloc(size_t);
146 extern int mblen(const char *, size_t);
147 extern size_t mbstowcs(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
148 	size_t);
149 extern int mbtowc(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, size_t);
150 extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
151 #if __cplusplus >= 199711L
152 extern "C++" {
153 	void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
154 }
155 #endif /* __cplusplus >= 199711L */
156 extern int rand(void);
157 extern void *realloc(void *, size_t);
158 extern void srand(unsigned int);
159 extern double strtod(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD);
160 extern long int strtol(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD, int);
161 extern unsigned long int strtoul(const char *_RESTRICT_KYWD,
162 	char **_RESTRICT_KYWD, int);
163 extern int system(const char *);
164 extern int wctomb(char *, wchar_t);
165 extern size_t wcstombs(char *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
166 	size_t);
167 
168 #if __cplusplus >= 199711L
169 extern "C++" {
170 	inline long   abs(long _l) { return labs(_l); }
171 	inline ldiv_t div(long _l1, long _l2) { return ldiv(_l1, _l2); }
172 }
173 #endif /* __cplusplus */
174 
175 #else /* not __STDC__ */
176 
177 extern void abort();
178 extern int abs();
179 extern int atexit();
180 extern double atof();
181 extern int atoi();
182 extern long int atol();
183 extern void *bsearch();
184 extern void *calloc();
185 extern div_t div();
186 extern void exit();
187 extern void free();
188 extern char *getenv();
189 extern long int labs();
190 extern ldiv_t ldiv();
191 extern void *malloc();
192 extern int mblen();
193 extern size_t mbstowcs();
194 extern int mbtowc();
195 extern void qsort();
196 extern int rand();
197 extern void *realloc();
198 extern void srand();
199 extern double strtod();
200 extern long int strtol();
201 extern unsigned long strtoul();
202 extern int system();
203 extern int wctomb();
204 extern size_t wcstombs();
205 
206 #endif	/* __STDC__ */
207 
208 #if __cplusplus >= 199711L
209 }
210 #endif /* end of namespace std */
211 
212 #ifdef	__cplusplus
213 }
214 #endif
215 
216 #endif	/* _ISO_STDLIB_ISO_H */
217