/* @(#) $Revision: ../hdr/stdlib.h@@/main/r10dav/libc_dav/libc_dav_cpe/1 $ */
#ifndef _STDLIB_INCLUDED
#define _STDLIB_INCLUDED

#ifndef _SYS_STDSYMS_INCLUDED
#  include <sys/stdsyms.h>
#endif /* _SYS_STDSYMS_INCLUDED */

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _INCLUDE__STDC__
#  define EXIT_FAILURE 1
#  define EXIT_SUCCESS 0
#  define MB_CUR_MAX __nl_char_size
   extern int __nl_char_size;

#  ifndef NULL
#    define NULL 0
#  endif

#  define RAND_MAX 32767
   typedef struct {
	int quot;	/* quotient */
	int rem;	/* remainder */
   } div_t;
   typedef struct {
	long int quot;	/* quotient */
	long int rem;	/* remainder */
   } ldiv_t;

#  ifndef _SIZE_T
#    define _SIZE_T
#ifndef __SIZE_TYPE__
#define __SIZE_TYPE__ long unsigned int
#endif
#ifndef _GCC_SIZE_T
#define _GCC_SIZE_T
     typedef __SIZE_TYPE__ size_t;
#endif
#  endif

#  ifndef _WCHAR_T
#    define _WCHAR_T
#ifndef __WCHAR_TYPE__
#define __WCHAR_TYPE__ int
#endif
#ifndef __cplusplus
     typedef __WCHAR_TYPE__ wchar_t;
#endif
#  endif

#  ifdef _PROTOTYPES 
#    ifndef _ATOF_DEFINED
#      define _ATOF_DEFINED
       extern double atof(const char *);
#    endif /* _ATOF_DEFINED */
     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 int atexit(void (*) (void));
     extern void exit(int);
     extern char *getenv(const char *);
     extern int system(const char *);
#    ifndef __cplusplus 
       extern int abs(int);
#    else
#      ifndef _MATH_INCLUDED
        inline int abs(int d) { return (d>0)?d:-d; }
#      endif /* _MATH_INCLUDED */
#    endif
     extern div_t div(int, int);
     extern ldiv_t ldiv(long int, long int);
     extern long int labs(long int);
     extern int mblen(const char *, size_t);
     extern int mbtowc(wchar_t *, const char *, size_t);
     extern int wctomb(char *, wchar_t);
     extern size_t mbstowcs(wchar_t *, const char *, size_t);
     extern size_t wcstombs(char *, const wchar_t *, size_t);
     extern void free(void *);
     extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
#  else /* _PROTOTYPES */
#    ifndef _ATOF_DEFINED
#      define _ATOF_DEFINED
       extern double atof();
#    endif /* _ATOF_DEFINED */
     extern int atoi();
     extern long int atol();
     extern double strtod();
     extern long int strtol();
     extern void free();
     extern unsigned long int strtoul();
     extern int rand();
     extern void srand();
     extern int atexit();
     extern void exit();
     extern char *getenv();
     extern int system();
     extern int abs();
     extern div_t div();
     extern ldiv_t ldiv();
     extern long int labs();
     extern void qsort();
     extern int mblen();
     extern int mbtowc();
     extern int wctomb();
     extern size_t mbstowcs();
     extern size_t wcstombs();
#  endif /* _PROTOTYPES */

#  ifdef _CLASSIC_ANSI_TYPES
     extern int abort();
     extern void *	bsearch();
     extern void *	calloc();
     extern void *	malloc();
     extern void *	realloc();
#  else
#    ifdef _PROTOTYPES 
       extern void abort(void);
       extern void *bsearch(const void *, const void *, size_t, size_t, int (*) (const void *, const void *));
       extern void *calloc(size_t, size_t);
       extern void *malloc(size_t);
       extern void *realloc(void *, size_t);
#    else /* _PROTOTYPES  */
       extern void abort();
       extern void *bsearch();
       extern void *calloc();
       extern void *malloc();
       extern void *realloc();
#    endif /* _PROTOTYPES */
#  endif

#endif /* _INCLUDE__STDC__ */

#ifdef _REENTRANT

struct drand48_data {
	unsigned short x[3];           /* 48 bit integer */
	unsigned short a[3];           /* mutiplier */
	unsigned short c;              /* addend */
	unsigned short lastx[3];       /* previous value of x */
	int init;           	       /* initialize ? */
};

#  ifdef _PROTOTYPES
   extern int drand48_r (struct drand48_data *, double *);
   extern int erand48_r (unsigned short [],struct drand48_data *,double*);
   extern int lrand48_r (struct drand48_data *, long *);
   extern int mrand48_r (struct drand48_data *, long *);
   extern int srand48_r (long, struct drand48_data *);
   extern int seed48_r (unsigned short [], struct drand48_data *);
   extern int lcong48_r (unsigned short [], struct drand48_data *);
   extern int nrand48_r (unsigned short [], struct drand48_data *, long*);
   extern int jrand48_r (unsigned short [], struct drand48_data *, long*);
#  else
   extern int drand48_r ();
   extern int erand48_r ();
   extern int lrand48_r ();
   extern int mrand48_r ();
   extern int srand48_r ();
   extern int seed48_r ();
   extern int lcong48_r ();
   extern int nrand48_r ();
   extern int jrand48_r ();
#  endif /* _PROTOTYPES */

#endif /* _REENTRANT */

#ifdef _XPG4
#  ifdef _PROTOTYPES
     extern void setkey(const char *);
     extern void lcong48( unsigned short [] );
#  else /* _PROTOTYPES */
     extern void setkey();
     extern void lcong48();
#  endif /* _PROTOTYPES */
#endif /* _XPG4 */


#if defined( _XPG4 ) || defined ( _INCLUDE_AES_SOURCE )
#  ifdef _PROTOTYPES
        extern double drand48(void);
        extern double erand48(unsigned short []);
        extern long jrand48(unsigned short []);
        extern long lrand48(void);
        extern long mrand48(void);
        extern long nrand48(unsigned short []);
        extern void srand48(long);
        extern unsigned short *seed48(unsigned short []);
        extern int putenv(const char *);
#  else  /* _PROTOTYPES */
        extern double drand48();
        extern double erand48();
        extern long jrand48();
        extern long lrand48();
        extern long mrand48();
        extern long nrand48();
        extern void srand48();
        extern unsigned short *seed48();
        extern int putenv();
#  endif /* _PROTOTYPES */
#endif /* _XPG4 || _INCLUDE_AES_SOURCE */


#ifdef _INCLUDE_AES_SOURCE
#    if !defined(_XPG4_EXTENDED) || defined(_INCLUDE_HPUX_SOURCE)
#         ifdef _PROTOTYPES
		extern int clearenv(void);
		extern int getopt(int, char * const [], const char *);
		extern char *getpass(const char *);
#         else   /* no _PROTOTYPES */
		extern int clearenv();
		extern int getopt();
		extern char *getpass();
#         endif	/* _PROTOTYPES */

          extern char *optarg;
          extern int optind;
          extern int opterr;
#    endif /* !_XPG4_EXTENDED || _INCLUDE_HPUX_SOURCE */
#endif	/* _INCLUDE_AES_SOURCE */


#ifdef _INCLUDE_XOPEN_SOURCE_EXTENDED 

# include <sys/wait.h>     /* For required W* macros */

/* formerly in unistd.h */
#  if defined(_XPG4_EXTENDED) || !defined(_INCLUDE_HPUX_SOURCE)
#    ifndef _MKTEMP_DEFINED
#      define _MKTEMP_DEFINED
#      ifdef _PROTOTYPES
		extern int mkstemp(char *);
		extern char *mktemp(char *);
		extern int ttyslot(void);
#      else  /* !_PROTOTYPES */
		extern int mkstemp();
		extern char *mktemp();
		extern int ttyslot();
#      endif /* _PROTOTYPES */
#    endif /* _MKTEMP_DEFINED */
#  else /* !_XPG4_EXTENDED || _INCLUDE_HPUX_SOURCE*/
        /* Look in unistd.h for the original HP-UX definition */
#  endif /* _XPG4_EXTENDED || !_INCLUDE_HPUX_SOURCE */

#  ifdef _PROTOTYPES
	extern long a64l(const char *);
	extern char *l64a(long);
	extern char *ecvt(double, int, int *, int *);
	extern char *fcvt(double, int, int *, int *);
	extern char *gcvt(double, int, char *);
	extern int getsubopt(char **, char * const *, char **);
	extern int grantpt(int);
	extern char *ptsname(int);
	extern char *realpath(const char *, char *);
	extern int unlockpt(int);
	extern void *valloc(size_t);
	extern char *initstate(unsigned int, char *, size_t);
	extern char *setstate(char *);		   	  
	extern void srandom(unsigned int);                
#    ifdef _XPG4_EXTENDED
	extern long random(void);
#    else /* ! _XPG4_EXTENDED */
        extern long random();				  
#    endif /* _XPG4_EXTENDED */
#  else /* ! _PROTOTYPES */
	extern long a64l();
	extern char *l64a();
	extern char *ecvt();
	extern char *fcvt();
	extern char *gcvt();
	extern int getsubopt();
	extern int grantpt();
	extern char *ptsname();
	extern char *realpath();
	extern int unlockpt();
	extern void *valloc();
	extern char *initstate();
	extern char *setstate();		   	  
	extern void srandom();                
	extern long random();				  
#  endif /* _PROTOTYPES */
#endif /* _INCLUDE_XOPEN_SOURCE_EXTENDED */


#ifdef _INCLUDE_HPUX_SOURCE
/* Constants defining mallopt operations */
#define M_MXFAST	1	/* set size of blocks to be fast */
#define M_NLBLKS	2	/* set number of block in a holding block */
#define M_GRAIN		3	/* set number of sizes mapped to one, for */
				/* small blocks */
#define M_KEEP		4	/* retain contents of block after a free */
				/* until another allocation */
#define M_BLOCK		5	/* enable signal blocking in all malloc */
				/* related routines */
#define M_UBLOCK	6	/* disable signal blocking set by M_BLOCK */
#define M_ENABLE_MMAP	7

#ifndef _STRUCT_MALLINFO
#  define _STRUCT_MALLINFO

  /* structure filled by mallinfo */
  struct mallinfo  {
	int arena;	/* total space in arena */
	int ordblks;	/* number of ordinary blocks */
	int smblks;	/* number of small blocks */
	int hblks;	/* number of holding blocks */
	int hblkhd;	/* space in holding block headers */
	int usmblks;	/* space in small blocks in use */
	int fsmblks;	/* space in free small blocks */
	int uordblks;	/* space in ordinary blocks in use */
	int fordblks;	/* space in free ordinary blocks */
	int keepcost;	/* cost of enabling keep option */
  };	
#endif /* _STRUCT_MALLINFO */

#  ifndef _LONG_DOUBLE
#    define _LONG_DOUBLE
     typedef struct {
       unsigned int word1, word2, word3, word4;
     } long_double;
#  endif /* _LONG_DOUBLE */

#  ifdef _PROTOTYPES
#    ifndef _PWD_INCLUDED
#      include <pwd.h>
#    endif /* _PWD_INCLUDED */

#    ifndef _ERRNO_INCLUDED
#      include <errno.h>
#    endif  /* _ERRNO_INCLUDED */

     extern char *_ldecvt(long_double, int, int *, int *);
     extern char *_ldfcvt(long_double, int, int *, int *);
     extern char *_ldgcvt(long_double, int, char *);
     extern int getpw(int, char *);
     extern void l3tol(long *, const char *, int);
     extern void ltol3(char *, const long *, int);
     extern char *ltostr(long, int);
     extern char *ultostr(unsigned long, int);
     extern char *ltoa(long);
     extern char *ultoa(unsigned long);
     extern void memorymap(int);
     extern struct mallinfo mallinfo(void);
     extern int mallopt(int, int);
     extern long_double strtold(const char *, char **);
#   ifdef _REENTRANT
     extern int _ldecvt_r(long_double, int, int *, int *, char *, int);
     extern int _ldfcvt_r(long_double, int, int *, int *, char *, int);
     extern int rand_r(long *, int *);
     extern int fcvt_r(double, int, int *, int *, char *, int);
     extern int ecvt_r(double, int, int *, int *, char *, int);
     extern int l64a_r(long, char *, int);
     extern int ltostr_r(long, int, char *, int);
     extern int ultostr_r(unsigned long, int, char *, int);
     extern int ltoa_r(long, char *, int);
     extern int ultoa_r(unsigned long, char *, int);
#   endif /* _REENTRANT */
#  else /* _PROTOTYPES */
     extern char *_ldecvt();
     extern char *_ldfcvt();
     extern char *_ldgcvt();
     extern char *ltostr();
     extern char *ultostr();
     extern char *ltoa();
     extern char *ultoa();
     extern void memorymap();
     extern struct mallinfo mallinfo();
     extern int mallopt();
     extern long_double strtold();
#   ifdef _REENTRANT
     extern int _ldecvt_r();
     extern int _ldfcvt_r();
     extern int rand_r();
     extern int fcvt_r();
     extern int ecvt_r();
     extern int l64a_r();
     extern int ltostr_r();
     extern int ultostr_r();
     extern int ltoa_r();
     extern int ultoa_r();
#   endif /* _REENTRANT */
#  endif /* _PROTOTYPES */

#endif /* _INCLUDE_HPUX_SOURCE */

#ifdef __cplusplus
}
#endif

#endif /* _STDLIB_INCLUDED */
