crtnone.cpp 9.5 KB

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