]> pd.if.org Git - pdclib/blob - includes/stdlib.h
Added exit, _Exit, atexit.
[pdclib] / includes / stdlib.h
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* General utilities <stdlib.h>
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 #ifndef _PDCLIB_STDLIB_H
12 #define _PDCLIB_STDLIB_H _PDCLIB_STDLIB_H
13
14 #ifndef _PDCLIB_INT_H
15 #define _PDCLIB_INT_H _PDCLIB_INT_H
16 #include <_PDCLIB_int.h>
17 #endif
18
19 #ifndef _PDCLIB_SIZE_T_DEFINED
20 #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED
21 typedef _PDCLIB_size_t size_t;
22 #endif
23
24 #define NULL         _PDCLIB_NULL
25 #define EXIT_SUCCESS _PDCLIB_SUCCESS
26 #define EXIT_FAILURE _PDCLIB_FAILURE
27
28 /* Numeric conversion functions */
29
30 /* TODO: atof(), strtof(), strtod(), strtold() */
31
32 /* Seperate the character array nptr into three parts: A (possibly empty)
33    sequence of whitespace characters, a character representation of an integer
34    to the given base, and trailing invalid characters (including the terminating
35    null character). If base is 0, assume it to be 10, unless the integer
36    representation starts with 0x / 0X (setting base to 16) or 0 (setting base to
37    8). If given, base can be anything from 0 to 36, using the 26 letters of the
38    base alphabet (both lowercase and uppercase) as digits 10 through 35.
39    The integer representation is then converted into the return type of the
40    function. It can start with a '+' or '-' sign. If the sign is '-', the result
41    of the conversion is negated.
42    If the conversion is successful, the converted value is returned. If endptr
43    is not a NULL pointer, a pointer to the first trailing invalid character is
44    returned in *endptr.
45    If no conversion could be performed, zero is returned (and nptr in *endptr,
46    if endptr is not a NULL pointer). If the converted value does not fit into
47    the return type, the functions return LONG_MIN, LONG_MAX, ULONG_MAX,
48    LLONG_MIN, LLONG_MAX, or ULLONG_MAX respectively, depending on the sign of
49    the integer representation and the return type, and errno is set to ERANGE.
50 */
51 long int strtol( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base );
52 long long int strtoll( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base );
53 unsigned long int strtoul( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base );
54 unsigned long long int strtoull( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base );
55
56 /* These functions are the equivalent of (int)strtol( nptr, NULL, 10 ),
57    strtol( nptr, NULL, 10 ) and strtoll(nptr, NULL, 10 ) respectively, with the
58    exception that they do not have to handle overflow situations in any defined
59    way.
60    (PDCLib does not simply forward these to their strtox() equivalents, but
61    provides a simpler atox() function that saves a couple of tests and simply
62    continues with the conversion in case of overflow.)
63 */
64 int atoi( const char * nptr );
65 long int atol( const char * nptr );
66 long long int atoll( const char * nptr );
67
68 /* Pseudo-random sequence generation functions */
69
70 extern unsigned long int _PDCLIB_seed;
71
72 #define RAND_MAX 32767
73
74 /* Returns the next number in a pseudo-random sequence, which is between 0 and
75    RAND_MAX.
76    (PDCLib uses the implementation suggested by the standard document, which is
77    next = next * 1103515245 + 12345; return (unsigned int)(next/65536) % 32768;)
78 */
79 int rand();
80
81 /* Initialize a new pseudo-random sequence with the starting seed. Same seeds
82    result in the same pseudo-random sequence. The default seed is 1.
83 */
84 void srand( unsigned int seed );
85
86 /* Memory management functions */
87
88 void * malloc( size_t size );
89 void free( void * ptr );
90
91 /* Communication with the environment */
92
93 void abort();
94 void exit( int status );
95 void _Exit( int status );
96
97 /* Searching and sorting */
98
99 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, int (*compar)( const void *, const void * ) );
100 void qsort( void * base, size_t nmemb, size_t size, int (*compar)( const void *, const void * ) );
101
102 /* Integer arithmetic functions */
103
104 int abs( int j );
105 long int labs( long int j );
106 long long int llabs( long long int j );
107
108 typedef struct _PDCLIB_div_t     div_t;
109 typedef struct _PDCLIB_ldiv_t   ldiv_t;
110 typedef struct _PDCLIB_lldiv_t lldiv_t;
111
112 div_t div( int numer, int denom );
113 ldiv_t ldiv( long int numer, long int denom );
114 lldiv_t lldiv( long long int numer, long long int denom );
115
116 /* Multibyte / wide character conversion functions */
117
118 /* TODO: Macro MB_CUR_MAX */
119
120 /* Multibyte / wide string conversion functions */
121
122
123 #endif