//
// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
//
// The contents of this file are covered under the licence agreement in the
// file "LICENCE" distributed with Cforall.
//
// stdlib --
//
// Author           : Peter A. Buhr
// Created On       : Thu Jan 28 17:12:35 2016
// Last Modified By : Peter A. Buhr
// Last Modified On : Fri Feb 24 21:07:16 2017
// Update Count     : 101
//

#ifndef STDLIB_H
#define STDLIB_H

//---------------------------------------

extern "C" {
#ifndef EXIT_FAILURE
#define	EXIT_FAILURE	1								// failing exit status
#define	EXIT_SUCCESS	0								// successful exit status
#endif // ! EXIT_FAILURE
} // extern "C"

//---------------------------------------

extern "C" { void * malloc( size_t ); }					// use default C routine for void *
forall( dtype T | sized(T) ) T * malloc( void );
forall( dtype T | sized(T) ) T * malloc( char fill );
forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size );
forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, unsigned char fill );
extern "C" { void * calloc( size_t nmemb, size_t size ); } // use default C routine for void *
forall( dtype T | sized(T) ) T * calloc( size_t nmemb );
extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void *
forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );
forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, unsigned char fill );

forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment );
forall( dtype T | sized(T) ) T * memalign( size_t alignment );		// deprecated
forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment );

extern "C" {
void * memset( void * ptr, int fill, size_t size );
void free( void * ptr );
} // extern "C"

forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );
forall( dtype T | { void ^?{}(T *); } ) void delete( T * ptr );
forall( dtype T, ttype Params | { void ^?{}(T *); void delete(Params); } ) void delete( T * ptr, Params rest );

//---------------------------------------

int ato( const char * ptr );
unsigned int ato( const char * ptr );
long int ato( const char * ptr );
unsigned long int ato( const char * ptr );
long long int ato( const char * ptr );
unsigned long long int ato( const char * ptr );
float ato( const char * ptr );
double ato( const char * ptr );
long double ato( const char * ptr );
float _Complex ato( const char * ptr );
double _Complex ato( const char * ptr );
long double _Complex ato( const char * ptr );

int strto( const char * sptr, char ** eptr, int base );
unsigned int strto( const char * sptr, char ** eptr, int base );
long int strto( const char * sptr, char ** eptr, int base );
unsigned long int strto( const char * sptr, char ** eptr, int base );
long long int strto( const char * sptr, char ** eptr, int base );
unsigned long long int strto( const char * sptr, char ** eptr, int base );
float strto( const char * sptr, char ** eptr );
double strto( const char * sptr, char ** eptr );
long double strto( const char * sptr, char ** eptr );
float _Complex strto( const char * sptr, char ** eptr );
double _Complex strto( const char * sptr, char ** eptr );
long double _Complex strto( const char * sptr, char ** eptr );

//---------------------------------------

forall( otype T | { int ?<?( T, T ); } )
T * bsearch( T key, const T * arr, size_t dimension );

forall( otype T | { int ?<?( T, T ); } )
void qsort( const T * arr, size_t dimension );

//---------------------------------------

forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
[ T, T ] div( T t1, T t2 );

//---------------------------------------

unsigned char abs( signed char );
extern "C" { int abs( int ); }							// use default C routine for int
unsigned long int abs( long int );
unsigned long long int abs( long long int );
float abs( float );
double abs( double );
long double abs( long double );
float abs( float _Complex );
double abs( double _Complex );
long double abs( long double _Complex );

//---------------------------------------

void rand48seed( long int s );
char rand48();
int rand48();
unsigned int rand48();
long int rand48();
unsigned long int rand48();
float rand48();
double rand48();
float _Complex rand48();
double _Complex rand48();
long double _Complex rand48();

//---------------------------------------

forall( otype T | { int ?<?( T, T ); } )
T min( T t1, T t2 );

forall( otype T | { int ?>?( T, T ); } )
T max( T t1, T t2 );

forall( otype T | { T min( T, T ); T max( T, T ); } )
T clamp( T value, T min_val, T max_val );

forall( otype T )
void swap( T * t1, T * t2 );

#endif // STDLIB_H

// Local Variables: //
// mode: c //
// tab-width: 4 //
// End: //
