xref: /illumos-gate/usr/src/head/iso/stdlib_iso.h (revision b9538c2103fde34bfe8a8c2b3e878ecd1586d182)
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 2014 Garrett D'Amore <garrett@damore.org>
24  * Copyright 2014 PALO, Richard.
25  *
26  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 /*	Copyright (c) 1988 AT&T	*/
31 /*	  All Rights Reserved	*/
32 
33 
34 /*
35  * An application should not include this header directly.  Instead it
36  * should be included only through the inclusion of other Sun headers.
37  *
38  * The contents of this header is limited to identifiers specified in the
39  * C Standard.  Any new identifiers specified in future amendments to the
40  * C Standard must be placed in this header.  If these new identifiers
41  * are required to also be in the C++ Standard "std" namespace, then for
42  * anything other than macro definitions, corresponding "using" directives
43  * must also be added to <locale.h>.
44  */
45 
46 #ifndef _ISO_STDLIB_ISO_H
47 #define	_ISO_STDLIB_ISO_H
48 
49 #include <sys/feature_tests.h>
50 #include <sys/null.h>
51 
52 #ifdef	__cplusplus
53 extern "C" {
54 #endif
55 
56 unsigned char __mb_cur_max(void);
57 #ifndef MB_CUR_MAX
58 #define	MB_CUR_MAX	(__mb_cur_max())
59 #endif
60 
61 #if __cplusplus >= 199711L
62 namespace std {
63 #endif
64 
65 typedef	struct {
66 	int	quot;
67 	int	rem;
68 } div_t;
69 
70 typedef struct {
71 	long	quot;
72 	long	rem;
73 } ldiv_t;
74 
75 #if !defined(_SIZE_T) || __cplusplus >= 199711L
76 #define	_SIZE_T
77 #if defined(_LP64) || defined(_I32LPx)
78 typedef unsigned long	size_t;		/* size of something in bytes */
79 #else
80 typedef unsigned int    size_t;		/* (historical version) */
81 #endif
82 #endif	/* !_SIZE_T */
83 
84 #define	EXIT_FAILURE	1
85 #define	EXIT_SUCCESS    0
86 #define	RAND_MAX	32767
87 
88 /*
89  * wchar_t is a built-in type in standard C++ and as such is not
90  * defined here when using standard C++. However, the GNU compiler
91  * fixincludes utility nonetheless creates its own version of this
92  * header for use by gcc and g++. In that version it adds a redundant
93  * guard for __cplusplus. To avoid the creation of a gcc/g++ specific
94  * header we need to include the following magic comment:
95  *
96  * we must use the C++ compiler's type
97  *
98  * The above comment should not be removed or changed until GNU
99  * gcc/fixinc/inclhack.def is updated to bypass this header.
100  */
101 #if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__))
102 #ifndef _WCHAR_T
103 #define	_WCHAR_T
104 #if defined(_LP64)
105 typedef	int	wchar_t;
106 #else
107 typedef long	wchar_t;
108 #endif
109 #endif	/* !_WCHAR_T */
110 #endif	/* !defined(__cplusplus) ... */
111 
112 #if !defined(_NORETURN_KYWD)
113 #if __STDC_VERSION__ - 0 >= 201112L
114 #define	_NORETURN_KYWD	_Noreturn
115 #else
116 #define	_NORETURN_KYWD
117 #endif	/* __STDC_VERSION__ - 0 >= 201112L */
118 #endif	/* !defined(_NORETURN_KYWD) */
119 
120 extern _NORETURN_KYWD void abort(void) __NORETURN;
121 extern int abs(int);
122 extern int atexit(void (*)(void));
123 extern double atof(const char *);
124 extern int atoi(const char *);
125 extern long int atol(const char *);
126 extern void *bsearch(const void *, const void *, size_t, size_t,
127 	int (*)(const void *, const void *));
128 #if __cplusplus >= 199711L && defined(__SUNPRO_CC)
129 extern "C++" {
130 	void *bsearch(const void *, const void *, size_t, size_t,
131 		int (*)(const void *, const void *));
132 }
133 #endif /* __cplusplus >= 199711L && defined(__SUNPRO_CC) */
134 extern void *calloc(size_t, size_t);
135 extern div_t div(int, int);
136 extern _NORETURN_KYWD void exit(int)
137 	__NORETURN;
138 extern void free(void *);
139 extern char *getenv(const char *);
140 extern long int labs(long);
141 extern ldiv_t ldiv(long, long);
142 extern void *malloc(size_t);
143 extern int mblen(const char *, size_t);
144 extern size_t mbstowcs(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
145 	size_t);
146 extern int mbtowc(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, size_t);
147 extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
148 #if __cplusplus >= 199711L && defined(__SUNPRO_CC)
149 extern "C++" {
150 	void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
151 }
152 #endif /* __cplusplus >= 199711L && defined(__SUNPRO_CC) */
153 extern int rand(void);
154 extern void *realloc(void *, size_t);
155 extern void srand(unsigned int);
156 extern double strtod(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD);
157 extern long int strtol(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD, int);
158 extern unsigned long int strtoul(const char *_RESTRICT_KYWD,
159 	char **_RESTRICT_KYWD, int);
160 extern int system(const char *);
161 extern int wctomb(char *, wchar_t);
162 extern size_t wcstombs(char *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
163 	size_t);
164 
165 #if __cplusplus >= 199711L
166 extern "C++" {
167 	inline long   abs(long _l) { return labs(_l); }
168 	inline ldiv_t div(long _l1, long _l2) { return ldiv(_l1, _l2); }
169 }
170 #endif /* __cplusplus */
171 
172 #if __cplusplus >= 199711L
173 }
174 #endif /* end of namespace std */
175 
176 #ifdef	__cplusplus
177 }
178 #endif
179 
180 #endif	/* _ISO_STDLIB_ISO_H */
181