crtnone.cpp 9.5 KB

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