stdlib.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef __STDLIB
  2. #define __STDLIB
  3. #include <default.h>
  4. #ifndef DOORS
  5. #define ldiv(n,d) ({ldiv_t __r;long __n=(n),__d=(d);asm("move.l 0xC8,%%a5;move.l %2,%%d1;move.l %3,%%d0;move.l (%%a5,2720),%%a0;jsr (%%a0);move.l %%d1,%0;move.l %2,%%d1;move.l %3,%%d0;move.l (%%a5,2724),%%a0;jsr (%%a0);move.l %%d1,%1" : "=&g"(__r.quot),"=g"(__r.rem) : "g"(__n),"g"(__d) : "a0","a1","a5","d0","d1","d2");__r;})
  6. #else
  7. #define ldiv(n,d) ({ldiv_t __r;long __n=(n),__d=(d);asm("move.l %2,%%d1;move.l %3,%%d0;jsr _ROM_CALL_2A8;move.l %%d1,%0;move.l %2,%%d1;move.l %3,%%d0;jsr _ROM_CALL_2A9;move.l %%d1,%1" : "=&g"(__r.quot),"=g"(__r.rem) : "g"(__n),"g"(__d) : "a0","a1","d0","d1","d2");__r;})
  8. #endif
  9. #ifndef NO_EXIT_SUPPORT
  10. extern void __exit(void)__ATTR_LIB_ASM_NORETURN__;
  11. #endif
  12. extern long __randseed;
  13. /* Begin Auto-Generated Part */
  14. #define NULL ((void*)0)
  15. #define RAND_MAX 32767
  16. #ifndef __HAVE_size_t
  17. #define __HAVE_size_t
  18. typedef unsigned long size_t;
  19. #endif
  20. typedef CALLBACK void(*atexit_t)(void);
  21. typedef CALLBACK short(*compare_t)(const void*elem1,const void*elem2);
  22. #ifndef __HAVE_div_t
  23. #define __HAVE_div_t
  24. typedef struct{short quot,rem;}div_t;
  25. #endif
  26. #ifndef __HAVE_ldiv_t
  27. #define __HAVE_ldiv_t
  28. typedef struct{long quot,rem;}ldiv_t;
  29. #endif
  30. #define abort() (_rom_call(void,(const char*),E6)("ABNORMAL PROGRAM TERMINATION"),exit(0))
  31. #define abs(x) ({typeof(x) __x = (x); __x >= 0 ? __x : -__x;})
  32. #ifndef __HAVE_alloca
  33. #define __HAVE_alloca
  34. void *alloca(long)__ATTR_GCC__;
  35. #endif
  36. extern short atexit(atexit_t)__ATTR_LIB_ASM__;
  37. extern short atoi(const char*)__ATTR_LIB_C__;
  38. extern long atol(const char*)__ATTR_LIB_C__;
  39. extern void *bsearch(const void* asm("a0"),const void* asm("a1"),short asm("d0"),short asm("d1"),compare_t asm("a2"))__ATTR_LIB_ASM__;
  40. #ifndef __HAVE_calloc
  41. #define __HAVE_calloc
  42. extern void *calloc(short asm("d0"),short asm("d1"))__ATTR_LIB_ASM__;
  43. #endif
  44. #define div(n,d) ({short __n=(n),__d=(d);div_t __r;__r.quot=__n/__d;__r.rem=__n%__d;__r;})
  45. #define exit(n) ({(n)?_rom_call(void,(short),152)(n):0;__exit();})
  46. #define fabs(x) _tios_float_1(106,x,float)
  47. #define free _rom_call(void,(void*),A3)
  48. #ifndef __HAVE_labs
  49. #define __HAVE_labs
  50. long labs(long)__ATTR_GCC__;
  51. #endif
  52. #define malloc _rom_call(void*,(long),A2)
  53. #define max(a,b) ({typeof(a) __a = (a); typeof(b) __b = (b); (__a > __b) ? __a : __b;})
  54. #define min(a,b) ({typeof(a) __a = (a); typeof(b) __b = (b); (__a < __b) ? __a : __b;})
  55. extern void qsort(void* asm("a0"),short asm("d0"),short asm("d1"),compare_t asm("a2"))__ATTR_LIB_ASM__;
  56. extern short rand(void)__ATTR_LIB_ASM__;
  57. #define random(x) ((short)((long)(unsigned short)rand()*(unsigned short)(x)/32768))
  58. #define randomize() srand(*(volatile unsigned char*)0x600017)
  59. #ifndef __HAVE_realloc
  60. #define __HAVE_realloc
  61. extern void *realloc(void* asm("a0"),long asm("d0"))__ATTR_LIB_ASM__;
  62. #endif
  63. #define srand(x) (__randseed=(x))
  64. extern long strtol(const char*,char**,short)__ATTR_LIB_C__;
  65. extern unsigned long strtoul(const char*,char**,short)__ATTR_LIB_C__;
  66. #if MIN_AMS>=101
  67. #ifndef __HAVE_atof
  68. #define __HAVE_atof
  69. extern float atof(const char*)__ATTR_LIB_ASM__;
  70. #endif
  71. #endif
  72. /* End Auto-Generated Part */
  73. #endif