xref: /illumos-gate/usr/src/head/iso/stdlib_iso.h (revision b4203d75)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
244870e0a7SRichard PALO  * Copyright 2014 PALO, Richard.
25ba3594baSGarrett D'Amore  *
267c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
31*b4203d75SMarcel Telka /*	  All Rights Reserved	*/
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * An application should not include this header directly.  Instead it
367c478bd9Sstevel@tonic-gate  * should be included only through the inclusion of other Sun headers.
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  * The contents of this header is limited to identifiers specified in the
397c478bd9Sstevel@tonic-gate  * C Standard.  Any new identifiers specified in future amendments to the
407c478bd9Sstevel@tonic-gate  * C Standard must be placed in this header.  If these new identifiers
417c478bd9Sstevel@tonic-gate  * are required to also be in the C++ Standard "std" namespace, then for
427c478bd9Sstevel@tonic-gate  * anything other than macro definitions, corresponding "using" directives
437c478bd9Sstevel@tonic-gate  * must also be added to <locale.h>.
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifndef _ISO_STDLIB_ISO_H
477c478bd9Sstevel@tonic-gate #define	_ISO_STDLIB_ISO_H
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
504870e0a7SRichard PALO #include <sys/null.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
537c478bd9Sstevel@tonic-gate extern "C" {
547c478bd9Sstevel@tonic-gate #endif
557c478bd9Sstevel@tonic-gate 
562d08521bSGarrett D'Amore unsigned char __mb_cur_max(void);
572d08521bSGarrett D'Amore #ifndef MB_CUR_MAX
582d08521bSGarrett D'Amore #define	MB_CUR_MAX	(__mb_cur_max())
597c478bd9Sstevel@tonic-gate #endif
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #if __cplusplus >= 199711L
627c478bd9Sstevel@tonic-gate namespace std {
637c478bd9Sstevel@tonic-gate #endif
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate typedef	struct {
667c478bd9Sstevel@tonic-gate 	int	quot;
677c478bd9Sstevel@tonic-gate 	int	rem;
687c478bd9Sstevel@tonic-gate } div_t;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate typedef struct {
717c478bd9Sstevel@tonic-gate 	long	quot;
727c478bd9Sstevel@tonic-gate 	long	rem;
737c478bd9Sstevel@tonic-gate } ldiv_t;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #if !defined(_SIZE_T) || __cplusplus >= 199711L
767c478bd9Sstevel@tonic-gate #define	_SIZE_T
777c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx)
787c478bd9Sstevel@tonic-gate typedef unsigned long	size_t;		/* size of something in bytes */
797c478bd9Sstevel@tonic-gate #else
807c478bd9Sstevel@tonic-gate typedef unsigned int    size_t;		/* (historical version) */
817c478bd9Sstevel@tonic-gate #endif
827c478bd9Sstevel@tonic-gate #endif	/* !_SIZE_T */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #define	EXIT_FAILURE	1
857c478bd9Sstevel@tonic-gate #define	EXIT_SUCCESS    0
867c478bd9Sstevel@tonic-gate #define	RAND_MAX	32767
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * wchar_t is a built-in type in standard C++ and as such is not
907c478bd9Sstevel@tonic-gate  * defined here when using standard C++. However, the GNU compiler
91159cf8a6Swesolows  * fixincludes utility nonetheless creates its own version of this
927c478bd9Sstevel@tonic-gate  * header for use by gcc and g++. In that version it adds a redundant
937c478bd9Sstevel@tonic-gate  * guard for __cplusplus. To avoid the creation of a gcc/g++ specific
947c478bd9Sstevel@tonic-gate  * header we need to include the following magic comment:
957c478bd9Sstevel@tonic-gate  *
967c478bd9Sstevel@tonic-gate  * we must use the C++ compiler's type
977c478bd9Sstevel@tonic-gate  *
987c478bd9Sstevel@tonic-gate  * The above comment should not be removed or changed until GNU
997c478bd9Sstevel@tonic-gate  * gcc/fixinc/inclhack.def is updated to bypass this header.
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate #if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__))
1027c478bd9Sstevel@tonic-gate #ifndef _WCHAR_T
1037c478bd9Sstevel@tonic-gate #define	_WCHAR_T
1047c478bd9Sstevel@tonic-gate #if defined(_LP64)
1057c478bd9Sstevel@tonic-gate typedef	int	wchar_t;
1067c478bd9Sstevel@tonic-gate #else
1077c478bd9Sstevel@tonic-gate typedef long	wchar_t;
1087c478bd9Sstevel@tonic-gate #endif
1097c478bd9Sstevel@tonic-gate #endif	/* !_WCHAR_T */
1107c478bd9Sstevel@tonic-gate #endif	/* !defined(__cplusplus) ... */
1117c478bd9Sstevel@tonic-gate 
112fc2512cfSRobert Mustacchi #if !defined(_NORETURN_KYWD)
113fc2512cfSRobert Mustacchi #if __STDC_VERSION__ - 0 >= 201112L
114fc2512cfSRobert Mustacchi #define	_NORETURN_KYWD	_Noreturn
115fc2512cfSRobert Mustacchi #else
116fc2512cfSRobert Mustacchi #define	_NORETURN_KYWD
117fc2512cfSRobert Mustacchi #endif	/* __STDC_VERSION__ - 0 >= 201112L */
118fc2512cfSRobert Mustacchi #endif	/* !defined(_NORETURN_KYWD) */
119fc2512cfSRobert Mustacchi 
120fc2512cfSRobert Mustacchi extern _NORETURN_KYWD void abort(void) __NORETURN;
1217c478bd9Sstevel@tonic-gate extern int abs(int);
1227c478bd9Sstevel@tonic-gate extern int atexit(void (*)(void));
1237c478bd9Sstevel@tonic-gate extern double atof(const char *);
1247c478bd9Sstevel@tonic-gate extern int atoi(const char *);
1257c478bd9Sstevel@tonic-gate extern long int atol(const char *);
1267c478bd9Sstevel@tonic-gate extern void *bsearch(const void *, const void *, size_t, size_t,
1277c478bd9Sstevel@tonic-gate 	int (*)(const void *, const void *));
128693e4d84SAlexander Pyhalov #if __cplusplus >= 199711L && defined(__SUNPRO_CC)
1297c478bd9Sstevel@tonic-gate extern "C++" {
1307c478bd9Sstevel@tonic-gate 	void *bsearch(const void *, const void *, size_t, size_t,
1317c478bd9Sstevel@tonic-gate 		int (*)(const void *, const void *));
1327c478bd9Sstevel@tonic-gate }
133693e4d84SAlexander Pyhalov #endif /* __cplusplus >= 199711L && defined(__SUNPRO_CC) */
1347c478bd9Sstevel@tonic-gate extern void *calloc(size_t, size_t);
1357c478bd9Sstevel@tonic-gate extern div_t div(int, int);
136fc2512cfSRobert Mustacchi extern _NORETURN_KYWD void exit(int)
1377c478bd9Sstevel@tonic-gate 	__NORETURN;
1387c478bd9Sstevel@tonic-gate extern void free(void *);
1397c478bd9Sstevel@tonic-gate extern char *getenv(const char *);
1407c478bd9Sstevel@tonic-gate extern long int labs(long);
1417c478bd9Sstevel@tonic-gate extern ldiv_t ldiv(long, long);
1427c478bd9Sstevel@tonic-gate extern void *malloc(size_t);
1437c478bd9Sstevel@tonic-gate extern int mblen(const char *, size_t);
1447c478bd9Sstevel@tonic-gate extern size_t mbstowcs(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
1457c478bd9Sstevel@tonic-gate 	size_t);
1467c478bd9Sstevel@tonic-gate extern int mbtowc(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, size_t);
1477c478bd9Sstevel@tonic-gate extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
148693e4d84SAlexander Pyhalov #if __cplusplus >= 199711L && defined(__SUNPRO_CC)
1497c478bd9Sstevel@tonic-gate extern "C++" {
1507c478bd9Sstevel@tonic-gate 	void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1517c478bd9Sstevel@tonic-gate }
152693e4d84SAlexander Pyhalov #endif /* __cplusplus >= 199711L && defined(__SUNPRO_CC) */
1537c478bd9Sstevel@tonic-gate extern int rand(void);
1547c478bd9Sstevel@tonic-gate extern void *realloc(void *, size_t);
1557c478bd9Sstevel@tonic-gate extern void srand(unsigned int);
1567c478bd9Sstevel@tonic-gate extern double strtod(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD);
1577c478bd9Sstevel@tonic-gate extern long int strtol(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD, int);
1587c478bd9Sstevel@tonic-gate extern unsigned long int strtoul(const char *_RESTRICT_KYWD,
1597c478bd9Sstevel@tonic-gate 	char **_RESTRICT_KYWD, int);
1607c478bd9Sstevel@tonic-gate extern int system(const char *);
1617c478bd9Sstevel@tonic-gate extern int wctomb(char *, wchar_t);
1627c478bd9Sstevel@tonic-gate extern size_t wcstombs(char *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
1637c478bd9Sstevel@tonic-gate 	size_t);
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #if __cplusplus >= 199711L
1667c478bd9Sstevel@tonic-gate extern "C++" {
abs(long _l)1677c478bd9Sstevel@tonic-gate 	inline long   abs(long _l) { return labs(_l); }
div(long _l1,long _l2)1687c478bd9Sstevel@tonic-gate 	inline ldiv_t div(long _l1, long _l2) { return ldiv(_l1, _l2); }
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate #endif /* __cplusplus */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate #if __cplusplus >= 199711L
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate #endif /* end of namespace std */
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate #endif
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate #endif	/* _ISO_STDLIB_ISO_H */
181