crtnone.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /*
  2. * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  4. */
  5. #include "bx_p.h"
  6. #include <bx/debug.h>
  7. #include <bx/math.h>
  8. #include <bx/sort.h>
  9. #include <bx/readerwriter.h>
  10. #if BX_CRT_NONE
  11. extern "C" void* memcpy(void* _dst, const void* _src, size_t _numBytes)
  12. {
  13. bx::memCopy(_dst, _src, _numBytes);
  14. return _dst;
  15. }
  16. extern "C" void* memmove(void* _dst, const void* _src, size_t _numBytes)
  17. {
  18. bx::memMove(_dst, _src, _numBytes);
  19. return _dst;
  20. }
  21. extern "C" void* memset(void* _dst, int _ch, size_t _numBytes)
  22. {
  23. bx::memSet(_dst, uint8_t(_ch), _numBytes);
  24. return _dst;
  25. }
  26. #if !BX_PLATFORM_NONE
  27. typedef int64_t off64_t;
  28. typedef int32_t pid_t;
  29. extern "C" int32_t memcmp(const void* _lhs, const void* _rhs, size_t _numBytes)
  30. {
  31. return bx::memCmp(_lhs, _rhs, _numBytes);
  32. }
  33. extern "C" size_t strlen(const char* _str)
  34. {
  35. return bx::strLen(_str);
  36. }
  37. extern "C" size_t strnlen(const char* _str, size_t _max)
  38. {
  39. return bx::strLen(_str, _max);
  40. }
  41. extern "C" void* strcpy(char* _dst, const char* _src)
  42. {
  43. bx::strCopy(_dst, INT32_MAX, _src, INT32_MAX);
  44. return _dst;
  45. }
  46. extern "C" void* strncpy(char* _dst, const char* _src, size_t _num)
  47. {
  48. bx::strCopy(_dst, INT32_MAX, _src, _num);
  49. return _dst;
  50. }
  51. extern "C" char* strcat(char* _dst, const char* _src)
  52. {
  53. bx::strCat(_dst, INT32_MAX, _src, INT32_MAX);
  54. return _dst;
  55. }
  56. extern "C" const char* strchr(const char* _str, int _ch)
  57. {
  58. return bx::strFind(_str, _ch);
  59. }
  60. extern "C" int32_t strcmp(const char* _lhs, const char* _rhs)
  61. {
  62. return bx::strCmp(_lhs, _rhs);
  63. }
  64. extern "C" int32_t strncmp(const char* _lhs, const char* _rhs, size_t _max)
  65. {
  66. return bx::strCmp(_lhs, _rhs, _max);
  67. }
  68. extern "C" const char* strstr(const char* _str, const char* _find)
  69. {
  70. return bx::strFind(_str, _find);
  71. }
  72. extern "C" void qsort(void* _base, size_t _num, size_t _size, bx::ComparisonFn _fn)
  73. {
  74. BX_CHECK(_num <= UINT32_MAX && _size <= UINT32_MAX, "");
  75. return bx::quickSort(_base, _num, _size, _fn);
  76. }
  77. extern "C" int isprint(int _ch)
  78. {
  79. return bx::isPrint(_ch);
  80. }
  81. extern "C" int toupper (int _ch)
  82. {
  83. return bx::toUpper(_ch);
  84. }
  85. extern "C" size_t mbstowcs(wchar_t* _dst, const char* _src, size_t _max)
  86. {
  87. BX_UNUSED(_dst, _src, _max);
  88. return 0;
  89. }
  90. extern "C" char* strdup(const char* _src)
  91. {
  92. BX_UNUSED(_src);
  93. return NULL;
  94. }
  95. extern "C" long int strtol(const char* _str, char** _end, int _base)
  96. {
  97. BX_UNUSED(_str, _end, _base);
  98. return -1;
  99. }
  100. extern "C" int abs(int _value)
  101. {
  102. return _value >= 0 ? _value : -_value;
  103. }
  104. extern "C" float fabsf(float _x)
  105. {
  106. return bx::abs(_x);
  107. }
  108. extern "C" double fabs(double _x)
  109. {
  110. return bx::abs(_x);
  111. }
  112. extern "C" double ldexp(double _x, int _exp)
  113. {
  114. return ldexp(float(_x), _exp);
  115. }
  116. extern "C" float expf(float _x)
  117. {
  118. return bx::exp(_x);
  119. }
  120. extern "C" float logf(float _x)
  121. {
  122. return bx::log(_x);
  123. }
  124. extern "C" float log10f(float _x)
  125. {
  126. BX_UNUSED(_x);
  127. return 0.0f;
  128. }
  129. extern "C" float powf(float _x, float _y)
  130. {
  131. return bx::pow(_x, _y);
  132. }
  133. extern "C" double pow(double _x, float _y)
  134. {
  135. return bx::pow(_x, _y);
  136. }
  137. extern "C" float sinf(float _x)
  138. {
  139. return bx::sin(_x);
  140. }
  141. extern "C" float cosf(float _x)
  142. {
  143. return bx::cos(_x);
  144. }
  145. extern "C" float tanf(float _x)
  146. {
  147. return bx::tan(_x);
  148. }
  149. extern "C" float atan2f(float _y, float _x)
  150. {
  151. return bx::atan2(_y, _x);
  152. }
  153. extern "C" float sqrtf(float _x)
  154. {
  155. return bx::sqrt(_x);
  156. }
  157. extern "C" double sqrt(double _x)
  158. {
  159. return bx::sqrt(_x);
  160. }
  161. extern "C" float ceilf(float _x)
  162. {
  163. return bx::ceil(_x);
  164. }
  165. extern "C" double ceil(double _x)
  166. {
  167. return bx::ceil(_x);
  168. }
  169. extern "C" float floorf(float _x)
  170. {
  171. return bx::floor(_x);
  172. }
  173. extern "C" double floor(double _x)
  174. {
  175. return bx::floor(_x);
  176. }
  177. extern "C" float acosf(float _x)
  178. {
  179. return bx::acos(_x);
  180. }
  181. extern "C" float fmodf(float _numer, float _denom)
  182. {
  183. return bx::mod(_numer, _denom);
  184. }
  185. extern "C" int atoi(const char* _str)
  186. {
  187. int32_t result = 0;
  188. bx::fromString(&result, _str);
  189. return result;
  190. }
  191. extern "C" double atof(const char* _str)
  192. {
  193. double result = 0.0;
  194. bx::fromString(&result, _str);
  195. return result;
  196. }
  197. extern "C" struct DIR* opendir(const char* _dirname)
  198. {
  199. BX_UNUSED(_dirname);
  200. return NULL;
  201. }
  202. extern "C" struct dirent* readdir(struct DIR* _dirp)
  203. {
  204. BX_UNUSED(_dirp);
  205. return NULL;
  206. }
  207. extern "C" int closedir(struct DIR* _dirp)
  208. {
  209. BX_UNUSED(_dirp);
  210. return 0;
  211. }
  212. extern "C" int vsnprintf(char* _out, size_t _max, const char* _format, va_list _argList)
  213. {
  214. return bx::vsnprintf(_out, _max, _format, _argList);
  215. }
  216. extern "C" int sprintf(char* _out, const char* _format, ...)
  217. {
  218. va_list argList;
  219. va_start(argList, _format);
  220. int32_t len = bx::vsnprintf(_out, INT32_MAX, _format, argList);
  221. va_end(argList);
  222. return len;
  223. }
  224. extern "C" int snprintf(char* _out, size_t _max, const char* _format, ...)
  225. {
  226. va_list argList;
  227. va_start(argList, _format);
  228. int32_t len = bx::vsnprintf(_out, _max, _format, argList);
  229. va_end(argList);
  230. return len;
  231. }
  232. extern "C" int printf(const char* _format, ...)
  233. {
  234. BX_UNUSED(_format);
  235. return -1;
  236. }
  237. struct FILE
  238. {
  239. };
  240. extern "C" int fprintf(FILE* _stream, const char* _format, ...)
  241. {
  242. BX_UNUSED(_stream, _format);
  243. return -1;
  244. }
  245. extern "C" int vfprintf(FILE* _stream, const char* _format, va_list _argList)
  246. {
  247. BX_UNUSED(_stream, _format, _argList);
  248. return -1;
  249. }
  250. extern "C" int sscanf(const char* _str, const char* _format, ...)
  251. {
  252. BX_UNUSED(_str, _format);
  253. return -1;
  254. }
  255. extern "C" int fscanf(FILE* _stream, const char* _format, ...)
  256. {
  257. BX_UNUSED(_stream, _format);
  258. return -1;
  259. }
  260. FILE * stdout;
  261. extern "C" FILE* fopen(const char* _filename, const char* _mode)
  262. {
  263. BX_UNUSED(_filename, _mode);
  264. return NULL;
  265. }
  266. extern "C" int fclose(FILE* _stream)
  267. {
  268. BX_UNUSED(_stream);
  269. return -1;
  270. }
  271. extern "C" size_t fread(void* _ptr, size_t _size, size_t _count, FILE* _stream)
  272. {
  273. BX_UNUSED(_ptr, _size, _count, _stream);
  274. return -1;
  275. }
  276. extern "C" size_t fwrite(const void* _ptr, size_t _size, size_t _count, FILE* _stream)
  277. {
  278. BX_UNUSED(_ptr, _size, _count, _stream);
  279. return -1;
  280. }
  281. extern "C" int fseek(FILE* _stream, long int _offset, int _origin)
  282. {
  283. BX_UNUSED(_stream, _offset, _origin);
  284. return -1;
  285. }
  286. extern "C" int fseeko64(FILE* _stream, off64_t _offset, int _whence)
  287. {
  288. BX_UNUSED(_stream, _offset, _whence);
  289. return -1;
  290. }
  291. extern "C" long int ftell(FILE* _stream)
  292. {
  293. BX_UNUSED(_stream);
  294. return -1;
  295. }
  296. extern "C" off64_t ftello64(FILE* _stream)
  297. {
  298. BX_UNUSED(_stream);
  299. return -1;
  300. }
  301. extern "C" int feof(FILE* _stream)
  302. {
  303. BX_UNUSED(_stream);
  304. return -1;
  305. }
  306. extern "C" int ferror(FILE* _stream)
  307. {
  308. BX_UNUSED(_stream);
  309. return -1;
  310. }
  311. extern "C" FILE* popen(const char* _command, const char* _type)
  312. {
  313. BX_UNUSED(_command, _type);
  314. return NULL;
  315. }
  316. extern "C" int pclose(FILE* _stream)
  317. {
  318. BX_UNUSED(_stream);
  319. return -1;
  320. }
  321. extern "C" int execvp(const char* _file, char* const _argv[])
  322. {
  323. BX_UNUSED(_file, _argv);
  324. return -1;
  325. }
  326. extern "C" long syscall(long _num, ...)
  327. {
  328. BX_UNUSED(_num);
  329. return -1;
  330. }
  331. extern "C" long sysconf(int name)
  332. {
  333. BX_UNUSED(name);
  334. return -1;
  335. }
  336. extern "C" pid_t fork()
  337. {
  338. return -1;
  339. }
  340. extern "C" int sched_yield()
  341. {
  342. return -1;
  343. }
  344. extern "C" int prctl(int _option, unsigned long _arg2, unsigned long _arg3, unsigned long _arg4, unsigned long _arg5)
  345. {
  346. BX_UNUSED(_option, _arg2, _arg3, _arg4, _arg5);
  347. return -1;
  348. }
  349. extern "C" int chdir(const char* _path)
  350. {
  351. BX_UNUSED(_path);
  352. return -1;
  353. }
  354. extern "C" char* getcwd(char* _buf, size_t _size)
  355. {
  356. BX_UNUSED(_buf, _size);
  357. return NULL;
  358. }
  359. extern "C" char* getenv(const char* _name)
  360. {
  361. BX_UNUSED(_name);
  362. return NULL;
  363. }
  364. extern "C" int setenv(const char* _name, const char* _value, int _overwrite)
  365. {
  366. BX_UNUSED(_name, _value, _overwrite);
  367. return -1;
  368. }
  369. extern "C" int unsetenv(const char* _name)
  370. {
  371. BX_UNUSED(_name);
  372. return -1;
  373. }
  374. extern "C" time_t time(time_t* _arg)
  375. {
  376. BX_UNUSED(_arg);
  377. return -1;
  378. }
  379. extern "C" int gettimeofday(struct timeval* _tv, struct timezone* _tz)
  380. {
  381. BX_UNUSED(_tv, _tz);
  382. return -1;
  383. }
  384. extern "C" void* realloc(void* _ptr, size_t _size)
  385. {
  386. BX_UNUSED(_ptr, _size);
  387. return NULL;
  388. }
  389. extern "C" void* malloc(size_t _size)
  390. {
  391. return ::realloc(NULL, _size);
  392. }
  393. extern "C" void free(void* _ptr)
  394. {
  395. BX_UNUSED(_ptr);
  396. }
  397. #endif // BX_PLATFORM_*
  398. extern "C" void abort()
  399. {
  400. while (true) {};
  401. }
  402. extern "C" void __assert_fail(const char* _assertion, const char* _file, uint32_t _line, const char* _function)
  403. {
  404. BX_UNUSED(_assertion, _file, _line, _function);
  405. abort();
  406. }
  407. void* __dso_handle = (void*)&__dso_handle;
  408. void operator delete(void*)
  409. {
  410. }
  411. extern "C" void __cxa_pure_virtual()
  412. {
  413. }
  414. extern "C" int __cxa_atexit(void (*_dtorFn)(void*), void* _arg, void* _dsoHandle)
  415. {
  416. BX_UNUSED(_dtorFn, _arg, _dsoHandle);
  417. return 0;
  418. }
  419. extern "C" void __gxx_personality_v0()
  420. {
  421. }
  422. extern "C" void _Unwind_Resume(void*)
  423. {
  424. }
  425. extern "C" int __gcc_personality_v0(int _version, ...)
  426. {
  427. BX_UNUSED(_version);
  428. return 0;
  429. }
  430. namespace __cxxabiv1
  431. {
  432. class __class_type_info
  433. {
  434. public:
  435. virtual ~__class_type_info();
  436. const char* m_name;
  437. };
  438. __class_type_info::~__class_type_info()
  439. {
  440. }
  441. class __si_class_type_info : public __class_type_info
  442. {
  443. public:
  444. virtual ~__si_class_type_info();
  445. };
  446. __si_class_type_info::~__si_class_type_info()
  447. {
  448. }
  449. class __vmi_class_type_info : public __class_type_info
  450. {
  451. public:
  452. virtual ~__vmi_class_type_info();
  453. };
  454. __vmi_class_type_info::~__vmi_class_type_info()
  455. {
  456. }
  457. __extension__ typedef int __guard __attribute__( (mode(__DI__) ) );
  458. extern "C" int __cxa_guard_acquire (__guard* _g)
  459. {
  460. return !*(char*)(_g);
  461. }
  462. extern "C" void __cxa_guard_release (__guard* _g)
  463. {
  464. *(char*)_g = 1;
  465. }
  466. extern "C" void __cxa_guard_abort (__guard* _g)
  467. {
  468. BX_UNUSED(_g);
  469. }
  470. } // namespace __cxxabiv1
  471. #endif // BX_CRT_NONE