diff options
Diffstat (limited to '3rdparty/bx/src/os.cpp')
-rw-r--r-- | 3rdparty/bx/src/os.cpp | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/3rdparty/bx/src/os.cpp b/3rdparty/bx/src/os.cpp index 0e925bb2f90..99394579b72 100644 --- a/3rdparty/bx/src/os.cpp +++ b/3rdparty/bx/src/os.cpp @@ -1,9 +1,8 @@ /* - * Copyright 2010-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + * Copyright 2010-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx/blob/master/LICENSE */ -#include "bx_p.h" #include <bx/string.h> #include <bx/os.h> #include <bx/uint32_t.h> @@ -15,25 +14,28 @@ #endif // BX_CRT_MSVC #if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif // WIN32_LEAN_AND_MEAN # include <windows.h> # include <psapi.h> #elif BX_PLATFORM_ANDROID \ - || BX_PLATFORM_EMSCRIPTEN \ || BX_PLATFORM_BSD \ + || BX_PLATFORM_EMSCRIPTEN \ + || BX_PLATFORM_HAIKU \ || BX_PLATFORM_HURD \ || BX_PLATFORM_IOS \ || BX_PLATFORM_LINUX \ + || BX_PLATFORM_NX \ || BX_PLATFORM_OSX \ || BX_PLATFORM_PS4 \ - || BX_PLATFORM_RPI \ - || BX_PLATFORM_STEAMLINK \ - || BX_PLATFORM_NX + || BX_PLATFORM_RPI # include <sched.h> // sched_yield -# if BX_PLATFORM_BSD \ - || BX_PLATFORM_IOS \ - || BX_PLATFORM_OSX \ - || BX_PLATFORM_PS4 \ - || BX_PLATFORM_STEAMLINK +# if BX_PLATFORM_BSD \ + || BX_PLATFORM_HAIKU \ + || BX_PLATFORM_IOS \ + || BX_PLATFORM_OSX \ + || BX_PLATFORM_PS4 # include <pthread.h> // mach_port_t # endif // BX_PLATFORM_* @@ -45,11 +47,13 @@ # if BX_PLATFORM_ANDROID # include <malloc.h> // mallinfo # elif BX_PLATFORM_LINUX \ - || BX_PLATFORM_RPI \ - || BX_PLATFORM_STEAMLINK + || BX_PLATFORM_RPI # include <stdio.h> // fopen # include <unistd.h> // syscall # include <sys/syscall.h> +# elif BX_PLATFORM_HAIKU +# include <stdio.h> // fopen +# include <unistd.h> // syscall # elif BX_PLATFORM_OSX # include <mach/mach.h> // mach_task_basic_info # elif BX_PLATFORM_HURD @@ -62,7 +66,6 @@ namespace bx { - void sleep(uint32_t _ms) { #if BX_PLATFORM_WINDOWS @@ -97,8 +100,7 @@ namespace bx #if BX_PLATFORM_WINDOWS return ::GetCurrentThreadId(); #elif BX_PLATFORM_LINUX \ - || BX_PLATFORM_RPI \ - || BX_PLATFORM_STEAMLINK + || BX_PLATFORM_RPI return (pid_t)::syscall(SYS_gettid); #elif BX_PLATFORM_IOS \ || BX_PLATFORM_OSX @@ -174,7 +176,7 @@ namespace bx void* dlopen(const FilePath& _filePath) { #if BX_PLATFORM_WINDOWS - return (void*)::LoadLibraryA(_filePath.get() ); + return (void*)::LoadLibraryA(_filePath.getCPtr() ); #elif BX_PLATFORM_EMSCRIPTEN \ || BX_PLATFORM_PS4 \ || BX_PLATFORM_XBOXONE \ @@ -183,12 +185,19 @@ namespace bx BX_UNUSED(_filePath); return NULL; #else - return ::dlopen(_filePath.get(), RTLD_LOCAL|RTLD_LAZY); + void* so = ::dlopen(_filePath.getCPtr(), RTLD_LOCAL|RTLD_LAZY); + BX_WARN(NULL != so, "dlopen failed: \"%s\".", ::dlerror() ); + return so; #endif // BX_PLATFORM_ } void dlclose(void* _handle) { + if (NULL == _handle) + { + return; + } + #if BX_PLATFORM_WINDOWS ::FreeLibrary( (HMODULE)_handle); #elif BX_PLATFORM_EMSCRIPTEN \ @@ -206,7 +215,7 @@ namespace bx { const int32_t symbolMax = _symbol.getLength()+1; char* symbol = (char*)alloca(symbolMax); - bx::strCopy(symbol, symbolMax, _symbol); + strCopy(symbol, symbolMax, _symbol); #if BX_PLATFORM_WINDOWS return (void*)::GetProcAddress( (HMODULE)_handle, symbol); @@ -226,16 +235,17 @@ namespace bx { const int32_t nameMax = _name.getLength()+1; char* name = (char*)alloca(nameMax); - bx::strCopy(name, nameMax, _name); + strCopy(name, nameMax, _name); #if BX_PLATFORM_WINDOWS DWORD len = ::GetEnvironmentVariableA(name, _out, *_inOutSize); bool result = len != 0 && len < *_inOutSize; *_inOutSize = len; return result; -#elif BX_PLATFORM_PS4 \ - || BX_PLATFORM_XBOXONE \ - || BX_PLATFORM_WINRT \ +#elif BX_PLATFORM_EMSCRIPTEN \ + || BX_PLATFORM_PS4 \ + || BX_PLATFORM_XBOXONE \ + || BX_PLATFORM_WINRT \ || BX_CRT_NONE BX_UNUSED(name, _out, _inOutSize); return false; @@ -263,21 +273,22 @@ namespace bx { const int32_t nameMax = _name.getLength()+1; char* name = (char*)alloca(nameMax); - bx::strCopy(name, nameMax, _name); + strCopy(name, nameMax, _name); char* value = NULL; if (!_value.isEmpty() ) { int32_t valueMax = _value.getLength()+1; value = (char*)alloca(valueMax); - bx::strCopy(value, valueMax, _value); + strCopy(value, valueMax, _value); } #if BX_PLATFORM_WINDOWS ::SetEnvironmentVariableA(name, value); -#elif BX_PLATFORM_PS4 \ - || BX_PLATFORM_XBOXONE \ - || BX_PLATFORM_WINRT \ +#elif BX_PLATFORM_EMSCRIPTEN \ + || BX_PLATFORM_PS4 \ + || BX_PLATFORM_XBOXONE \ + || BX_PLATFORM_WINRT \ || BX_CRT_NONE BX_UNUSED(name, value); #else @@ -339,7 +350,7 @@ namespace bx int32_t len = 0; for(uint32_t ii = 0; NULL != _argv[ii]; ++ii) { - len += snprintf(&temp[len], bx::uint32_imax(0, total-len) + len += snprintf(&temp[len], uint32_imax(0, total-len) , "%s " , _argv[ii] ); @@ -368,4 +379,9 @@ namespace bx #endif // BX_PLATFORM_LINUX || BX_PLATFORM_HURD } + void exit(int32_t _exitCode) + { + ::exit(_exitCode); + } + } // namespace bx |