xref: /titanic_41/usr/src/head/iso/stdlib_iso.h (revision b59b3655028aeb11832ad679eb5c2577c2b75235)
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 /*
23*b59b3655SGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24*b59b3655SGarrett D'Amore  *
257c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
307c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * An application should not include this header directly.  Instead it
357c478bd9Sstevel@tonic-gate  * should be included only through the inclusion of other Sun headers.
367c478bd9Sstevel@tonic-gate  *
377c478bd9Sstevel@tonic-gate  * The contents of this header is limited to identifiers specified in the
387c478bd9Sstevel@tonic-gate  * C Standard.  Any new identifiers specified in future amendments to the
397c478bd9Sstevel@tonic-gate  * C Standard must be placed in this header.  If these new identifiers
407c478bd9Sstevel@tonic-gate  * are required to also be in the C++ Standard "std" namespace, then for
417c478bd9Sstevel@tonic-gate  * anything other than macro definitions, corresponding "using" directives
427c478bd9Sstevel@tonic-gate  * must also be added to <locale.h>.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #ifndef _ISO_STDLIB_ISO_H
467c478bd9Sstevel@tonic-gate #define	_ISO_STDLIB_ISO_H
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
517c478bd9Sstevel@tonic-gate extern "C" {
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate 
5462c3776aSGarrett D'Amore unsigned char __mb_cur_max(void);
5562c3776aSGarrett D'Amore #ifndef MB_CUR_MAX
5662c3776aSGarrett D'Amore #define	MB_CUR_MAX	(__mb_cur_max())
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #if __cplusplus >= 199711L
607c478bd9Sstevel@tonic-gate namespace std {
617c478bd9Sstevel@tonic-gate #endif
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate typedef	struct {
647c478bd9Sstevel@tonic-gate 	int	quot;
657c478bd9Sstevel@tonic-gate 	int	rem;
667c478bd9Sstevel@tonic-gate } div_t;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate typedef struct {
697c478bd9Sstevel@tonic-gate 	long	quot;
707c478bd9Sstevel@tonic-gate 	long	rem;
717c478bd9Sstevel@tonic-gate } ldiv_t;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #if !defined(_SIZE_T) || __cplusplus >= 199711L
747c478bd9Sstevel@tonic-gate #define	_SIZE_T
757c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx)
767c478bd9Sstevel@tonic-gate typedef unsigned long	size_t;		/* size of something in bytes */
777c478bd9Sstevel@tonic-gate #else
787c478bd9Sstevel@tonic-gate typedef unsigned int    size_t;		/* (historical version) */
797c478bd9Sstevel@tonic-gate #endif
807c478bd9Sstevel@tonic-gate #endif	/* !_SIZE_T */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #ifndef	NULL
837c478bd9Sstevel@tonic-gate #if defined(_LP64)
847c478bd9Sstevel@tonic-gate #define	NULL	0L
857c478bd9Sstevel@tonic-gate #else
867c478bd9Sstevel@tonic-gate #define	NULL	0
877c478bd9Sstevel@tonic-gate #endif
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	EXIT_FAILURE	1
917c478bd9Sstevel@tonic-gate #define	EXIT_SUCCESS    0
927c478bd9Sstevel@tonic-gate #define	RAND_MAX	32767
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * wchar_t is a built-in type in standard C++ and as such is not
967c478bd9Sstevel@tonic-gate  * defined here when using standard C++. However, the GNU compiler
97159cf8a6Swesolows  * fixincludes utility nonetheless creates its own version of this
987c478bd9Sstevel@tonic-gate  * header for use by gcc and g++. In that version it adds a redundant
997c478bd9Sstevel@tonic-gate  * guard for __cplusplus. To avoid the creation of a gcc/g++ specific
1007c478bd9Sstevel@tonic-gate  * header we need to include the following magic comment:
1017c478bd9Sstevel@tonic-gate  *
1027c478bd9Sstevel@tonic-gate  * we must use the C++ compiler's type
1037c478bd9Sstevel@tonic-gate  *
1047c478bd9Sstevel@tonic-gate  * The above comment should not be removed or changed until GNU
1057c478bd9Sstevel@tonic-gate  * gcc/fixinc/inclhack.def is updated to bypass this header.
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate #if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__))
1087c478bd9Sstevel@tonic-gate #ifndef _WCHAR_T
1097c478bd9Sstevel@tonic-gate #define	_WCHAR_T
1107c478bd9Sstevel@tonic-gate #if defined(_LP64)
1117c478bd9Sstevel@tonic-gate typedef	int	wchar_t;
1127c478bd9Sstevel@tonic-gate #else
1137c478bd9Sstevel@tonic-gate typedef long	wchar_t;
1147c478bd9Sstevel@tonic-gate #endif
1157c478bd9Sstevel@tonic-gate #endif	/* !_WCHAR_T */
1167c478bd9Sstevel@tonic-gate #endif	/* !defined(__cplusplus) ... */
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate extern void abort(void) __NORETURN;
1197c478bd9Sstevel@tonic-gate extern int abs(int);
1207c478bd9Sstevel@tonic-gate extern int atexit(void (*)(void));
1217c478bd9Sstevel@tonic-gate extern double atof(const char *);
1227c478bd9Sstevel@tonic-gate extern int atoi(const char *);
1237c478bd9Sstevel@tonic-gate extern long int atol(const char *);
1247c478bd9Sstevel@tonic-gate extern void *bsearch(const void *, const void *, size_t, size_t,
1257c478bd9Sstevel@tonic-gate 	int (*)(const void *, const void *));
126693e4d84SAlexander Pyhalov #if __cplusplus >= 199711L && defined(__SUNPRO_CC)
1277c478bd9Sstevel@tonic-gate extern "C++" {
1287c478bd9Sstevel@tonic-gate 	void *bsearch(const void *, const void *, size_t, size_t,
1297c478bd9Sstevel@tonic-gate 		int (*)(const void *, const void *));
1307c478bd9Sstevel@tonic-gate }
131693e4d84SAlexander Pyhalov #endif /* __cplusplus >= 199711L && defined(__SUNPRO_CC) */
1327c478bd9Sstevel@tonic-gate extern void *calloc(size_t, size_t);
1337c478bd9Sstevel@tonic-gate extern div_t div(int, int);
1347c478bd9Sstevel@tonic-gate extern void exit(int)
1357c478bd9Sstevel@tonic-gate 	__NORETURN;
1367c478bd9Sstevel@tonic-gate extern void free(void *);
1377c478bd9Sstevel@tonic-gate extern char *getenv(const char *);
1387c478bd9Sstevel@tonic-gate extern long int labs(long);
1397c478bd9Sstevel@tonic-gate extern ldiv_t ldiv(long, long);
1407c478bd9Sstevel@tonic-gate extern void *malloc(size_t);
1417c478bd9Sstevel@tonic-gate extern int mblen(const char *, size_t);
1427c478bd9Sstevel@tonic-gate extern size_t mbstowcs(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
1437c478bd9Sstevel@tonic-gate 	size_t);
1447c478bd9Sstevel@tonic-gate extern int mbtowc(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, size_t);
1457c478bd9Sstevel@tonic-gate extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
146693e4d84SAlexander Pyhalov #if __cplusplus >= 199711L && defined(__SUNPRO_CC)
1477c478bd9Sstevel@tonic-gate extern "C++" {
1487c478bd9Sstevel@tonic-gate 	void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1497c478bd9Sstevel@tonic-gate }
150693e4d84SAlexander Pyhalov #endif /* __cplusplus >= 199711L && defined(__SUNPRO_CC) */
1517c478bd9Sstevel@tonic-gate extern int rand(void);
1527c478bd9Sstevel@tonic-gate extern void *realloc(void *, size_t);
1537c478bd9Sstevel@tonic-gate extern void srand(unsigned int);
1547c478bd9Sstevel@tonic-gate extern double strtod(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD);
1557c478bd9Sstevel@tonic-gate extern long int strtol(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD, int);
1567c478bd9Sstevel@tonic-gate extern unsigned long int strtoul(const char *_RESTRICT_KYWD,
1577c478bd9Sstevel@tonic-gate 	char **_RESTRICT_KYWD, int);
1587c478bd9Sstevel@tonic-gate extern int system(const char *);
1597c478bd9Sstevel@tonic-gate extern int wctomb(char *, wchar_t);
1607c478bd9Sstevel@tonic-gate extern size_t wcstombs(char *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
1617c478bd9Sstevel@tonic-gate 	size_t);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #if __cplusplus >= 199711L
1647c478bd9Sstevel@tonic-gate extern "C++" {
abs(long _l)1657c478bd9Sstevel@tonic-gate 	inline long   abs(long _l) { return labs(_l); }
div(long _l1,long _l2)1667c478bd9Sstevel@tonic-gate 	inline ldiv_t div(long _l1, long _l2) { return ldiv(_l1, _l2); }
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate #endif /* __cplusplus */
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate #if __cplusplus >= 199711L
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate #endif /* end of namespace std */
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate #endif
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate #endif	/* _ISO_STDLIB_ISO_H */
179