X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=includes%2Fstdlib.h;h=e436c6f18d3cfcb795a656e953ad231ead9c3268;hb=aa980e7f23430161549089ab9661f07d9db116c4;hp=4518f2273111f603df9b25fb88d1c8283133288d;hpb=ac3f809c3c10347c110fac3db93af0954eda98bb;p=pdclib diff --git a/includes/stdlib.h b/includes/stdlib.h index 4518f22..e436c6f 100644 --- a/includes/stdlib.h +++ b/includes/stdlib.h @@ -1,132 +1,80 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- -// General utilities -// ---------------------------------------------------------------------------- +/* $Id$ */ -#ifndef __STDLIB_H -#define __STDLIB_H __STDLIB_H +/* Release $Name$ */ -// ---------------------------------------------------------------------------- -// MACROS +/* General utilities -#define EXIT_FAILURE // TODO -#define EXIT_SUCCESS // TODO -#define MB_CUR_MAX // TODO -#define NULL 0 -#define RAND_MAX // TODO + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ -// ---------------------------------------------------------------------------- -// TYPEDEFS +#ifndef _PDCLIB_STDLIB_H +#define _PDCLIB_STDLIB_H _PDCLIB_STDLIB_H -typedef struct -{ - int quotient; - int remainder; -} div_t; +#ifndef _PDCLIB_INT_H +#define _PDCLIB_INT_H _PDCLIB_INT_H +#include <_PDCLIB_int.h> +#endif -typedef struct -{ - long quotient; - long remainder; -} ldiv_t; +typedef struct _PDCLIB_div_t div_t; +typedef struct _PDCLIB_ldiv_t ldiv_t; +typedef struct _PDCLIB_lldiv_t lldiv_t; -typedef struct -{ long long quotient; - long long remainder; -} lldiv_t; +#ifndef _PDCLIB_SIZE_T_DEFINED +#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED +typedef _PDCLIB_size_t size_t; +#endif -typedef size_t; // TODO +#define NULL _PDCLIB_NULL +#define EXIT_SUCCESS _PDCLIB_SUCCESS; +#define EXIT_FAILURE _PDCLIB_FAILURE; -#ifndef __cplusplus -typedef wchar_t; // TODO -#endif // __cplusplus +/* Numeric conversion functions */ -// ---------------------------------------------------------------------------- -// FUNCTIONS - C++ +int atoi( const char * nptr ); +long int atol( const char * nptr ); +long long int atoll( const char * nptr ); -#ifdef __cplusplus +long int strtol( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ); +long long int strtoll( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ); +unsigned long int strtoul( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ); +unsigned long long int strtoull( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ); -long abs( long i ); -long long abs( long long i ); +/* Pseudo-random sequence generation functions */ -ldiv_t div( long numer, long denom ); -lldiv_t div( long long numer, long long denom ); +extern unsigned long int _PDCLIB_seed; -extern "C++" int atexit( void (*func) ( void ) ); -extern "C" int atexit( void (*func) ( void ) ); +#define RAND_MAX 32767 -extern "C++" void * bsearch( const void * key, const void * base, - size_t nelem, size_t size, - int (*cmp) ( const void * ck, const void * ce ) ); -extern "C" void * bsearch( const void * key, const void * base, - size_t nelem, size_t size, - int (*cmp) ( const void * ck, const void * ce ) ); - -extern "C++" void qsort( void * base, size_t nelem, size_t size, - int (*cmp) ( const void * e1, const void * e2 ) ); -extern "C" void qsort( void * base, size_t nelem, size_t size, - int (*cmp) ( const void * e1, const void * e2 ) ); +int rand(); +void srand( unsigned int seed ); -#endif // __cplusplus +/* Memory management functions */ -// ---------------------------------------------------------------------------- -// FUNCTIONS - Standard C -int abs( int i ); -long long llabs( long long i ); -long labs( long i ); +/* Communication with the environment */ -div_t div( int numer, int denom ); -lldiv_t lldiv( long long numer, long long denom ); -ldiv_t ldiv( long numer, long denom ); +void abort(); +void exit(); -int rand( void ); -void srand( unsigned int seed ); +/* Searching and sorting */ -double atof( const char * s ); -int atoi( const char * s ); -long atol( const char * s ); -long long atoll( const char * s); -double strtod( const char * restrict s, char * * restrict endptr ); -float strtof( const char * restrict s, char * * restrict endptr ); -long double strtold( const char * restrict s, char * * restrict endptr ); +/* Integer arithmetic functions */ -long long strtoll( const char * restrict s, char * * restrict endptr, int base ); -unsigned long long strtoull( const char * restrict s, char * * restrict endptr, int base); +int abs( int j ); +long int labs( long int j ); +long long int llabs( long long int j ); -long strtol( const char * restrict s, char * * restrict endptr, int base ); -unsigned long strtoul( const char * restrict s, char * * restrict endptr, int base); - -void * calloc( size_t nelem, size_t size ); -void free( void * ptr ); -void * malloc( size_t size ); -void * realloc( void * ptr, size_t size ); - -int mblen( const char * s, size_t n ); -size_t mbstowcs( wchar_t * restrict wcs, 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 wcs, size_t n ); -int wctomb( char * s, wchar_t wchar ); +div_t div( int numer, int denom ); +ldiv_t ldiv( long int numer, long int denom ); +lldiv_t lldiv( long long int numer, long long int denom ); -void _Exit( int status ); -void exit( int status ); -void abort( void ); -char * getenv( const char * name ); -int system( const char * s ); +/* Multibyte / wide character conversion functions */ -#ifndef __cplusplus +/* TODO: Macro MB_CUR_MAX */ -int atexit( void (*func) ( void ) ); -void * bsearch( const void * key, const void * base, size_t nelem, size_t size, - int (*cmp) ( const void * ck, const void * ce) ); -void qsort( void * base, size_t nelem, size_t size, - int (*cmp) ( const void * e1, const void * e2) ); +/* Multibyte / wide string conversion functions */ -#endif // __cplusplus -#endif // __STDLIB_H +#endif