1 /*-------------------------------------------------------------------------
2 stdlib.h - General utilities (ISO C 11 7.22)
4 Copyright (C) 1998, Sandeep Dutta . sandeep.dutta@usa.net
5 Copyright (c) 2016-2021, Philipp Klaus Krause, pkk@spth.de
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
30 #ifndef __STDC_VERSION_STDLIB_H__
31 #define __STDC_VERSION_STDLIB_H__ 201710L /* TODO: replace by __STDC_VERSION__ when this header becomes C23-compliant! */
33 #if !defined(__SDCC_pic14)
34 #if __STDC_VERSION__ >= 199901L
35 #define __SDCC_LONGLONG
39 #if !defined(__SDCC_mcs51) && !defined(__SDCC_ds390) && !defined(__SDCC_ds400) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) && !defined(__SDCC_mos6502) && !defined(__SDCC_mos65c02) && !defined(__SDCC_pic14) && !defined(__SDCC_pic16) && !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15)
43 #ifndef __SIZE_T_DEFINED
44 #define __SIZE_T_DEFINED
45 typedef unsigned int size_t;
48 #ifndef __WCHAR_T_DEFINED
49 #define __WCHAR_T_DEFINED
50 typedef unsigned long int wchar_t;
54 #define NULL (void *)0
57 #define RAND_MAX 32767
61 #if __STDC_VERSION__ >= 202311L
62 typedef bool once_flag
;
63 #define ONCE_FLAG_INIT false
64 void call_once(once_flag
*flag
, void (*func
)(void));
67 /* Numeric conversion functions (ISO C11 7.22.1) */
68 extern float atof (const char *nptr
);
69 extern int atoi (const char *nptr
);
70 extern long int atol (const char *nptr
);
71 extern long int strtol(const char *nptr
, char **endptr
, int base
);
72 extern unsigned long int strtoul(const char *nptr
, char **endptr
, int base
);
73 #ifdef __SDCC_LONGLONG
74 extern long long int atoll (const char *nptr
);
75 extern long long int strtoll(const char *nptr
, char **endptr
, int base
);
76 extern unsigned long long int strtoull(const char *nptr
, char **endptr
, int base
);
80 extern void __uitoa(unsigned int, char *, unsigned char);
81 extern void __itoa(int, char *, unsigned char);
82 extern void __ultoa(unsigned long, char *, unsigned char);
83 extern void __ltoa(long, char *, unsigned char);
85 /* Pseudo-random sequence generation functions (ISO C11 7.22.2) */
87 void srand(unsigned int seed
);
89 /* Memory management functions (ISO C11 7.22.3) */
90 #if defined(__SDCC_mcs51) || defined(__SDCC_ds390) || defined(__SDCC_ds400)
91 void __xdata
*calloc (size_t nmemb
, size_t size
);
92 void __xdata
*malloc (size_t size
);
93 void __xdata
*realloc (void *ptr
, size_t size
);
95 void *calloc (size_t nmemb
, size_t size
);
96 void *malloc (size_t size
);
97 void *realloc (void *ptr
, size_t size
);
99 #if __STDC_VERSION__ >= 201112L
100 inline void *aligned_alloc(size_t alignment
, size_t size
)
106 extern void free (void * ptr
);
108 #if __STDC_VERSION__ >= 202311L
109 inline void free_sized(void *ptr
, size_t size
)
115 inline void free_aligned_sized(void *ptr
, size_t alignment
, size_t size
)
123 /* Searching and sorting utilities (ISO C11 7.22.5) */
124 extern void *bsearch(const void *key
, const void *base
, size_t nmemb
, size_t size
, int (*compar
)(const void *, const void *) __reentrant
);
125 extern void qsort(void *base
, size_t nmemb
, size_t size
, int (*compar
)(const void *, const void *) __reentrant
);
127 /* Integer arithmetic functions (ISO C11 7.22.6) */
128 #if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r2ka) || defined(__SDCC_r3ka) || defined(__SDCC_tlcs90) || defined (__SDCC_ez80_z80) || defined (__SDCC_z80n) || defined(__SDCC_r800)
129 int abs(int j
) __preserves_regs(b
, c
, iyl
, iyh
);
133 long int labs(long int j
);
134 #ifdef __SDCC_LONGLONG
135 long long int llabs(long long int j
);
153 #if !defined(__SDCC_ds390) && !defined(__SDCC_ds390) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) // struct return not yet supported
154 div_t div(int numer
, int denom
);
155 ldiv_t ldiv(long int numer
, long int denom
);
156 #if !defined(__SDCC_mos6502) && !defined(__SDCC_mos65c02) // size of struct return is limited to <= 8
157 lldiv_t
lldiv(long long int numer
, long long int denom
);
161 /* C99 Multibyte/wide character conversion functions (ISO C11 7.22.7) */
162 #if __STDC_VERSION__ >= 199901L
163 int mblen(const char *s
, size_t n
);
164 int mbtowc(wchar_t *restrict pwc
, const char *restrict s
, size_t n
);
165 int wctomb(char *s
, wchar_t wc
);
168 /* C99 Multibyte/wide string conversion functions (ISO C 11 7.22.8) */
169 #if __STDC_VERSION__ >= 199901L
170 size_t mbstowcs(wchar_t *restrict pwcs
, const char *restrict s
, size_t n
);
171 size_t wcstombs(char *restrict s
, const wchar_t *restrict pwcs
, size_t n
);
174 /* C2X Alignment of memory */
175 #if __STDC_VERSION__ >= 202311L
176 size_t memalignment(const void *p
);
179 /* Bounds-checking interfaces from annex K of the C11 standard. */
180 #if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__
182 #ifndef __RSIZE_T_DEFINED
183 #define __RSIZE_T_DEFINED
184 typedef size_t rsize_t
;
187 #ifndef __ERRNO_T_DEFINED
188 #define __ERRNO_T_DEFINED
192 typedef void (*constraint_handler_t
)(const char *restrict msg
, void *restrict ptr
, errno_t error
);