]> pd.if.org Git - pdclib/blobdiff - includes/stdlib.h
Add nothrow annotations where appropriate
[pdclib] / includes / stdlib.h
index 15f07b026c2d4da7a723249f22803135e2a2f234..22cc80c72b5e52011897f5a9b3fd2b05c7868fa9 100644 (file)
@@ -25,10 +25,10 @@ typedef _PDCLIB_size_t size_t;
 
 /* 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 +52,10 @@ long double strtold( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restri
 /* 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 );
-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 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 +65,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 +80,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 +93,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 +118,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 +138,14 @@ void * realloc( void * ptr, size_t size );
    temporary files before exiting with EXIT_FAILURE.
    abort() does not return.
 */
-_PDCLIB_noreturn void abort( void );
+_PDCLIB_noreturn void abort( void ) _PDCLIB_nothrow;
 
 /* 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 +153,7 @@ int atexit( void (*func)( void ) );
    and EXIT_FAILURE above.)
    exit() does not return.
 */
-_PDCLIB_noreturn 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 +161,7 @@ _PDCLIB_noreturn void exit( int status );
    comment for EXIT_SUCCESS and EXIT_FAILURE above.)
    _Exit() does not return.
 */
-_PDCLIB_noreturn 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 +170,14 @@ _PDCLIB_noreturn 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 +190,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 +202,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 +213,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 +229,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 */