#ifndef _MSL_CSTDLIB
#define _MSL_CSTDLIB

#include <ansi_params.h>

#if !_MSL_USING_MW_C_HEADERS
    #include <stdlib.h>

    #if _MSL_PUT_THIRD_PARTY_C_IN_STD
        #include <msl_cpp_std_stdlib.h>
    #endif
#elif defined(__PALMOS_TRAPS__)
    #include <cstdlib_Palm_OS>
#else

#include <div_t.h>
#include <null.h>
#include <size_t.h>
#include <msl_secure.h>
#include <msl_rsize_t.h>

#if _MSL_WIDE_CHAR
    #include <wchar_t.h>
#endif

#if _MSL_NEEDS_EXTRAS
    #include <extras_stdlib.h>
#endif

#ifndef RC_INVOKED

#ifndef _MSL_MB_CUR_MAX
    #define _MSL_MB_CUR_MAX 3
#endif

_MSL_BEGIN_NAMESPACE_STD
    _MSL_BEGIN_EXTERN_C

#define RAND_MAX 32767

#if defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__
    #define RAND_MAX_S 32767
#endif

#define MB_CUR_MAX _MSL_MB_CUR_MAX

#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1

#define _MAX_PATH 1024

#if _MSL_FLOATING_POINT
_MSL_IMP_EXP_C double _MSL_CDECL atof(const char *) _MSL_CANT_THROW;
_MSL_IMP_EXP_C double _MSL_CDECL strtod(const char * _MSL_RESTRICT, char * * _MSL_RESTRICT) _MSL_CANT_THROW;
_MSL_IMP_EXP_C long double _MSL_CDECL strtold(const char * _MSL_RESTRICT, char * * _MSL_RESTRICT) _MSL_CANT_THROW;
#if _MSL_C99
_MSL_IMP_EXP_C float _MSL_CDECL strtof(const char * _MSL_RESTRICT, char * * _MSL_RESTRICT) _MSL_CANT_THROW;
#endif
#endif

_MSL_IMP_EXP_C int _MSL_CDECL atoi(const char *) _MSL_CANT_THROW;
_MSL_IMP_EXP_C long _MSL_CDECL atol(const char *) _MSL_CANT_THROW;

#if _MSL_LONGLONG
#if _MSL_C99
_MSL_IMP_EXP_C long long _MSL_CDECL atoll(const char *) _MSL_CANT_THROW;
#endif
#endif

_MSL_IMP_EXP_C long _MSL_CDECL strtol(const char * _MSL_RESTRICT, char * * _MSL_RESTRICT, int) _MSL_CANT_THROW;
_MSL_IMP_EXP_C unsigned long _MSL_CDECL strtoul(const char * _MSL_RESTRICT, char * * _MSL_RESTRICT, int) _MSL_CANT_THROW;

#if _MSL_LONGLONG
#if _MSL_C99
_MSL_IMP_EXP_C long long _MSL_CDECL strtoll(const char * _MSL_RESTRICT, char * * _MSL_RESTRICT, int) _MSL_CANT_THROW;
_MSL_IMP_EXP_C unsigned long long _MSL_CDECL strtoull(const char * _MSL_RESTRICT, char * * _MSL_RESTRICT, int) _MSL_CANT_THROW;
#endif
#endif

_MSL_IMP_EXP_C int _MSL_CDECL rand(void) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void _MSL_CDECL srand(unsigned int) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void * _MSL_CDECL calloc(size_t, size_t) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void _MSL_CDECL free(void *) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void * _MSL_CDECL malloc(size_t) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void * _MSL_CDECL realloc(void *, size_t) _MSL_CANT_THROW;
_MSL_IMP_EXP_C size_t _MSL_CDECL __msize(void *) _MSL_CANT_THROW;

#if !(defined(_MSL_PRO4_MALLOC) || defined(_MSL_CLASSIC_MALLOC) || defined(_MSL_MALLOC_BACKUP))

#ifndef _MSL_ALLOCATE_SIZE
    #define _MSL_ALLOCATE_SIZE __allocate_size
#endif

#ifndef _MSL_ALLOCATE
    #define _MSL_ALLOCATE __allocate
#endif

#ifndef _MSL_ALLOCATE_RESIZE
    #define _MSL_ALLOCATE_RESIZE __allocate_resize
#endif

#ifndef _MSL_ALLOCATE_EXPAND
    #define _MSL_ALLOCATE_EXPAND __allocate_expand
#endif

_MSL_IMP_EXP_C size_t _MSL_CDECL _MSL_ALLOCATE_SIZE(void *) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void * _MSL_CDECL _MSL_ALLOCATE(size_t, size_t *) _MSL_CANT_THROW;
_MSL_IMP_EXP_C int _MSL_CDECL _MSL_ALLOCATE_RESIZE(void *, size_t, size_t *) _MSL_CANT_THROW;
_MSL_IMP_EXP_C int _MSL_CDECL _MSL_ALLOCATE_EXPAND(void *, size_t, size_t, size_t *) _MSL_CANT_THROW;

#endif

#ifdef __VEC__

_MSL_IMP_EXP_C void * _MSL_CDECL vec_calloc(size_t, size_t) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void _MSL_CDECL vec_free(void *) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void * _MSL_CDECL vec_malloc(size_t) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void * _MSL_CDECL vec_realloc(void *, size_t) _MSL_CANT_THROW;

    #if _MSL_USE_INLINE && _MSL_MALLOC_IS_ALTIVEC_ALIGNED
_MSL_INLINE void * _MSL_CDECL vec_calloc (size_t _nmemb, size_t _size) _MSL_CANT_THROW {
    return calloc(_nmemb, _size);
}
_MSL_INLINE void _MSL_CDECL vec_free (void * _ptr) _MSL_CANT_THROW {
    free(_ptr);
}
_MSL_INLINE void * _MSL_CDECL vec_malloc (size_t _size) _MSL_CANT_THROW {
    return malloc(_size);
}
_MSL_INLINE void * _MSL_CDECL vec_realloc (void * _ptr, size_t _size) _MSL_CANT_THROW {
    return realloc(_ptr, _size);
}
    #endif
#endif

_MSL_IMP_EXP_C void _MSL_CDECL abort(void) _MSL_CANT_THROW;
_MSL_IMP_EXP_C int _MSL_CDECL atexit(void(_MSL_CDECL * func)(void)) _MSL_CANT_THROW;
_MSL_IMP_EXP_C void _MSL_CDECL exit(int);
#if _MSL_C99
_MSL_IMP_EXP_C void _MSL_CDECL _Exit(int) _MSL_CANT_THROW;
#endif

_MSL_IMP_EXP_C char * _MSL_CDECL getenv(const char *) _MSL_CANT_THROW;
_MSL_IMP_EXP_C int _MSL_CDECL system(const char *) _MSL_CANT_THROW;

typedef int (* _compare_function)(const void *, const void *);

_MSL_IMP_EXP_C void * _MSL_CDECL bsearch(const void *, const void *, size_t, size_t, _compare_function);
_MSL_IMP_EXP_C void _MSL_CDECL qsort(void *, size_t, size_t, _compare_function);

#if defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__
_MSL_IMP_EXP_C errno_t _MSL_CDECL getenv_s(size_t * _MSL_RESTRICT, char * _MSL_RESTRICT, rsize_t, const char * _MSL_RESTRICT) _MSL_CANT_THROW;

typedef int (* _compare_function_s)(const void *, const void *, void *);

_MSL_IMP_EXP_C void * _MSL_CDECL bsearch_s(const void *, const void *, rsize_t, rsize_t, _compare_function_s, void *);
_MSL_IMP_EXP_C void _MSL_CDECL qsort_s(void *, rsize_t, rsize_t, _compare_function_s, void *);

    #if _MSL_WIDE_CHAR
_MSL_IMP_EXP_C int _MSL_CDECL wctomb_s(int * _MSL_RESTRICT, char * _MSL_RESTRICT, rsize_t, wchar_t) _MSL_CANT_THROW;
    #endif
#endif

_MSL_IMP_EXP_C int _MSL_CDECL abs(int) _MSL_CANT_THROW;

_MSL_IMP_EXP_C long _MSL_CDECL labs(long) _MSL_CANT_THROW;

#if _MSL_LONGLONG
#if (_MSL_C99 || defined(__cplusplus))
_MSL_IMP_EXP_C long long _MSL_CDECL llabs(long long) _MSL_CANT_THROW;
#endif
#endif

#ifdef __POWERPC__

    #ifndef __cplusplus
        #if !__MOTO__ && !__MRC__
            #define abs(n) __abs(n)
            #define labs(n) __labs(n)
        #endif
    #endif

#endif

_MSL_IMP_EXP_C div_t _MSL_CDECL div(int, int) _MSL_CANT_THROW;
_MSL_IMP_EXP_C ldiv_t _MSL_CDECL ldiv(long, long) _MSL_CANT_THROW;

#if _MSL_LONGLONG
#if (_MSL_C99 || defined(__cplusplus))
_MSL_IMP_EXP_C lldiv_t _MSL_CDECL lldiv(long long, long long) _MSL_CANT_THROW;
#endif
#endif

#ifdef __cplusplus
_MSL_END_EXTERN_C

extern "C++" {
inline long _MSL_CDECL abs (long n) _MSL_CANT_THROW {
    return labs(n);
}
inline ldiv_t _MSL_CDECL div (long numerator, long denominator) _MSL_CANT_THROW {
    return ldiv(numerator, denominator);
}

        #if _MSL_LONGLONG
inline long long _MSL_CDECL abs (long long n) _MSL_CANT_THROW {
    return llabs(n);
}
inline lldiv_t _MSL_CDECL div (long long numerator, long long denominator) _MSL_CANT_THROW {
    return lldiv(numerator, denominator);
}
        #endif
}

_MSL_BEGIN_EXTERN_C
#endif

#if _MSL_WIDE_CHAR
_MSL_IMP_EXP_C int _MSL_CDECL mblen(const char *, size_t) _MSL_CANT_THROW;
_MSL_IMP_EXP_C int _MSL_CDECL mbtowc(wchar_t * _MSL_RESTRICT, const char * _MSL_RESTRICT, size_t) _MSL_CANT_THROW;
_MSL_IMP_EXP_C int _MSL_CDECL wctomb(char *, wchar_t) _MSL_CANT_THROW;
_MSL_IMP_EXP_C size_t _MSL_CDECL mbstowcs(wchar_t * _MSL_RESTRICT, const char * _MSL_RESTRICT, size_t) _MSL_CANT_THROW;
_MSL_IMP_EXP_C size_t _MSL_CDECL wcstombs(char * _MSL_RESTRICT, const wchar_t * _MSL_RESTRICT, size_t) _MSL_CANT_THROW;
#endif

_MSL_END_EXTERN_C
    _MSL_END_NAMESPACE_STD

#endif

#endif

#endif
