From 5518cc58d3cd6307fa8a1d00db438a16a79ce63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 26 Apr 2018 21:27:23 -0700 Subject: [PATCH] Cleanup. --- src/crtnone.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/crtnone.cpp b/src/crtnone.cpp index f84f257..388dd25 100644 --- a/src/crtnone.cpp +++ b/src/crtnone.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #if BX_CRT_NONE @@ -87,6 +88,11 @@ extern "C" int32_t strncmp(const char* _lhs, const char* _rhs, size_t _max) return bx::strCmp(_lhs, _rhs, _max); } +extern "C" int32_t strcasecmp(const char* _lhs, const char* _rhs) +{ + return bx::strCmpI(_lhs, _rhs); +} + extern "C" const char* strstr(const char* _str, const char* _find) { return bx::strFind(_str, _find); @@ -335,7 +341,7 @@ extern "C" FILE* fopen(const char* _filename, const char* _mode) { BX_UNUSED(_filename, _mode); bx::debugPrintf("fopen(\"%s\", \"%s\");\n", _filename, _mode); - NOT_IMPLEMENTED(); +// NOT_IMPLEMENTED(); return NULL; } @@ -427,7 +433,7 @@ extern "C" long syscall(long _num, ...) { BX_UNUSED(_num); bx::debugPrintf("syscall %d\n", _num); - NOT_IMPLEMENTED(); +// NOT_IMPLEMENTED(); return -1; } @@ -475,7 +481,7 @@ extern "C" char* getenv(const char* _name) { BX_UNUSED(_name); bx::debugPrintf("getenv(%s) not implemented!\n", _name); - return (char*)""; + return NULL; } extern "C" int setenv(const char* _name, const char* _value, int _overwrite) @@ -501,11 +507,51 @@ extern "C" time_t time(time_t* _arg) return -1; } +#if 0 +struct timeval +{ + time_t tv_sec; + suseconds_t tv_usec; +}; + +struct timespec +{ + time_t tv_sec; + long tv_nsec; +}; +#endif // + +typedef int32_t clockid_t; + +inline void toTimespecNs(timespec& _ts, int64_t _nsecs) +{ + _ts.tv_sec = _nsecs/INT64_C(1000000000); + _ts.tv_nsec = _nsecs%INT64_C(1000000000); +} + +extern "C" int clock_gettime(clockid_t _clock, struct timespec* _ts) +{ + BX_UNUSED(_clock); + int64_t now = bx::getHPCounter(); + toTimespecNs(*_ts, now); + return 0; +} + extern "C" int gettimeofday(struct timeval* _tv, struct timezone* _tz) { - BX_UNUSED(_tv, _tz); - NOT_IMPLEMENTED(); - return -1; + BX_UNUSED(_tz); + + timespec ts; + + if (NULL == _tv) + { + return 0; + } + + clock_gettime(0 /*CLOCK_REALTIME*/, &ts); + _tv->tv_sec = ts.tv_sec; + _tv->tv_usec = (int)ts.tv_nsec / 1000; + return 0; } extern "C" void* realloc(void* _ptr, size_t _size)