#ifndef _STDLIB_H_
#define _STDLIB_H_
/**
 *
 *	Header defined by ANSI to hold items that had no other
 *	sensible home
 *
 *	AMENDMENT HISTORY
 *	~~~~~~~~~~~~~~~~~
 *	01 Sep 94	DJW   - Name hiding implemented for routines that are
 *						used internally within C68 libraries.
 *
 *	02 Jan 95	DJW   - Added missing 'const' qualifer to some prototypes.
 *
 *  10 Mar 96   DJW   - Added getpass() routine.
**/

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

#ifndef NULL
#define NULL  ((void *)0)
#endif

/*
 *	ANSI defined constants
 */
#define EXIT_SUCCESS 0				/* default program success exit code */
#define EXIT_FAILURE -1 			/* default program error exit code */
#define MB_CUR_MAX sizeof(char) 	/* Max size of multi-byte characters */

#ifndef RAND_MAX
/*	Note that this value will need changing if sizeof(int) is not 32 bit */
#define RAND_MAX	 2147483647  /* max value for int */
#endif

/*
 *	These are not strictly ANSI, but this is where SVR4 puts them!
 */
extern	char *	optarg;
extern	int 	optind, opterr, optopt;
/*
 *	Types required by this file
 */
typedef struct { int quot; int rem; } div_t;
typedef struct {long quot; long rem; } ldiv_t;

#ifdef __STDC__
#define _P_(params) params
#else
#define _P_(params)
#endif

/**
 *
 * Level 3 memory allocation services
 *		(ANSI compatible)
 *
**/
/* Name Hiding definitions */
#define calloc	_Calloc
#define realloc _Realloc
/* Prototypes */
void * malloc	_P_((size_t));
void * calloc	_P_((size_t, size_t));
void * realloc	_P_((void *, size_t));
void   free 	_P_((void *));
char * alloca	_P_((size_t));		 /* Not ANSI */
/**
 *
 * Level 2 memory allocation services
 *
**/
/* int	allmem	_P_((void)); */
/* int	bldmem	_P_((int)); */
char * getmem	_P_((int));
char * getml	_P_((long));
int    rlsmem	_P_((char *, int));
int    rlsml	_P_((char *, long));
/* long sizmem	_P_((void)); */
/* long chkml	_P_((void)); */
/* void rstmem	_P_((void)); */
/**
 *
 * Sort functions
 *
**/
/*	Name hiding definitions */
#define qsort	_Qsort

/*	Prototypes */
/*	ANSI */
void   *bsearch _P_((const void *, const void *, size_t, size_t, int (*)(const void *, const void *)));
void	qsort	_P_((void *, size_t, size_t, int (*)(const void *, const void *)));
/*	LATTICE */
void	dqsort	_P_((double *, int));
void	fqsort	_P_((float *, int));
void	lqsort	_P_((long *, int));
void	sqsort	_P_((short *, int));
void	tqsort	_P_((char **, int));
/**
 *
 *		Random Number routines
 *
**/
int    rand 	_P_((void));
void   srand	_P_((unsigned));
double drand48	_P_((void)); 
double erand48	_P_((short *));
long   jrand48	_P_((short *));
void   lcong48	_P_((short *));
long   lrand48	_P_((void));
long   mrand48	_P_((void));
long   nrand48	_P_((short *));
short *seed48	_P_((short *));
void   srand48	_P_((long));
/**
 *
 * Miscellaneous functions
 *
**/
/*	Name hiding definitions */
#define abort	_Abort
#define putenv	_Putenv
#define realloc _Realloc
#define strtod  _Strtod
#define strtoul _Strtoul
/*	prototypes */
int    abs		_P_((int));
void   abort	_P_((void));
char * argopt	_P_((int, char**, char *, int *, char *));
int    atexit	_P_((void (*)(void)));
double atof 	_P_((const char *));
int    atoi 	_P_((const char *));
long   atol 	_P_((const char *));
div_t  div		_P_((int, int));
void   exit 	_P_((int));
char * getenv	_P_((const char *));
gid_t  getegid	_P_((void));
uid_t  geteuid	_P_((void));
int    getfnl	_P_((char *, char *, unsigned, int));
gid_t  getgid	_P_((void));
int    getopt	_P_((int, char **, char *));
int    isatty	_P_((int));
long   labs 	_P_((long));
ldiv_t ldiv 	_P_((long, long));
char * mktemp	_P_((char *));
int    onexit	_P_((int(*)(void)));
int    putenv	_P_((char *));
double strtod	_P_((const char *, char **));
long   strtol	_P_((const char *, char **, int));
unsigned long strtoul _P_((const char *, char**, int)); 
int    system	_P_((const char *));
char * ttyname	_P_((int));
long   utpack	_P_((char *));
void   utunpk	_P_((long, char *));
/*	Macro overrides */
#define atof(s) strtod(s, 0)
#define atoi(s) (int)strtoul(s, 0, 10)
#define atol(s) (long)strtoul(s, 0, 10)
/*
 *	ANSI Wide & Multi-Byte character routines
 */
int 	mblen		_P_((const char * s, size_t n));
int 	mbtowc		_P_((wchar_t * pwc, const char *s, size_t n));
size_t	mbstowcs	_P_((wchar_t * pwc, const char *s, size_t n));
int 	wctomb		_P_((char * s, wchar_t pwc));
size_t	wcstombs	_P_((char * s, const wchar_t * pwc, size_t n));

/*
 *	Console specific routiines
 */
char *  getpass     _P_((char * prompt));
/*
 *	LATTICE
 */
#define iabs(value) abs(value)
int 	envunpk _P_((char *));
char *	itoa	_P_((int, char *));

#ifdef __LIBRARY__
/*************************************************************************
 *
 *							C A U T I O N
 *							~~~~~~~~~~~~~
 *
 *	The remainder of this header contains definitions that are internal
 *	to the way that the C68 libraries have been implemented on QDOS/SMS.
 *	These definitions should not be used by any user program as they are
 *	subject to change without notice.
 *
 *************************************************************************/

int 	_mul10add	_P_((double *valuep, int digit));
double	_adjust 	_P_((double *valuep, int decexp, int negflag));

#endif /* __LIBRARY__ */
		 
#undef _P_

#endif /* _STDLIB_H */
