/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72X src/bos/usr/include/stdlib.h 1.31.11.11                         */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1985,2021              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)89  1.31.11.11  src/bos/usr/include/stdlib.h, incstd, bos72X, x2021_25A9 6/4/21 03:15:26 */ 
/*
 * COMPONENT_NAME: (INCSTD) Standard Include Files
 *
 * FUNCTIONS:
 *
 * ORIGINS: 27,71
 *
 * (C) COPYRIGHT International Business Machines Corp. 1985, 2007
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */

/*
 * (c) Copyright 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC. 
 * ALL RIGHTS RESERVED 
 */

#ifndef _H_STDLIB
#define _H_STDLIB

#ifndef _H_STANDARDS
#include <standards.h>
#endif
#include <comp_macros.h>

#if defined(__IBMCPP__) && !defined(__ibmxl__)

#   define atoff  ____atoff
#   define strtof  ____strtof

#     if __ORDERED__
#       undef _SIZE_T
#     endif

#   if defined (__MATH__) && defined (_ANSI_C_SOURCE)
      inline int _NOTHROW(abs, (int));
#    if defined (__ABS_LONG__)
      extern "C++" inline long _NOTHROW(abs, (long));
#    endif
      inline long _NOTHROW(labs, (long));
#   endif
#   if defined (__MATH__) && defined(__XLC13__) && defined(_LONG_LONG) && defined(_ALL_SOURCE)
      inline long long _NOTHROW(llabs, (long long));
#   endif
#   if defined (__MATH__) && defined (__XLC121__) && defined (_ALL_SOURCE)
      inline void imul_dbl(long ,long ,long *);
      inline void umul_dbl(unsigned long ,unsigned long ,
                    unsigned long *);
#   endif
#endif /* defined(__IBMCPP__) && !defined(__ibmxl__) */

#ifdef __cplusplus
extern "C" {
#endif

/*
 * The ANSI standard requires that certain values be in stdlib.h.
 * It also requires if _ANSI_C_SOURCE is defined then ONLY these
 * values are present. This header includes all the ANSI required entries.
 * In addition other entries for the XIX system are included.
 */

#if defined(_ALL_SOURCE) && defined(__SUID_PROFILE_CHECK) 
#define  system(arg) secure_system(arg)
#define  popen(arg1,arg2) secure_popen(arg1,arg2)
#endif

#ifdef _ANSI_C_SOURCE

/*
 * The following 3 definitions are included in <sys/types.h>.  They are
 * also included here to comply with ANSI standards.
 */

#ifndef NULL
#define	NULL	0
#endif

#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned long	size_t;
#endif

#ifndef	_WCHAR_T
#define _WCHAR_T
#ifdef __64BIT__
typedef unsigned int	wchar_t;
#else
typedef unsigned short	wchar_t;
#endif
#endif

typedef struct div_t  {	        /* struct returned from div	*/
	int quot;               /* quotient                     */
	int rem;                /* remainder                    */
} div_t;

typedef struct ldiv_t  {	/* struct returned from ldiv	*/
	long int quot;          /* quotient                     */
	long int rem;           /* remainder                    */
} ldiv_t;

#define EXIT_FAILURE   (1)		/* exit function failure	*/
#define EXIT_SUCCESS	0		/* exit function success	*/

#define RAND_MAX	32767		/* max value returned by rand	*/

extern size_t __getmbcurmax (void);
extern int __getmaxdispwidth (void);

#define MB_CUR_MAX		(__getmbcurmax())
#define __max_disp_width	(__getmaxdispwidth())

#ifdef _NO_PROTO
        extern double   _NOTHROW(strtod, ());
        extern long int _NOTHROW(strtol, ());
        extern unsigned long int _NOTHROW(strtoul, ());
#else
        extern double   _NOTHROW(strtod, (const char * __restrict__, char ** __restrict__));        extern long int _NOTHROW(strtol, (const char * __restrict__, char ** __restrict__,
int));
        extern unsigned long int _NOTHROW(strtoul, (const char * __restrict__, char ** __restrict__, int));
#endif

/*
 * C99 Functions
 */
#if defined(_ISOC99_SOURCE) || __cplusplus >= 201103L
#if __cplusplus >= 201103L
        _NORETURN(void, _Exit)(int) noexcept;
#else
#ifdef _NO_PROTO
        extern _NOTHROW(_NORETURN(void, _Exit), ());
#else
        extern _NOTHROW(_NORETURN(void, _Exit), (int));
#endif
#endif
#ifdef _NO_PROTO
        extern float		_NOTHROW(strtof, ());
#else
        extern float    	_NOTHROW(strtof, (const char * __restrict__, char ** __restrict__));
#endif

/*
 * Support for 64-bit integers, called long long int and unsigned long long int
 */
#if defined(_LONG_LONG)

typedef struct lldiv_t {
     long long int quot; /* quotient  */
     long long int rem ; /* remainder */
} lldiv_t;

#ifdef _NO_PROTO
extern long long int    _NOTHROW(atoll, ());
extern long long int _NOTHROW(llabs, ( ));
extern lldiv_t _NOTHROW(lldiv, ( ));
extern long long int _NOTHROW(strtoll, ( ));
extern unsigned long long int _NOTHROW(strtoull, ( ));

#else /* ifdef _NO_PROTO */
extern long long int    _NOTHROW(atoll, (const char *));
extern long long int _NOTHROW(llabs, ( long long int ));
extern lldiv_t _NOTHROW(lldiv, ( long long int, long long int )); /* First arg / second arg
*/
extern long long int _NOTHROW(strtoll, (
     const char * __restrict__, /* String to convert */
     char ** __restrict__,      /* Pointer to update */
     int ));                     /* Base to use */
extern unsigned long long int _NOTHROW(strtoull, (
     const char * __restrict__, /* String to convert */
     char ** __restrict__,      /* Pointer to update */
     int ));                     /* Base to use */

#endif /* ifdef _NO_PROTO */
#endif /* if defined(_LONG_LONG)  */

#ifndef _STRTOLD
#define _STRTOLD
#if defined(__LONGDOUBLE128) || defined(__LONGDOUBLE80)
extern long double _NOTHROW(strtold, (const char * __restrict__, char ** __restrict__));
#else
static long double
_NOTHROW(strtold, (const char * __restrict__ __a, char ** __restrict__ __b)) {
	return ((long double)strtod (__a, __b));
}
#endif
#endif

#endif /* _ISOC99_SOURCE */

/*
 * Functions that are methods
 */
#ifdef   _NO_PROTO
	extern int		_NOTHROW(mblen, ());
	extern size_t 	_NOTHROW(mbstowcs, ());
	extern int		_NOTHROW(mbtowc, ());
	extern size_t	_NOTHROW(wcstombs, ());
	extern int		_NOTHROW(wctomb, ());
#else /* _NO_PROTO */
	extern int	 	_NOTHROW(mblen, (const char *, size_t));
	extern size_t 	_NOTHROW(mbstowcs, (wchar_t * __restrict__, const char * __restrict__, size_t));
	extern int		_NOTHROW(mbtowc, (wchar_t * __restrict__, const char * __restrict__, size_t));
	extern size_t	_NOTHROW(wcstombs, (char * __restrict__, const wchar_t * __restrict__, size_t));
	extern int		_NOTHROW(wctomb, (char *, const wchar_t));
#endif /* _NO_PROTO */

#if __cplusplus >= 201103L
        _NORETURN(void, abort)(void) noexcept;
        int atexit(void (*)(void)) noexcept;
#else
#ifdef _NO_PROTO
        extern _NOTHROW(_NORETURN(void, abort), ());
        extern int atexit();
#else
        extern _NOTHROW(_NORETURN(void, abort), (void));
        extern int atexit(void (*)(void));
#endif
#endif

/*
 * Regular Functions no prototyping
 */
#ifdef _NO_PROTO
	extern double 	_NOTHROW(atof, ());
	extern int 	_NOTHROW(atoi, ());
	extern long int _NOTHROW(atol, ());
	extern int 	_NOTHROW(rand, ());
	extern void	_NOTHROW(srand, ());
	extern void 	*_NOTHROW(calloc, ());
	extern void	_NOTHROW(free, ());
	extern void	*_NOTHROW(malloc, ());
	extern void 	*_NOTHROW(realloc, ());
	extern _NOTHROW(_NORETURN(void, exit), ());
	extern char	*_NOTHROW(getenv, ());
	extern int 	system();
	extern void 	*bsearch();
	extern void 	qsort();
/*ISO C standard from 2011 onward*/
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || __cplusplus >= 201103L || defined(_ALL_SOURCE)
	extern int      _NOTHROW(at_quick_exit, ());
#ifndef __quickexit
#define __quickexit
	extern _NOTHROW(_NORETURN(void, quick_exit), ());
#endif
	extern void     *_NOTHROW(aligned_alloc, ());
#endif

/*
 * Undefine conflicting definition in  macros.h
 */
#ifdef _ALL_SOURCE
#ifdef abs
#undef abs
#endif
#endif /* _ALL_SOURCE */
	extern int 	_NOTHROW(abs, ());
	extern struct div_t	_NOTHROW(div, ());
	extern long int	_NOTHROW(labs, ());
	extern struct ldiv_t 	_NOTHROW(ldiv, ());

#ifndef _STRTOLD
#define _STRTOLD
#if defined(__LONGDOUBLE128) || defined(__LONGDOUBLE80)
	long double _NOTHROW(strtold, ());
#endif /* #ifdef __LONGDOUBLE128 || __LONGDOUBLE80 */
#endif

/*
 * Regular Functions with prototyping
 */
#else  /* _NO_PROTO */
/*
 * Any changes to the atof() prototype must also be made to the atof()
 * prototype in math.h.
 */
	extern double 	_NOTHROW(atof, (const char *));
	extern int 	_NOTHROW(atoi, (const char *));
	extern long int _NOTHROW(atol, (const char *));
	extern int 	_NOTHROW(rand, (void));
	extern void	_NOTHROW(srand, (unsigned int));
	extern void 	*_NOTHROW(calloc, (size_t, size_t));
	extern void	_NOTHROW(free, (void *));
	extern void	*_NOTHROW(malloc, (size_t));
	extern void 	*_NOTHROW(realloc, (void *, size_t));
	extern _NOTHROW(_NORETURN(void, exit), (int));
	extern char	*_NOTHROW(getenv, (const char *));
	extern int 	system(const char *);
	extern void 	*bsearch(const void *, const void *, size_t, size_t, int(*)(const void *,const void *));
	extern void 	qsort(void *, size_t, size_t, int(*)(const void *,const void *));
/*ISO C standard from 2011 onward*/
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || __cplusplus >= 201103L || defined(_ALL_SOURCE)
	extern int      _NOTHROW(at_quick_exit, (void (*f)(void)));
#ifndef __quickexit
#define __quickexit
	extern _NOTHROW(_NORETURN(void, quick_exit), (int));
#endif
	extern void     *_NOTHROW(aligned_alloc, (size_t, size_t));
#endif

/**********
 * Undefine conflicting definition in  macros.h
 */
#ifdef _ALL_SOURCE
#ifdef abs
#undef abs
#endif
#endif /* _ALL_SOURCE */
	
	extern int 	_NOTHROW(abs, (int));
	extern struct div_t	_NOTHROW(div, (int, int));
	extern long int	_NOTHROW(labs, (long int));
	extern struct ldiv_t 	_NOTHROW(ldiv, (long int, long int));

#ifndef _STRTOLD
#define _STRTOLD
#if defined(__LONGDOUBLE128) || defined(__LONGDOUBLE80)
/*
 * strtold() is available only for the non-default 128-bit
 * long double mode.  For converting to default (64-bit)
 * long double type, use strtod().
 */
	long double _NOTHROW(strtold, (const char * __restrict__, char ** __restrict__));
#endif /* #ifdef __LONGDOUBLE128 || __LONGDOUBLE80 */
#endif

#  endif /* _NO_PROTO */
#endif /* _ANSI_C_SOURCE */


#ifdef _POSIX_SOURCE

#if _POSIX_C_SOURCE >= 200112L
extern int _NOTHROW(posix_memalign, (void **,size_t,size_t));
#endif /* _POSIX_C_SOURCE >= 200112L */

#endif



/*
 * functions required by XOPEN
 */
#ifdef _XOPEN_SOURCE

#ifndef _H_WAIT
#include <sys/wait.h>   /* WNOHANG, WUNTRACED, WEXITSTATUS(), etc. */
#endif

#if defined(_THREAD_SAFE) && defined(_ALL_SOURCE)
/*
 * The following structure is used by the different thread_safe
 * *rand48_r() functions and must be passed in as an argument.
 */
 typedef struct drand48_data {
        unsigned x[3];                  /* 48 bit integer value */
        unsigned a[3];                  /* mutiplier value */
        unsigned c;                     /* addend value */
        unsigned short lastx[3];        /* previous value of Xi */
        int init;                       /* initialize ? */
} DRAND48D;
#endif	/* _THREAD_SAFE  && _ALL_SOURCE */

#ifdef _NO_PROTO
	extern double 		_NOTHROW(drand48, ());
	extern double 		_NOTHROW(erand48, ());
	extern long 		_NOTHROW(jrand48, ());
	extern void 		_NOTHROW(lcong48, ());
	extern long 		_NOTHROW(lrand48, ());
	extern long 		_NOTHROW(mrand48, ());
	extern long 		_NOTHROW(nrand48, ());
	extern unsigned short 	*_NOTHROW(seed48, ());
	extern void 		_NOTHROW(setkey, ());
	extern void 		_NOTHROW(srand48, ());
	extern int 		_NOTHROW(putenv, ());

#if (_XOPEN_SOURCE>=500) || defined(_THREAD_SAFE)
/*
 * rand_r() was only visible under _XOPEN_SOURCE/_THREAD_SAFE
 * but now needs to be visible under _XOPEN_SOURCE>=500 or _THREAD_SAFE.
 */
	extern  int     _NOTHROW(rand_r, ());
#endif /* _XOPEN_SOURCE>=500 or _THREAD_SAFE */

#if defined(_THREAD_SAFE) && defined(_ALL_SOURCE)
	extern int	getopt_r();
	extern  int     _NOTHROW(drand48_r, ());
	extern  int     _NOTHROW(erand48_r, ());
	extern  int     _NOTHROW(lrand48_r, ());
	extern  int     _NOTHROW(mrand48_r, ());
	extern  int     _NOTHROW(srand48_r, ());
	extern  int     _NOTHROW(seed48_r, ());
	extern  int     _NOTHROW(lcong48_r, ());
	extern  int     _NOTHROW(nrand48_r, ());
	extern  int     _NOTHROW(jrand48_r, ());
        extern  int	_NOTHROW(ecvt_r, ());
        extern  int	_NOTHROW(fcvt_r, ());
#endif	/* _THREAD_SAFE */
#if _XOPEN_SOURCE_EXTENDED==1
	extern long _NOTHROW(a64l, ());
#if (((_XOPEN_SOURCE < 700) && (_POSIX_C_SOURCE < 200809L)) || defined(_ALL_SOURCE))
	extern char *_NOTHROW(ecvt, ());
	extern char *_NOTHROW(fcvt, ());
	extern char *_NOTHROW(gcvt, ());
	extern char *_NOTHROW(mktemp, ());
#endif
	extern int  _NOTHROW(getsubopt, ());
	extern int  _NOTHROW(grantpt, ());
	extern char *_NOTHROW(initstate, ());
	extern char *_NOTHROW(l64a, ());
	extern int  mkstemp();
#if (_XOPEN_SOURCE >= 700) /* SUSv4 routine */	
	extern char *_NOTHROW(mkdtemp, ());
#endif 	
#ifdef _LARGE_FILES
#define mkstemp mkstemp64
#endif
#ifdef _LARGE_FILE_API
	extern int  mkstemp64(char *);
#endif
	extern char *_NOTHROW(ptsname, ());
	extern long _NOTHROW(random, ());
	extern char *_NOTHROW(realpath, ());
	extern char *_NOTHROW(setstate, ());
	extern void _NOTHROW(srandom, ());
	extern int  _NOTHROW(unlockpt, ());
#if (_XOPEN_SOURCE < 600)
	/* These functions were removed in SUSv3 */
#define _UNIX03_REMOVED
	extern int  _NOTHROW(ttyslot, ());
	extern void *_NOTHROW(valloc, ());
#endif
#endif /* _XOPEN_SOURCE_EXTENDED */
#else
	extern double 		_NOTHROW(drand48, (void));
	extern double 		_NOTHROW(erand48, (unsigned short[]));
	extern long 		_NOTHROW(jrand48, (unsigned short[]));
	extern void 		_NOTHROW(lcong48, (unsigned short int *));
	extern long 		_NOTHROW(lrand48, (void));
	extern long 		_NOTHROW(mrand48, (void));
	extern long 		_NOTHROW(nrand48, (unsigned short[]));
	extern unsigned short 	*_NOTHROW(seed48, (unsigned short[]));
	extern void 		_NOTHROW(setkey, (const char *));
	extern void 		_NOTHROW(srand48, (long));
#if (_XOPEN_SOURCE >= 500)
	extern int 		_NOTHROW(putenv, (char *));
#else  /* _XOPEN_SOURCE >= 500 */
	extern int 		_NOTHROW(putenv, (const char *));
#endif /* _XOPEN_SOURCE >= 500 */

#if (_XOPEN_SOURCE>=500) || defined(_THREAD_SAFE)
/*
 * AIX 3.2 used the POSIX 1003.4a Draft 4 interfaces while post 3.2
 * release use the new Draft 7 interfaces.  There is a DCE compatibility
 * library that contains the interfaces that changed, and these are the
 * prototypes for those routines for backward compatibility.
 * Also, rand_r() was only visible under _XOPEN_SOURCE/_THREAD_SAFE
 * but now needs to be visible under _XOPEN_SOURCE>=500 or _THREAD_SAFE.
 */

#if _AIX32_THREADS
	extern	int	_NOTHROW(rand_r, (unsigned int *, int *));
#else	/* POSIX 1003.4a Draft 7 prototype */
	extern	int	_NOTHROW(rand_r, (unsigned int *));
#endif /* _AIX32_THREADS */
#endif /* _XOPEN_SOURCE>=500 or _THREAD_SAFE */

#if defined(_THREAD_SAFE) && defined(_ALL_SOURCE)
	extern int		getopt_r( int, char* const*, const char*, int *,
					  char **, int *, int , int *,
					  int *);
	extern  int     _NOTHROW(drand48_r, (DRAND48D *, double *));
	extern  int     _NOTHROW(erand48_r, (unsigned short [], DRAND48D *,
                          	  double *));
	extern  int     _NOTHROW(lrand48_r, (DRAND48D *, long *));
	extern  int     _NOTHROW(mrand48_r, (DRAND48D *, long *));
	extern  int     _NOTHROW(srand48_r, (long, DRAND48D *));
	extern  int     _NOTHROW(seed48_r, (unsigned short [], DRAND48D *));
	extern  int     _NOTHROW(lcong48_r, (unsigned short [], DRAND48D *));
	extern  int     _NOTHROW(nrand48_r, (unsigned short [], DRAND48D *,
				  long *));
	extern  int     _NOTHROW(jrand48_r, (unsigned short [], DRAND48D *,
				  long *));
        extern  int	_NOTHROW(ecvt_r, (double, int, int *, int *, char *, int));
        extern  int	_NOTHROW(fcvt_r, (double, int, int *, int *, char *, int));
#endif	/* _THREAD_SAFE */
#if _XOPEN_SOURCE_EXTENDED==1
	extern long _NOTHROW(a64l, (const char *));
#if (((_XOPEN_SOURCE < 700) && (_POSIX_C_SOURCE < 200809L)) || defined(_ALL_SOURCE))
	extern char *_NOTHROW(ecvt, (double, int, int *, int *));
	extern char *_NOTHROW(fcvt, (double, int, int *, int *));
	extern char *_NOTHROW(gcvt, (double, int, char *));
	extern char *_NOTHROW(mktemp, (char *));
#endif
	extern int  _NOTHROW(getsubopt, (char **, char *const *, char **));
	extern int  _NOTHROW(grantpt, (int));
	extern char *_NOTHROW(initstate, (unsigned, char *, size_t));
	extern char *_NOTHROW(l64a, (long));
	extern int  mkstemp(char *);
#if (_XOPEN_SOURCE >= 700) /* SUSv4 routine */	
	extern char *_NOTHROW(mkdtemp, (char *));
#endif
#ifdef _LARGE_FILES
#define mkstemp mkstemp64
#endif
#ifdef _LARGE_FILE_API
	extern int  mkstemp64(char *);
#endif
	extern char *_NOTHROW(ptsname, (int));
	extern long _NOTHROW(random, (void));
	extern char *_NOTHROW(realpath, (const char *, char *));
#if (_XOPEN_SOURCE < 700)
	extern char *_NOTHROW(setstate, (const char *));
#else
	extern char *_NOTHROW(setstate, (char *));
#endif
	extern void _NOTHROW(srandom, (unsigned));
	extern int  _NOTHROW(unlockpt, (int));
#if (_XOPEN_SOURCE < 600)
	/* These functions were removed in SUSv3 */
#define _UNIX03_REMOVED
	extern int  _NOTHROW(ttyslot, (void));
	extern void *_NOTHROW(valloc, (size_t));
#endif
#endif /* _XOPEN_SOURCE_EXTENDED */
#endif /* _NO_PROTO */

#if (_XOPEN_SOURCE >= 600)
#ifdef _NO_PROTO
	extern int	posix_openpt();
	extern int	_NOTHROW(setenv, ());
	extern int	_NOTHROW(unsetenv, ());
#else
	extern int  	posix_openpt	(int);
	extern int      _NOTHROW(setenv, (const char *, const char *, int));
	extern int      _NOTHROW(unsetenv, (const char *));
#endif
#endif /* _XOPEN_SOURCE >= 600 */

#endif /* _XOPEN_SOURCE */


/*
 * The following macro definitions cause the XLC compiler to inline
 * these functions whenever possible.
 */

/*
 * Undefine conflicting definition in  macros.h
 */

#ifdef _ALL_SOURCE
#ifdef abs
#undef abs
#endif
#endif /* _ALL_SOURCE */

#if (defined (__MATH__) &&  defined (_ANSI_C_SOURCE) )
#define abs(__j)          __abs(__j)
#define labs(__j)         __labs(__j)
#endif /* __MATH__  and _ANSI_C_SOURCE */

/*
 * Definition of functions and structures used by the thread-safe
 * random_r() functions.
 */
#if defined(_ALL_SOURCE) && defined(_THREAD_SAFE)
typedef struct random_data {
        int     *fptr;
        int     *rptr;
        int     *state;
        int     rand_type;
        int     rand_deg;
        int     rand_sep;
        int     *end_ptr;
} RANDOMD;

/* functions */

#ifdef _NO_PROTO
extern  int     _NOTHROW(srandom_r, ());
extern  int     _NOTHROW(initstate_r, ());
extern  int     _NOTHROW(setstate_r, ());
extern  long    _NOTHROW(random_r, ());
extern	int	l64a_r();
#else
extern  int     _NOTHROW(srandom_r, (unsigned, RANDOMD *));
extern  int     _NOTHROW(initstate_r, (unsigned, char *, size_t, char **,RANDOMD *));
extern  int     _NOTHROW(setstate_r, (char *, char **,  RANDOMD *));
extern  int     _NOTHROW(random_r, (long *, RANDOMD *));
extern	int	l64a_r(long, char*, int);
#endif /* _NO_PROTO */

#endif /* _ALL_SOURCE && _THREAD_SAFE */

/*
 * The following function prototypes are not defined for programs
 * that are adhering to strict ANSI conformance, but are included
 * for floating point support.
 */

#ifdef _ALL_SOURCE

#ifndef _H_TYPES
#include <sys/types.h>
#endif

#ifndef __H_LOCALEDEF
#include <sys/localedef.h>
#endif

/*
 * Redefine MB_CUR_MAX and __max_disp_width to not call the functions
 */
#undef MB_CUR_MAX
#undef __max_disp_width

#ifdef _THREAD_SAFE
#define MB_CUR_MAX		(__OBJ_DATA(*__LC_CHARMAP_PTR)->cm_mb_cur_max)
#define __max_disp_width	(__OBJ_DATA(*__LC_CHARMAP_PTR)->cm_max_disp_width)
#define __XMB_CUR_MAX(__cmap)	(__OBJ_DATA(*__cmap)->cm_mb_cur_max)
#define __x__max_disp_width(__cmap)	(__OBJ_DATA(*__cmap)->cm_max_disp_width)
#define __MB_CUR_MAX_L(__cmap)   (__OBJ_DATA(*__cmap)->cm_mb_cur_max)
#define __max_disp_width_l(__cmap) (__OBJ_DATA(*__cmap)->cm_max_disp_width)
#else
#define MB_CUR_MAX              (__OBJ_DATA(__lc_charmap)->cm_mb_cur_max)
#define __max_disp_width        (__OBJ_DATA(__lc_charmap)->cm_max_disp_width)
#endif

extern char *optarg;
extern int optind;
extern int opterr;

/* The following functions are required by the COSE (UU) API. */

#define ATEXIT_MAX	2048	/* Max Number of functions that can be
				   registered in the atexit() functions.
				   ATEXIT_MAX IS ALSO DEFINED IN sys/limits.h */

#ifdef _NO_PROTO
	extern float    atoff();
	extern void     imul_dbl();
	extern void     umul_dbl();
	extern int	_NOTHROW(on_exit, ());
	extern int      unatexit();
#else /* use prototypes */
	extern float    atoff(char *);
	extern void     imul_dbl(long, long, long *);
	extern void     umul_dbl(unsigned long, unsigned long, unsigned long *);
	extern int	_NOTHROW(on_exit, (void (*)(int, void *), void *));
	extern int      unatexit(void (*)(void));
#endif /* ifdef _NO_PROTO */

#if (defined (__MATH__) &&  defined (__XLC121__) && defined (_ALL_SOURCE) )
#define imul_dbl(__a, __b, __c)   __imul_dbl(__a, __b, __c)
#define umul_dbl(__a, __b, __c)   __umul_dbl(__a, __b, __c)
#endif

#ifdef _NO_PROTO
/*
 * functions that are methods
 */
	extern double			_NOTHROW(wcstod, ());
	extern long int			_NOTHROW(wcstol, ());
	extern unsigned long int 	_NOTHROW(wcstoul, ());

	extern int			_NOTHROW(rpmatch, ());
	extern int			_NOTHROW(clearenv, ());
	extern int			_NOTHROW(getopt, ());
	extern char			*getpass();
#ifndef _UNIX03_REMOVED
	extern int  			_NOTHROW(ttyslot, ());
	extern void			*_NOTHROW(valloc, ());
#endif
#else
	extern double	 		_NOTHROW(wcstod, (const wchar_t *, wchar_t **));
	extern long int	 		_NOTHROW(wcstol, (const wchar_t *, wchar_t **, int));
	extern unsigned long int 	_NOTHROW(wcstoul, (const wchar_t *, wchar_t **, int));

	extern int			_NOTHROW(rpmatch, (const char *));
	extern int			_NOTHROW(clearenv, (void));
	extern int			_NOTHROW(getopt, (int, char* const*, const char*));
	extern char			*getpass(const char *);
#ifndef _UNIX03_REMOVED
        extern int  			_NOTHROW(ttyslot, (void));
        extern void 			*_NOTHROW(valloc, (size_t));
#endif
#endif /* _NO_PROTO */

#endif /* _ALL_SOURCE */

/*
 * __XLC121__ is automatically defined by the XLC 1.2.1 compiler so that
 * the compiler can inline the following functions when possible.
 */

#if (defined (__MATH__) &&  defined (__XLC121__) && defined (_ANSI_C_SOURCE) )
#define div(__numer,__denom)        __div(__numer,__denom)
#define ldiv(__numer,__denom)       __ldiv(__numer,__denom)
#endif

#if defined(_ALL_SOURCE) && defined(_LINUX_SOURCE_COMPAT)
#ifdef	_NO_PROTO
extern void *__linux_malloc();
extern void *__linux_realloc();
extern void *__linux_calloc();
extern void *__linux_valloc();
#else
extern void *__linux_malloc(size_t);
extern void *__linux_realloc(void *, size_t);
extern void *__linux_calloc(size_t, size_t);
extern void *__linux_valloc(size_t);
#endif
#define malloc __linux_malloc
#define calloc __linux_calloc
#define realloc __linux_realloc
#define valloc __linux_valloc
#endif	/* _LINUX_SOURCE_COMPAT */

#ifdef _ALL_SOURCE
#ifdef	_NO_PROTO
extern void *vec_malloc();
extern void *vec_calloc();
#else
extern void *vec_malloc(size_t);
extern void *vec_calloc(size_t, size_t);
#endif
#define vec_realloc realloc
#define vec_free free
#if defined(__VEC__) || defined(__AIXVEC)
#if (defined(__IBMC__) || defined(__IBMCPP__)) && !defined(__clang__)
#pragma map(malloc,"vec_malloc")
#pragma map(calloc,"vec_calloc")
#else  /* (__IBMC__ || __IBMCPP__) && !__clang__ */
#define malloc vec_malloc
#define calloc vec_calloc
#endif  /* (__IBMC__ || __IBMCPP__) && !__clang__ */
#endif /* __VEC__ || __AIXVEC */
#endif	/* _ALL_SOURCE */

#ifdef __STDC_WANT_DEC_FP__     /* DFP scope requested */

#ifdef _NO_PROTO
	extern _Decimal32 strtod32();
	extern _Decimal64 strtod64();
	extern _Decimal128 strtod128();
#else
	extern _Decimal32 strtod32(const char *, char **);
	extern _Decimal64 strtod64(const char *, char **);
	extern _Decimal128 strtod128(const char *, char **);
#endif /* _NO_PROTO */

#endif /* __STDC_WANT_DEC_FP__ */

#ifdef __cplusplus
}
#endif

#if !defined(__xlC__) || defined(__ibmxl__) || defined(__cplusplus)
#if defined(__IBMCPP__) && !defined(__ibmxl__)
   extern "builtin" char *__alloca (size_t);
#  define alloca __alloca
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
   #undef  alloca
   #define alloca(size)   __builtin_alloca (size)
#endif
#endif /* !defined(__xlC__) || defined(__ibmxl__) || defined(__cplusplus) */

#if defined(__IBMCPP__) || (defined(__ibmxl__) && defined(__cplusplus))
#   undef atoff
#   undef strtof

    extern "C" {
      float atoff(char *);
      float _NOTHROW(strtof, (const char *, char**));
    }

#   if ((defined(__MATH__) && defined (__XLC121__)) || defined(__ibmxl__)) && defined(_ANSI_C_SOURCE)
#     undef div
#     undef ldiv
#    ifndef __ibmxl__
      extern "builtin" div_t   __div(int, int);
      extern "builtin" ldiv_t   __ldiv(long, long);
#    else
      extern div_t   __div(int, int) __attribute__((__IBMbuiltin__));
      extern ldiv_t   __ldiv(long, long) __attribute__((__IBMbuiltin__));
#    endif

        _FAST_INLINE div_t _NOTHROW(div, (int __numer, int __denom)) { return __div(__numer, __denom); }
        extern "C++" inline ldiv_t _NOTHROW(div, (long __numer, long __denom)) { return __ldiv(__numer, __denom); }
        _FAST_INLINE ldiv_t _NOTHROW(ldiv, (long __numer, long __denom)) { return __ldiv(__numer, __denom); }
#   endif

#   if (defined (__MATH__) || defined(__ibmxl__)) && defined (_ANSI_C_SOURCE)
#     undef abs
#     undef labs
#    ifndef __ibmxl__
      extern "builtin" int   __abs(int);
      extern "builtin" long   __labs(long);
#    endif
      _FAST_INLINE int _NOTHROW(abs, (int __n)) { return __abs(__n);}
#    if defined (__ABS_LONG__)
      extern "C++" inline long _NOTHROW(abs, (long __n)) { return __labs(__n);}
#    endif
      _FAST_INLINE long _NOTHROW(labs, (long __n)) { return __labs(__n);}
#   endif
#   if defined(_LONG_LONG) && (defined(__ibmxl__) || (defined (__MATH__) && defined(__XLC13__) && defined(_ALL_SOURCE)))
#      undef llabs
#    ifndef __ibmxl__
      extern "builtin" long long  __llabs(long long);
#    endif
      _FAST_INLINE long long _NOTHROW(llabs, (long long __n)) { return __llabs(__n);}
#   endif

#   if ((defined (__MATH__) && defined (__XLC121__)) || defined(__ibmxl__)) && defined (_ALL_SOURCE)
#     undef imul_dbl
#     undef umul_dbl
#     ifndef __ibmxl__
      extern "builtin" void __imul_dbl(long,long,long *);
      extern "builtin" void __umul_dbl(unsigned long,unsigned long,unsigned long *);
#     endif
      _FAST_INLINE void imul_dbl(long __a,long __b,long *__c)
        { __imul_dbl(__a,__b,__c); }
      _FAST_INLINE void umul_dbl(unsigned long __a,unsigned long __b,
                    unsigned long *__c)
        { __umul_dbl(__a,__b,__c); }
#   else
      extern "C" void imul_div (long, long, long*);
      extern "C" void umul_div (unsigned long, unsigned long, unsigned long*);
#   endif
#endif /* def defined(__IBMCPP__) || (defined(__ibmxl__) && defined(__cplusplus)) */

#endif /* _H_STDLIB */