stdlib.h 3.0 KB

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