1 2 // automatically generated by m4 from headers in proto subdir 3 4 5 #ifndef __STDLIB_H__ 6 #define __STDLIB_H__ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 // DATA STRUCTURES 12 13 #ifndef _SIZE_T_DEFINED 14 #define _SIZE_T_DEFINED 15 typedef unsigned int size_t; 16 #endif 17 18 #ifndef _WCHAR_T_DEFINED 19 #define _WCHAR_T_DEFINED 20 typedef unsigned char wchar_t; 21 #endif 22 23 #ifndef _FLOAT_T_DEFINED 24 #define _FLOAT_T_DEFINED 25 26 #ifdef __CLANG 27 28 typedef float float_t; 29 30 #endif 31 32 #ifdef __SDCC 33 34 typedef float float_t; 35 36 #endif 37 38 #ifdef __SCCZ80 39 40 typedef double float_t; 41 42 #endif 43 44 #endif 45 46 #ifndef _DOUBLE_T_DEFINED 47 #define _DOUBLE_T_DEFINED 48 49 #ifdef __CLANG 50 51 typedef float double_t; 52 53 #endif 54 55 #ifdef __SDCC 56 57 typedef float double_t; 58 59 #endif 60 61 #ifdef __SCCZ80 62 63 typedef double double_t; 64 65 #endif 66 67 #endif 68 69 typedef struct 70 { 71 72 int rem; 73 int quot; 74 75 } div_t; 76 77 typedef struct 78 { 79 80 unsigned int rem; 81 unsigned int quot; 82 83 } divu_t; 84 85 typedef struct 86 { 87 88 long quot; 89 long rem; 90 91 } ldiv_t; 92 93 typedef struct 94 { 95 96 unsigned long quot; 97 unsigned long rem; 98 99 } ldivu_t; 100 101 #ifdef __CLANG 102 103 typedef struct 104 { 105 long long rem; 106 long long quot; 107 108 } lldiv_t; 109 110 typedef struct 111 { 112 unsigned long long rem; 113 unsigned long long quot; 114 115 } lldivu_t; 116 117 #endif 118 119 #ifdef __SDCC 120 121 typedef struct 122 { 123 long long rem; 124 long long quot; 125 126 } lldiv_t; 127 128 typedef struct 129 { 130 unsigned long long rem; 131 unsigned long long quot; 132 133 } lldivu_t; 134 135 #endif 136 137 #ifndef NULL 138 #define NULL ((void*)(0)) 139 #endif 140 141 #define EXIT_FAILURE 0 142 #define EXIT_SUCCESS 1 143 144 #define RAND_MAX 32767 145 146 #define MB_CUR_MAX 1 147 148 #define FTOA_FLAG_PLUS 0x40 149 #define FTOA_FLAG_SPACE 0x20 150 #define FTOA_FLAG_HASH 0x10 151 152 #define DTOA_FLAG_PLUS 0x40 153 #define DTOA_FLAG_SPACE 0x20 154 #define DTOA_FLAG_HASH 0x10 155 156 // FUNCTIONS 157 158 extern void _div_(div_t *d,int numer,int denom); 159 extern void _div__callee(div_t *d,int numer,int denom) __z88dk_callee; 160 #define _div_(a,b,c) _div__callee(a,b,c) 161 162 163 extern void _divu_(divu_t *d,unsigned int numer,unsigned int denom); 164 extern void _divu__callee(divu_t *d,unsigned int numer,unsigned int denom) __z88dk_callee; 165 #define _divu_(a,b,c) _divu__callee(a,b,c) 166 167 168 extern void _ldiv_(ldiv_t *ld,long numer,long denom); 169 extern void _ldiv__callee(ldiv_t *ld,long numer,long denom) __z88dk_callee; 170 #define _ldiv_(a,b,c) _ldiv__callee(a,b,c) 171 172 173 extern void _ldivu_(ldivu_t *ld,unsigned long numer,unsigned long denom); 174 extern void _ldivu__callee(ldivu_t *ld,unsigned long numer,unsigned long denom) __z88dk_callee; 175 #define _ldivu_(a,b,c) _ldivu__callee(a,b,c) 176 177 178 extern void _insertion_sort_(void *base,size_t nmemb,size_t size,void *compar); 179 extern void _insertion_sort__callee(void *base,size_t nmemb,size_t size,void *compar) __z88dk_callee; 180 #define _insertion_sort_(a,b,c,d) _insertion_sort__callee(a,b,c,d) 181 182 183 extern void _quicksort_(void *base,size_t nmemb,size_t size,void *compar); 184 extern void _quicksort__callee(void *base,size_t nmemb,size_t size,void *compar) __z88dk_callee; 185 #define _quicksort_(a,b,c,d) _quicksort__callee(a,b,c,d) 186 187 188 extern void _shellsort_(void *base,size_t nmemb,size_t size,void *compar); 189 extern void _shellsort__callee(void *base,size_t nmemb,size_t size,void *compar) __z88dk_callee; 190 #define _shellsort_(a,b,c,d) _shellsort__callee(a,b,c,d) 191 192 193 extern uint16_t _random_uniform_cmwc_8_(void *seed); 194 extern uint16_t _random_uniform_cmwc_8__fastcall(void *seed) __z88dk_fastcall; 195 #define _random_uniform_cmwc_8_(a) _random_uniform_cmwc_8__fastcall(a) 196 197 198 extern uint32_t _random_uniform_xor_32_(uint32_t *seed); 199 extern uint32_t _random_uniform_xor_32__fastcall(uint32_t *seed) __z88dk_fastcall; 200 #define _random_uniform_xor_32_(a) _random_uniform_xor_32__fastcall(a) 201 202 203 extern uint16_t _random_uniform_xor_8_(uint32_t *seed); 204 extern uint16_t _random_uniform_xor_8__fastcall(uint32_t *seed) __z88dk_fastcall; 205 #define _random_uniform_xor_8_(a) _random_uniform_xor_8__fastcall(a) 206 207 208 extern int _strtoi_(char *nptr,char **endptr,int base); 209 extern int _strtoi__callee(char *nptr,char **endptr,int base) __z88dk_callee; 210 #define _strtoi_(a,b,c) _strtoi__callee(a,b,c) 211 212 213 extern uint16_t _strtou_(char *nptr,char **endptr,int base); 214 extern uint16_t _strtou__callee(char *nptr,char **endptr,int base) __z88dk_callee; 215 #define _strtou_(a,b,c) _strtou__callee(a,b,c) 216 217 218 extern void abort(void) __preserves_regs(a,b,c,d,e,h,l); 219 220 extern int abs(int j) __preserves_regs(b,c,d,e); 221 extern int abs_fastcall(int j) __preserves_regs(b,c,d,e) __z88dk_fastcall; 222 #define abs(a) abs_fastcall(a) 223 224 225 extern int at_quick_exit(void *func); 226 extern int at_quick_exit_fastcall(void *func) __z88dk_fastcall; 227 #define at_quick_exit(a) at_quick_exit_fastcall(a) 228 229 230 extern int atexit(void *func); 231 extern int atexit_fastcall(void *func) __z88dk_fastcall; 232 #define atexit(a) atexit_fastcall(a) 233 234 235 extern double_t atof(char *nptr); 236 extern double_t atof_fastcall(char *nptr) __z88dk_fastcall; 237 #define atof(a) atof_fastcall(a) 238 239 240 extern int atoi(char *buf); 241 extern int atoi_fastcall(char *buf) __z88dk_fastcall; 242 #define atoi(a) atoi_fastcall(a) 243 244 245 extern long atol(char *buf); 246 extern long atol_fastcall(char *buf) __z88dk_fastcall; 247 #define atol(a) atol_fastcall(a) 248 249 250 extern void *bsearch(void *key,void *base,size_t nmemb,size_t size,void *compar); 251 extern void *bsearch_callee(void *key,void *base,size_t nmemb,size_t size,void *compar) __z88dk_callee; 252 #define bsearch(a,b,c,d,e) bsearch_callee(a,b,c,d,e) 253 254 255 extern size_t dtoa(double_t x,void *buf,uint16_t prec,uint16_t flags); 256 extern size_t dtoa_callee(double_t x,void *buf,uint16_t prec,uint16_t flags) __z88dk_callee; 257 #define dtoa(a,b,c,d) dtoa_callee(a,b,c,d) 258 259 260 extern size_t dtoe(double_t x,void *buf,uint16_t prec,uint16_t flags); 261 extern size_t dtoe_callee(double_t x,void *buf,uint16_t prec,uint16_t flags) __z88dk_callee; 262 #define dtoe(a,b,c,d) dtoe_callee(a,b,c,d) 263 264 265 extern size_t dtog(double_t x,void *buf,uint16_t prec,uint16_t flags); 266 extern size_t dtog_callee(double_t x,void *buf,uint16_t prec,uint16_t flags) __z88dk_callee; 267 #define dtog(a,b,c,d) dtog_callee(a,b,c,d) 268 269 270 extern size_t dtoh(double_t x,void *buf,uint16_t prec,uint16_t flags); 271 extern size_t dtoh_callee(double_t x,void *buf,uint16_t prec,uint16_t flags) __z88dk_callee; 272 #define dtoh(a,b,c,d) dtoh_callee(a,b,c,d) 273 274 275 extern void exit(int status) __preserves_regs(a,b,c,d,e,h,l); 276 extern void exit_fastcall(int status) __preserves_regs(a,b,c,d,e,h,l) __z88dk_fastcall; 277 #define exit(a) exit_fastcall(a) 278 279 280 extern size_t ftoa(float_t x,void *buf,uint16_t prec,uint16_t flags); 281 extern size_t ftoa_callee(float_t x,void *buf,uint16_t prec,uint16_t flags) __z88dk_callee; 282 #define ftoa(a,b,c,d) ftoa_callee(a,b,c,d) 283 284 285 extern size_t ftoe(float_t x,void *buf,uint16_t prec,uint16_t flags); 286 extern size_t ftoe_callee(float_t x,void *buf,uint16_t prec,uint16_t flags) __z88dk_callee; 287 #define ftoe(a,b,c,d) ftoe_callee(a,b,c,d) 288 289 290 extern size_t ftog(float_t x,void *buf,uint16_t prec,uint16_t flags); 291 extern size_t ftog_callee(float_t x,void *buf,uint16_t prec,uint16_t flags) __z88dk_callee; 292 #define ftog(a,b,c,d) ftog_callee(a,b,c,d) 293 294 295 extern size_t ftoh(float_t x,void *buf,uint16_t prec,uint16_t flags); 296 extern size_t ftoh_callee(float_t x,void *buf,uint16_t prec,uint16_t flags) __z88dk_callee; 297 #define ftoh(a,b,c,d) ftoh_callee(a,b,c,d) 298 299 300 extern char *itoa(int num,char *buf,int radix); 301 extern char *itoa_callee(int num,char *buf,int radix) __z88dk_callee; 302 #define itoa(a,b,c) itoa_callee(a,b,c) 303 304 305 extern long labs(long j) __preserves_regs(b,c); 306 extern long labs_fastcall(long j) __preserves_regs(b,c) __z88dk_fastcall; 307 #define labs(a) labs_fastcall(a) 308 309 310 extern char *ltoa(long num,char *buf,int radix); 311 extern char *ltoa_callee(long num,char *buf,int radix) __z88dk_callee; 312 #define ltoa(a,b,c) ltoa_callee(a,b,c) 313 314 315 extern void qsort(void *base,size_t nmemb,size_t size,void *compar); 316 extern void qsort_callee(void *base,size_t nmemb,size_t size,void *compar) __z88dk_callee; 317 #define qsort(a,b,c,d) qsort_callee(a,b,c,d) 318 319 320 extern void quick_exit(int status) __preserves_regs(a,b,c,d,e,h,l); 321 extern void quick_exit_fastcall(int status) __preserves_regs(a,b,c,d,e,h,l) __z88dk_fastcall; 322 #define quick_exit(a) quick_exit_fastcall(a) 323 324 325 extern int rand(void); 326 327 extern void srand(uint16_t seed) __preserves_regs(b,c,d,e); 328 extern void srand_fastcall(uint16_t seed) __preserves_regs(b,c,d,e,h,l) __z88dk_fastcall; 329 #define srand(a) srand_fastcall(a) 330 331 332 extern double_t strtod(char *nptr,char **endptr); 333 extern double_t strtod_callee(char *nptr,char **endptr) __z88dk_callee; 334 #define strtod(a,b) strtod_callee(a,b) 335 336 337 extern float_t strtof(char *nptr,char **endptr); 338 extern float_t strtof_callee(char *nptr,char **endptr) __z88dk_callee; 339 #define strtof(a,b) strtof_callee(a,b) 340 341 342 extern long strtol(char *nptr,char **endptr,int base); 343 extern long strtol_callee(char *nptr,char **endptr,int base) __z88dk_callee; 344 #define strtol(a,b,c) strtol_callee(a,b,c) 345 346 347 extern uint32_t strtoul(char *nptr,char **endptr,int base); 348 extern uint32_t strtoul_callee(char *nptr,char **endptr,int base) __z88dk_callee; 349 #define strtoul(a,b,c) strtoul_callee(a,b,c) 350 351 352 extern int system(char *s); 353 extern int system_fastcall(char *s) __z88dk_fastcall; 354 #define system(a) system_fastcall(a) 355 356 357 extern char *ultoa(uint32_t num,char *buf,int radix); 358 extern char *ultoa_callee(uint32_t num,char *buf,int radix) __z88dk_callee; 359 #define ultoa(a,b,c) ultoa_callee(a,b,c) 360 361 362 extern char *utoa(uint16_t num,char *buf,int radix); 363 extern char *utoa_callee(uint16_t num,char *buf,int radix) __z88dk_callee; 364 #define utoa(a,b,c) utoa_callee(a,b,c) 365 366 367 368 #ifndef _ALLOC_MALLOC_H 369 370 extern void *aligned_alloc(size_t alignment,size_t size); 371 extern void *aligned_alloc_callee(size_t alignment,size_t size) __z88dk_callee; 372 #define aligned_alloc(a,b) aligned_alloc_callee(a,b) 373 374 375 extern void *calloc(size_t nmemb,size_t size); 376 extern void *calloc_callee(size_t nmemb,size_t size) __z88dk_callee; 377 #define calloc(a,b) calloc_callee(a,b) 378 379 380 extern void free(void *p) __preserves_regs(b,c); 381 extern void free_fastcall(void *p) __preserves_regs(b,c) __z88dk_fastcall; 382 #define free(a) free_fastcall(a) 383 384 385 extern void *malloc(size_t size); 386 extern void *malloc_fastcall(size_t size) __z88dk_fastcall; 387 #define malloc(a) malloc_fastcall(a) 388 389 390 extern void *realloc(void *p,size_t size); 391 extern void *realloc_callee(void *p,size_t size) __z88dk_callee; 392 #define realloc(a,b) realloc_callee(a,b) 393 394 395 396 extern void *aligned_alloc_unlocked(size_t alignment,size_t size); 397 extern void *aligned_alloc_unlocked_callee(size_t alignment,size_t size) __z88dk_callee; 398 #define aligned_alloc_unlocked(a,b) aligned_alloc_unlocked_callee(a,b) 399 400 401 extern void *calloc_unlocked(size_t nmemb,size_t size); 402 extern void *calloc_unlocked_callee(size_t nmemb,size_t size) __z88dk_callee; 403 #define calloc_unlocked(a,b) calloc_unlocked_callee(a,b) 404 405 406 extern void free_unlocked(void *p) __preserves_regs(b,c); 407 extern void free_unlocked_fastcall(void *p) __preserves_regs(b,c) __z88dk_fastcall; 408 #define free_unlocked(a) free_unlocked_fastcall(a) 409 410 411 extern void *malloc_unlocked(size_t size); 412 extern void *malloc_unlocked_fastcall(size_t size) __z88dk_fastcall; 413 #define malloc_unlocked(a) malloc_unlocked_fastcall(a) 414 415 416 extern void *realloc_unlocked(void *p,size_t size); 417 extern void *realloc_unlocked_callee(void *p,size_t size) __z88dk_callee; 418 #define realloc_unlocked(a,b) realloc_unlocked_callee(a,b) 419 420 421 422 #endif 423 424 #ifdef __CLANG 425 426 extern long long atoll(char *buf); 427 extern void _lldiv_(lldiv_t *ld,long long numer,long long denom); 428 extern void _lldivu_(lldivu_t *ld,unsigned long long numer,unsigned long long denom); 429 extern long long llabs(long long i); 430 extern char *lltoa(long long num,char *buf,int radix); 431 extern long long strtoll(char *nptr,char **endptr,int base); 432 extern unsigned long long strtoull(char *nptr,char **endptr,int base); 433 extern char *ulltoa(unsigned long long num,char *buf,int radix); 434 435 #endif 436 437 #ifdef __SDCC 438 439 extern long long atoll(char *buf); 440 extern long long atoll_callee(char *buf) __z88dk_callee; 441 #define atoll(a) atoll_callee(a) 442 443 extern void _lldiv_(lldiv_t *ld,long long numer,long long denom); 444 extern void _lldiv__callee(lldiv_t *ld,long long numer,long long denom) __z88dk_callee; 445 #define _lldiv_(a,b,c) _lldiv__callee(a,b,c) 446 447 448 extern void _lldivu_(lldivu_t *ld,unsigned long long numer,unsigned long long denom); 449 extern void _lldivu__callee(lldivu_t *ld,unsigned long long numer,unsigned long long denom) __z88dk_callee; 450 #define _lldivu_(a,b,c) _lldivu__callee(a,b,c) 451 452 453 454 extern long long llabs(long long i); 455 extern long long llabs_callee(long long i) __z88dk_callee; 456 #define llabs(a) llabs_callee(a) 457 458 extern char *lltoa(long long num,char *buf,int radix); 459 extern char *lltoa_callee(long long num,char *buf,int radix) __z88dk_callee; 460 #define lltoa(a,b,c) lltoa_callee(a,b,c) 461 462 463 extern long long strtoll(char *nptr,char **endptr,int base); 464 extern long long strtoll_callee(char *nptr,char **endptr,int base) __z88dk_callee; 465 #define strtoll(a,b,c) strtoll_callee(a,b,c) 466 467 468 extern unsigned long long strtoull(char *nptr,char **endptr,int base); 469 extern unsigned long long strtoull_callee(char *nptr,char **endptr,int base) __z88dk_callee; 470 #define strtoull(a,b,c) strtoull_callee(a,b,c) 471 472 473 extern char *ulltoa(unsigned long long num,char *buf,int radix); 474 extern char *ulltoa_callee(unsigned long long num,char *buf,int radix) __z88dk_callee; 475 #define ulltoa(a,b,c) ulltoa_callee(a,b,c) 476 477 478 479 #endif 480 481 #ifdef __ZXNEXT 482 483 extern unsigned char mkstemp_ex(char *template); 484 extern unsigned char mkstemp_ex_fastcall(char *template) __z88dk_fastcall; 485 #define mkstemp_ex(a) mkstemp_ex_fastcall(a) 486 487 488 489 extern char *getenv(const char *name); 490 extern char *getenv_fastcall(const char *name) __z88dk_fastcall; 491 #define getenv(a) getenv_fastcall(a) 492 493 494 extern char *getenv_ex(const char *filename,const char *name); 495 extern char *getenv_ex_callee(const char *filename,const char *name) __z88dk_callee; 496 #define getenv_ex(a,b) getenv_ex_callee(a,b) 497 498 499 extern char *env_getenv(unsigned char handle,const char *name,char *val,unsigned int valsz,void *buf,unsigned int bufsz); 500 extern char *env_getenv_callee(unsigned char handle,const char *name,char *val,unsigned int valsz,void *buf,unsigned int bufsz) __z88dk_callee; 501 #define env_getenv(a,b,c,d,e,f) env_getenv_callee(a,b,c,d,e,f) 502 503 504 505 #endif 506 507 #endif 508