]> pd.if.org Git - pdclib.old/blobdiff - includes/stdlib.h
Modify various POSIX platform files so you can build on top of glibc for testing
[pdclib.old] / includes / stdlib.h
index 026a82a5020cc7ea97b53bd2234619e99a8aeafe..1151d1acc23f401b87bb367e557e8b6a158f7b70 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$ */
 
-/* General utilities <stdlib.h>
+/* 7.20 General utilities <stdlib.h>
 
    This file is part of the Public Domain C Library (PDCLib).
    Permission is granted to use, modify, and / or redistribute at will.
@@ -8,11 +8,8 @@
 
 #ifndef _PDCLIB_STDLIB_H
 #define _PDCLIB_STDLIB_H _PDCLIB_STDLIB_H
-
-#ifndef _PDCLIB_INT_H
-#define _PDCLIB_INT_H _PDCLIB_INT_H
 #include <_PDCLIB_int.h>
-#endif
+_PDCLIB_BEGIN_EXTERN_C
 
 #ifndef _PDCLIB_SIZE_T_DEFINED
 #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED
@@ -24,14 +21,19 @@ typedef _PDCLIB_size_t size_t;
 #define NULL _PDCLIB_NULL
 #endif
 
+#ifndef _PDCLIB_MB_CUR_MAX_DEFINED
+#define _PDCLIB_MB_CUR_MAX_DEFINED
+#define MB_CUR_MAX (_PDCLIB_mb_cur_max())
+#endif
+
 /* Numeric conversion functions */
 
 /* TODO: atof(), strtof(), strtod(), strtold() */
 
-double atof( const char * nptr );
-double strtod( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr );
-float strtof( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr );
-long double strtold( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr );
+double atof( const char * nptr ) _PDCLIB_nothrow;
+double strtod( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr ) _PDCLIB_nothrow;
+float strtof( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr ) _PDCLIB_nothrow;
+long double strtold( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr ) _PDCLIB_nothrow;
 
 /* Seperate the character array nptr into three parts: A (possibly empty)
    sequence of whitespace characters, a character representation of an integer
@@ -52,10 +54,13 @@ long double strtold( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restri
    LLONG_MIN, LLONG_MAX, or ULLONG_MAX respectively, depending on the sign of
    the integer representation and the return type, and errno is set to ERANGE.
 */
-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 );
+/* There is strtoimax() and strtoumax() in <inttypes.h> operating on intmax_t /
+   uintmax_t, if the long long versions do not suit your needs.
+*/
+long int strtol( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ) _PDCLIB_nothrow;
+long long int strtoll( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ) _PDCLIB_nothrow;
+unsigned long int strtoul( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ) _PDCLIB_nothrow;
+unsigned long long int strtoull( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ) _PDCLIB_nothrow;
 
 /* These functions are the equivalent of (int)strtol( nptr, NULL, 10 ),
    strtol( nptr, NULL, 10 ) and strtoll(nptr, NULL, 10 ) respectively, with the
@@ -65,9 +70,9 @@ unsigned long long int strtoull( const char * _PDCLIB_restrict nptr, char * * _P
    provides a simpler atox() function that saves a couple of tests and simply
    continues with the conversion in case of overflow.)
 */
-int atoi( const char * nptr );
-long int atol( const char * nptr );
-long long int atoll( const char * nptr );
+int atoi( const char * nptr ) _PDCLIB_nothrow;
+long int atol( const char * nptr ) _PDCLIB_nothrow;
+long long int atoll( const char * nptr ) _PDCLIB_nothrow;
 
 /* Pseudo-random sequence generation functions */
 
@@ -80,12 +85,12 @@ extern unsigned long int _PDCLIB_seed;
    (PDCLib uses the implementation suggested by the standard document, which is
    next = next * 1103515245 + 12345; return (unsigned int)(next/65536) % 32768;)
 */
-int rand( void );
+int rand( void ) _PDCLIB_nothrow;
 
 /* Initialize a new pseudo-random sequence with the starting seed. Same seeds
    result in the same pseudo-random sequence. The default seed is 1.
 */
-void srand( unsigned int seed );
+void srand( unsigned int seed ) _PDCLIB_nothrow;
 
 /* Memory management functions */
 
@@ -93,21 +98,21 @@ void srand( unsigned int seed );
    satisfied, return NULL. Otherwise, return a pointer to the allocated
    memory. Memory contents are undefined.
 */
-void * malloc( size_t size );
+void * malloc( size_t size ) _PDCLIB_nothrow;
 
 /* Allocate a chunk of heap memory that is large enough to hold nmemb elements
    of the given size, and zero-initialize that memory. If request could not be
    satisfied, return NULL. Otherwise, return a pointer to the allocated
    memory.
 */
-void * calloc( size_t nmemb, size_t size );
+void * calloc( size_t nmemb, size_t size ) _PDCLIB_nothrow;
 
 /* De-allocate a chunk of heap memory previously allocated using malloc(),
    calloc(), or realloc(), and pointed to by ptr. If ptr does not match a
    pointer previously returned by the mentioned allocation functions, or
    free() has already been called for this ptr, behaviour is undefined.
 */
-void free( void * ptr );
+void free( void * ptr ) _PDCLIB_nothrow;
 
 /* Resize a chunk of memory previously allocated with malloc() and pointed to
    by ptr to the given size (which might be larger or smaller than the original
@@ -118,7 +123,7 @@ void free( void * ptr );
    memory beyond the original size is undefined. If ptr is NULL, realloc()
    behaves like malloc().
 */
-void * realloc( void * ptr, size_t size );
+void * realloc( void * ptr, size_t size ) _PDCLIB_nothrow;
 
 /* Communication with the environment */
 
@@ -138,14 +143,14 @@ void * realloc( void * ptr, size_t size );
    temporary files before exiting with EXIT_FAILURE.
    abort() does not return.
 */
-void abort( void );
+_PDCLIB_noreturn void abort( void ) _PDCLIB_nothrow;
 
-/* Register a function that will be called on exit(), _Exit(), or when main()
-   returns. At least 32 functions can be registered this way, and will be
-   called in reverse order of registration (last-in, first-out).
+/* Register a function that will be called on exit(), or when main() returns.
+   At least 32 functions can be registered this way, and will be called in
+   reverse order of registration (last-in, first-out).
    Returns zero if registration is successfull, nonzero if it failed.
 */
-int atexit( void (*func)( void ) ); 
+int atexit( void (*func)( void ) ) _PDCLIB_nothrow
 
 /* Normal process termination. Functions registered by atexit() (see above) are
    called, streams flushed, files closed and temporary files removed before the
@@ -153,7 +158,7 @@ int atexit( void (*func)( void ) );
    and EXIT_FAILURE above.)
    exit() does not return.
 */
-void exit( int status );
+_PDCLIB_noreturn void exit( int status ) _PDCLIB_nothrow;
 
 /* Normal process termination. Functions registered by atexit() (see above) are
    NOT CALLED. This implementation DOES flush streams, close files and removes
@@ -161,7 +166,7 @@ void exit( int status );
    comment for EXIT_SUCCESS and EXIT_FAILURE above.)
    _Exit() does not return.
 */
-void _Exit( int status );
+_PDCLIB_noreturn void _Exit( int status ) _PDCLIB_nothrow;
 
 /* Search an environment-provided key-value map for the given key name, and
    return a pointer to the associated value string (or NULL if key name cannot
@@ -170,14 +175,14 @@ void _Exit( int status );
    Details on the provided keys and how to set / change them are determined by
    the hosting OS and its glue function.
 */
-char * getenv( const char * name );
+char * getenv( const char * name ) _PDCLIB_nothrow;
 
 /* If string is a NULL pointer, system() returns nonzero if a command processor
    is available, and zero otherwise. If string is not a NULL pointer, it is
    passed to the command processor. If system() returns, it does so with a
    value that is determined by the hosting OS and its glue function.
 */
-int system( const char * string );
+int system( const char * string ) _PDCLIB_nothrow;
 
 /* Searching and sorting */
 
@@ -190,6 +195,8 @@ int system( const char * string );
    greater than the array element, respectively.
    The function returns a pointer to the first matching element found, or NULL
    if no match is found.
+
+   ** May throw **
 */
 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, int (*compar)( const void *, const void * ) );
 
@@ -200,6 +207,8 @@ void * bsearch( const void * key, const void * base, size_t nmemb, size_t size,
    to be less than, equal to, or greater than the second argument, respectively.
    If two elements are compared equal, their order in the sorted array is not
    specified.
+
+   ** May throw **
 */
 void qsort( void * base, size_t nmemb, size_t size, int (*compar)( const void *, const void * ) );
 
@@ -209,9 +218,9 @@ void qsort( void * base, size_t nmemb, size_t size, int (*compar)( const void *,
    complement's notation (most modern CPUs), the largest negative value cannot
    be represented as positive value. In this case, behaviour is unspecified.
 */
-int abs( int j );
-long int labs( long int j );
-long long int llabs( long long int j );
+int abs( int j ) _PDCLIB_nothrow;
+long int labs( long int j ) _PDCLIB_nothrow;
+long long int llabs( long long int j ) _PDCLIB_nothrow;
 
 /* These structures each have a member quot and a member rem, of type int (for
    div_t), long int (for ldiv_t) and long long it (for lldiv_t) respectively.
@@ -225,9 +234,9 @@ typedef struct _PDCLIB_lldiv_t lldiv_t;
 /* Return quotient (quot) and remainder (rem) of an integer division in one of
    the structs above.
 */
-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 );
+div_t div( int numer, int denom ) _PDCLIB_nothrow;
+ldiv_t ldiv( long int numer, long int denom ) _PDCLIB_nothrow;
+lldiv_t lldiv( long long int numer, long long int denom ) _PDCLIB_nothrow;
 
 /* TODO: Multibyte / wide character conversion functions */
 
@@ -241,4 +250,5 @@ size_t mbstowcs( wchar_t * _PDCLIB_restrict pwcs, const char * _PDCLIB_restrict
 size_t wcstombs( char * _PDCLIB_restrict s, const wchar_t * _PDCLIB_restrict pwcs, size_t n );
 */
 
+_PDCLIB_END_EXTERN_C
 #endif