]> pd.if.org Git - pdclib/blob - includes/stdlib.h
Some cleanup.
[pdclib] / includes / stdlib.h
1 // ----------------------------------------------------------------------------
2 // $Id$
3 // ----------------------------------------------------------------------------
4 // Public Domain C Library - http://pdclib.sourceforge.net
5 // This code is Public Domain. Use, modify, and redistribute at will.
6 // ----------------------------------------------------------------------------
7 // General utilities
8 // ----------------------------------------------------------------------------
9
10 #ifndef __STDLIB_H
11 #define __STDLIB_H __STDLIB_H
12
13 // ----------------------------------------------------------------------------
14 // MACROS
15
16 #define EXIT_FAILURE // TODO
17 #define EXIT_SUCCESS // TODO
18 #define MB_CUR_MAX   // TODO
19 #define NULL         0
20 #define RAND_MAX     // TODO
21
22 // ----------------------------------------------------------------------------
23 // TYPEDEFS
24
25 typedef struct
26 {
27     int quotient;
28     int remainder;
29 } div_t;
30
31 typedef struct
32 {
33     long quotient;
34     long remainder;
35 } ldiv_t;
36
37 typedef struct
38 {   long long quotient;
39     long long remainder;
40 } lldiv_t;
41
42 typedef size_t; // TODO
43
44 #ifndef __cplusplus
45 typedef wchar_t; // TODO
46 #endif // __cplusplus
47
48 // ----------------------------------------------------------------------------
49 // FUNCTIONS - C++
50
51 #ifdef __cplusplus
52
53 long abs( long i );
54 long long abs( long long i );
55
56 ldiv_t div( long numer, long denom );
57 lldiv_t div( long long numer, long long denom );
58
59 extern "C++" int atexit( void (*func) ( void ) );
60 extern "C"   int atexit( void (*func) ( void ) );
61
62 extern "C++" void * bsearch( const void * key, const void * base,
63                              size_t nelem, size_t size,
64                              int (*cmp) ( const void * ck, const void * ce ) );
65 extern "C"   void * bsearch( const void * key, const void * base,
66                              size_t nelem, size_t size,
67                              int (*cmp) ( const void * ck, const void * ce ) );
68
69 extern "C++" void qsort( void * base, size_t nelem, size_t size,
70                          int (*cmp) ( const void * e1, const void * e2 ) );
71 extern "C"   void qsort( void * base, size_t nelem, size_t size,
72                          int (*cmp) ( const void * e1, const void * e2 ) );
73
74 #endif // __cplusplus
75
76 // ----------------------------------------------------------------------------
77 // FUNCTIONS - Standard C
78
79 int abs( int i );
80 long long llabs( long long i );
81 long labs( long i );
82
83 div_t div( int numer, int denom );
84 lldiv_t lldiv( long long numer, long long denom );
85 ldiv_t ldiv( long numer, long denom );
86
87 int rand( void );
88 void srand( unsigned int seed );
89
90 double atof( const char * s );
91 int atoi( const char * s );
92 long atol( const char * s );
93 long long atoll( const char * s);
94
95 double strtod( const char * restrict s, char * * restrict endptr );
96 float strtof( const char * restrict s, char * * restrict endptr );
97 long double strtold( const char * restrict s, char * * restrict endptr );
98
99 long long strtoll( const char * restrict s, char * * restrict endptr, int base );
100 unsigned long long strtoull( const char * restrict s, char * * restrict endptr, int base);
101
102 long strtol( const char * restrict s, char * * restrict endptr, int base );
103 unsigned long strtoul( const char * restrict s, char * * restrict endptr, int base);
104
105 void * calloc( size_t nelem, size_t size );
106 void free( void * ptr );
107 void * malloc( size_t size );
108 void * realloc( void * ptr, size_t size );
109
110 int mblen( const char * s, size_t n );
111 size_t mbstowcs( wchar_t * restrict wcs, const char * restrict s, size_t n );
112 int mbtowc( wchar_t * restrict pwc, const char * restrict s, size_t n );
113 size_t wcstombs( char * restrict s, const wchar_t * restrict wcs, size_t n );
114 int wctomb( char * s, wchar_t wchar );
115
116 void _Exit( int status );
117 void exit( int status );
118 void abort( void );
119 char * getenv( const char * name );
120 int system( const char * s );
121
122 #ifndef __cplusplus
123
124 int atexit( void (*func) ( void ) );
125 void * bsearch( const void * key, const void * base, size_t nelem, size_t size,
126                 int (*cmp) ( const void * ck, const void * ce) );
127 void qsort( void * base, size_t nelem, size_t size,
128             int (*cmp) ( const void * e1, const void * e2) );
129
130 #endif // __cplusplus
131
132 #endif // __STDLIB_H