/*
 * stdlib.h
 *
 * Definitions for common types, variables, and functions.
 */


#ifndef _STDLIB_H_
#define _STDLIB_H_

#include <_ansi.h>

#define __need_size_t
#define __need_wchar_t
#include <stddef.h>

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

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

#ifndef NULL
#define NULL 0
#endif

#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0

#define RAND_MAX 0x7fffffff

#define MB_CUR_MAX 1

#undef __NORETURN /* из-за того, что в нескольких файлах */
#ifdef __GNUC__
#define __NORETURN __attribute__((noreturn))
#else
#define __NORETURN
#endif


#ifdef __cplusplus
extern "C" {
#endif


_VOID   _EXFUN(abort,(_VOID)) __NORETURN;
int _EXFUN(abs,(int));
int _EXFUN(atexit,(_VOID (*_func)(_VOID)));
int _EXFUN(on_exit,(_VOID (*func)(int __status, _VOID *__arg), _VOID *__arg));
double  _EXFUN(atof,(_CONST char *_nptr));
float   _EXFUN(atoff,(_CONST char *_nptr));
int _EXFUN(atoi,(_CONST char *_nptr));
long    _EXFUN(atol,(_CONST char *_nptr));
long long _EXFUN(atoll,(_CONST char *_nptr));
_PTR    _EXFUN(bsearch,(_CONST _PTR _key,
               _CONST _PTR _base,
               size_t _nmemb,
               size_t size,
               int _EXFUN((*_compar),(_CONST _PTR , _CONST _PTR ))));
div_t   _EXFUN(div,(int _numer, int _denom));
_VOID   _EXFUN(exit,(int _status)) __NORETURN;
char *  _EXFUN(getenv,(_CONST char *_string));
long    _EXFUN(labs,(long));
ldiv_t  _EXFUN(ldiv,(long _numer, long _denom));
_VOID   _EXFUN(qsort,(_PTR _base, size_t _nmemb, size_t _size, int(*_compar)(_CONST _PTR , _CONST _PTR )));
int _EXFUN(rand,(_VOID));
_VOID   _EXFUN(srand,(unsigned _seed));
double  _EXFUN(strtod,(_CONST char *n, char **end_PTR));
float   _EXFUN(strtodf,(_CONST char *n, char **end_PTR));
long    _EXFUN(strtol,(_CONST char *_n, char **_end_PTR, int _base));
unsigned long _EXFUN(strtoul,(_CONST char *_n_PTR, char **_end_PTR, int _base));

#if __STRICT_ANSI__ == 0 || __STDC_VERSION__ >= 199901L
         long long _EXFUN( strtoll,(_CONST char *_n_PTR, char **_end_PTR, int _base));
unsigned long long _EXFUN(strtoull,(_CONST char *_n_PTR, char **_end_PTR, int _base));
#endif

int _EXFUN(system,(_CONST char *_string));

int _EXFUN(putenv,(_CONST char *_string));
int _EXFUN(setenv,(_CONST char *_string, _CONST char *_value, int _overwrite));

char * _EXFUN(gcvt,(double,int,char *));
char * _EXFUN(gcvtf,(float,int,char *));
char * _EXFUN(fcvt,(double,int,int *,int *));
char * _EXFUN(fcvtf,(float,int,int *,int *));
char * _EXFUN(ecvt,(double,int,int *,int *));
char * _EXFUN(ecvtbuf,(double, int, int*, int*, char *));
char * _EXFUN(fcvtbuf,(double, int, int*, int*, char *));
char * _EXFUN(ecvtf,(float,int,int *,int *));
char * _EXFUN(dtoa,(double, int, int, int *, int*, char**));

char * _EXFUN(mktemp,(char *templte));
int _EXFUN(mkstemp,(char *templte));

#ifdef __cplusplus
}
#endif

#include <malloc.h>

/* Include alloca() declaration as required by ANSI standard */
#include <alloca.h>

/* FIXME: stubs for STLport!
 * These declarations are needed only to compile something like
 *   using std::mblen;
 * No implementation is provided.
 * { */
#ifdef __cplusplus
extern "C" {
int mblen(const char *s, size_t n);
size_t mbstowcs(wchar_t * /*restrict*/ pwcs, const char * /*restrict*/ s, size_t n);
int mbtowc(wchar_t * /*restrict*/ pwc, const char * /*restrict*/ s, size_t n);
size_t wcstombs(char * /*restrict*/ s, const wchar_t * /*restrict*/ pwcs, size_t n);
int wctomb(char *s, wchar_t wchar);
} /* extern "C" */
#endif /* __cplusplus */
/* } FIXME */

#endif /* _STDLIB_H_ */
