/**************************************************************************
*   Copyright 2000 Compaq Computer Corporation
*
*   COMPAQ Registered in U.S. Patent and Trademark Office.
*
*   Confidential computer software. Valid license from Compaq or authorized
*   sublicensor required for possession, use or copying. Consistent with
*   FAR 12.211 and 12.212, Commercial Computer Software, Computer Software
*   Documentation, and Technical Data for Commercial Items are licensed to
*   the U.S. Government under vendor's standard commercial license.
**************************************************************************/

#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
#if defined(__linux__)
#define _STDLIB_H
#else
#define _STDLIB_H_
#endif  /* __linux__  */

#if defined(__linux__)
#define NULL    0
#else
#define NULL    0L
#endif   /* __linux__ */

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

#if  defined(_BSD) || defined(__linux__) 
#define RAND_MAX	2147483647	/* max value returned by rand	*/
#else
#define RAND_MAX	32767		/* max value returned by rand	*/
#endif

namespace std {
extern "C" {

typedef unsigned long   size_t;

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

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


/* Some header files define abs. If defined, undef to prevent syntax error */
#ifdef abs
#undef abs
#endif

extern void	abort (void);
extern int	atexit (void (*)(void));
extern void	exit (int);
extern char	*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 *));
extern int 	abs (int );
extern long int	labs (long int );
extern struct div_t	div (int , int );
extern struct ldiv_t 	ldiv (long int , long int );

/**********
** Functions that are methods
**********/
extern int	mblen (const char *, size_t);
extern size_t	mbstowcs (wchar_t *, const char *, size_t);
extern int	mbtowc (wchar_t *, const char *, size_t);
extern size_t	wcstombs (char *, const wchar_t *, size_t);
extern int	wctomb (char *, wchar_t);

extern double 	atof (const char *);
extern int 	atoi (const char *);
extern long int atol (const char *);
extern double 	strtod (const char *, char **);
extern long int strtol (const char *, char **, int );
extern unsigned long int strtoul (const char *, char **, int );
extern int 	rand (void);
extern void	srand (unsigned int );
extern void 	*calloc (size_t , size_t );
extern void	free (void *);
extern void	*malloc (size_t );
extern void 	*realloc (void *, size_t );

}  /* extern "C"  */

/*  Get overloaded function signatures */

#include <stdlib_ovrld_impl>

}  /* namespace std */


#if defined(__linux__)
#define	MB_CUR_MAX	(__ctype_get_mb_cur_max ())

extern "C" {
extern  std::size_t  __ctype_get_mb_cur_max (void);
}
#else
#define MB_CUR_MAX  __getmbcurmax()	/* max bytes in multibyte char	*/

extern "C" {
extern int __getmbcurmax (void);
}
#endif  /*  __linux__ */


#endif /* _STDLIB_H_ */
