From deb89436bc8ae0d3576206265c31d4a83b960794 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Mon, 19 Jan 2026 14:06:44 +0200 Subject: [PATCH] [STDC++COMPAT] Add rand_s for GCC 13 and pre-NT6 builds GCC 13 STL requires this. --- sdk/lib/gcc-compat/CMakeLists.txt | 5 +++++ sdk/lib/gcc-compat/rand_s.c | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 sdk/lib/gcc-compat/rand_s.c diff --git a/sdk/lib/gcc-compat/CMakeLists.txt b/sdk/lib/gcc-compat/CMakeLists.txt index 6e2b269f802..f2cbe46038d 100644 --- a/sdk/lib/gcc-compat/CMakeLists.txt +++ b/sdk/lib/gcc-compat/CMakeLists.txt @@ -7,6 +7,11 @@ list(APPEND SOURCE __throw_out_of_range_fmt.cpp StringCchCopyNA.c) +if(DLL_EXPORT_VERSION LESS 0x600) + list(APPEND SOURCE + rand_s.c) +endif() + add_library(stdc++compat ${SOURCE}) set_target_cpp_properties(stdc++compat WITH_EXCEPTIONS) add_dependencies(stdc++compat xdk) diff --git a/sdk/lib/gcc-compat/rand_s.c b/sdk/lib/gcc-compat/rand_s.c new file mode 100644 index 00000000000..64fa176713b --- /dev/null +++ b/sdk/lib/gcc-compat/rand_s.c @@ -0,0 +1,23 @@ +/* + * PROJECT: GCC C++ support library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Workaround for missing rand_s on pre-NT6 builds + * COPYRIGHT: Copyright 2026 Timo Kreuzer + */ + +#include + +errno_t __cdecl rand_s(_Out_ unsigned int *RandomValue) +{ + if (!RandomValue) + return EINVAL; + + *RandomValue = rand(); + return 0; +} + +#ifdef _M_IX86 +void* _imp__rand_s = rand_s; +#else +void* __imp_rand_s = rand_s; +#endif