xref: /illumos-gate/usr/src/head/iso/stdlib_iso.h (revision 9498083eeaed1aacdde41369b7fa6f3b84870791)
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 extern void abort(void) __NORETURN;
113 extern int abs(int);
114 extern int atexit(void (*)(void));
115 extern double atof(const char *);
116 extern int atoi(const char *);
117 extern long int atol(const char *);
118 extern void *bsearch(const void *, const void *, size_t, size_t,
119 	int (*)(const void *, const void *));
120 #if __cplusplus >= 199711L && defined(__SUNPRO_CC)
121 extern "C++" {
122 	void *bsearch(const void *, const void *, size_t, size_t,
123 		int (*)(const void *, const void *));
124 }
125 #endif /* __cplusplus >= 199711L && defined(__SUNPRO_CC) */
126 extern void *calloc(size_t, size_t);
127 extern div_t div(int, int);
128 extern void exit(int)
129 	__NORETURN;
130 extern void free(void *);
131 extern char *getenv(const char *);
132 extern long int labs(long);
133 extern ldiv_t ldiv(long, long);
134 extern void *malloc(size_t);
135 extern int mblen(const char *, size_t);
136 extern size_t mbstowcs(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
137 	size_t);
138 extern int mbtowc(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, size_t);
139 extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
140 #if __cplusplus >= 199711L && defined(__SUNPRO_CC)
141 extern "C++" {
142 	void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
143 }
144 #endif /* __cplusplus >= 199711L && defined(__SUNPRO_CC) */
145 extern int rand(void);
146 extern void *realloc(void *, size_t);
147 extern void srand(unsigned int);
148 extern double strtod(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD);
149 extern long int strtol(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD, int);
150 extern unsigned long int strtoul(const char *_RESTRICT_KYWD,
151 	char **_RESTRICT_KYWD, int);
152 extern int system(const char *);
153 extern int wctomb(char *, wchar_t);
154 extern size_t wcstombs(char *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
155 	size_t);
156 
157 #if __cplusplus >= 199711L
158 extern "C++" {
159 	inline long   abs(long _l) { return labs(_l); }
160 	inline ldiv_t div(long _l1, long _l2) { return ldiv(_l1, _l2); }
161 }
162 #endif /* __cplusplus */
163 
164 #if __cplusplus >= 199711L
165 }
166 #endif /* end of namespace std */
167 
168 #ifdef	__cplusplus
169 }
170 #endif
171 
172 #endif	/* _ISO_STDLIB_ISO_H */
173