mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 19:12:57 +00:00
[CRT] Move rand_s into it's own file
This commit is contained in:
parent
0ea48e79fc
commit
f319538d98
4 changed files with 72 additions and 45 deletions
|
@ -11,6 +11,13 @@ list(APPEND MSVCRTEX_SOURCE
|
||||||
misc/ofmt_stub.c
|
misc/ofmt_stub.c
|
||||||
stdio/acrt_iob_func.c)
|
stdio/acrt_iob_func.c)
|
||||||
|
|
||||||
|
if(DLL_EXPORT_VERSION LESS 0x600)
|
||||||
|
list(APPEND MSVCRTEX_SOURCE
|
||||||
|
stdlib/_invalid_parameter.c
|
||||||
|
stdlib/rand_s.c
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||||
# Clang performs some optimizations requiring those funtions
|
# Clang performs some optimizations requiring those funtions
|
||||||
list(APPEND MSVCRTEX_SOURCE
|
list(APPEND MSVCRTEX_SOURCE
|
||||||
|
|
|
@ -26,48 +26,3 @@ srand(unsigned int seed)
|
||||||
thread_data_t *data = msvcrt_get_thread_data();
|
thread_data_t *data = msvcrt_get_thread_data();
|
||||||
data->random_seed = seed;
|
data->random_seed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
|
||||||
* rand_s (MSVCRT.@)
|
|
||||||
*/
|
|
||||||
int CDECL rand_s(unsigned int *pval)
|
|
||||||
{
|
|
||||||
BOOLEAN (WINAPI *pSystemFunction036)(PVOID, ULONG); // RtlGenRandom
|
|
||||||
HINSTANCE hadvapi32;
|
|
||||||
|
|
||||||
if (!pval)
|
|
||||||
{
|
|
||||||
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
|
||||||
*_errno() = EINVAL;
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*pval = 0;
|
|
||||||
hadvapi32 = LoadLibraryA("advapi32.dll");
|
|
||||||
if (!hadvapi32)
|
|
||||||
{
|
|
||||||
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
|
||||||
*_errno() = EINVAL;
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pSystemFunction036 = (void*)GetProcAddress(hadvapi32, "SystemFunction036");
|
|
||||||
if (!pSystemFunction036)
|
|
||||||
{
|
|
||||||
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
|
||||||
*_errno() = EINVAL;
|
|
||||||
FreeLibrary(hadvapi32);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pSystemFunction036(pval, sizeof(*pval)))
|
|
||||||
{
|
|
||||||
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
|
||||||
*_errno() = EINVAL;
|
|
||||||
FreeLibrary(hadvapi32);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
FreeLibrary(hadvapi32);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
64
sdk/lib/crt/stdlib/rand_s.c
Normal file
64
sdk/lib/crt/stdlib/rand_s.c
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: ReactOS CRT library
|
||||||
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
||||||
|
* PURPOSE: rand_s implementation
|
||||||
|
* COPYRIGHT: Copyright 2010 Sylvain Petreolle <spetreolle@yahoo.fr>
|
||||||
|
* Copyright 2015 Christoph von Wittich <christoph_vw@reactos.org>
|
||||||
|
* Copyright 2015 Pierre Schweitzer <pierre@reactos.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <precomp.h>
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* rand_s (MSVCRT.@)
|
||||||
|
*/
|
||||||
|
int CDECL rand_s(unsigned int *pval)
|
||||||
|
{
|
||||||
|
BOOLEAN (WINAPI *pSystemFunction036)(PVOID, ULONG); // RtlGenRandom
|
||||||
|
HINSTANCE hadvapi32;
|
||||||
|
|
||||||
|
if (!pval)
|
||||||
|
{
|
||||||
|
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
||||||
|
*_errno() = EINVAL;
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pval = 0;
|
||||||
|
hadvapi32 = LoadLibraryA("advapi32.dll");
|
||||||
|
if (!hadvapi32)
|
||||||
|
{
|
||||||
|
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
||||||
|
*_errno() = EINVAL;
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pSystemFunction036 = (void*)GetProcAddress(hadvapi32, "SystemFunction036");
|
||||||
|
if (!pSystemFunction036)
|
||||||
|
{
|
||||||
|
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
||||||
|
*_errno() = EINVAL;
|
||||||
|
FreeLibrary(hadvapi32);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pSystemFunction036(pval, sizeof(*pval)))
|
||||||
|
{
|
||||||
|
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
||||||
|
*_errno() = EINVAL;
|
||||||
|
FreeLibrary(hadvapi32);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeLibrary(hadvapi32);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Small hack: import stub to allow GCC's stdc++ to link
|
||||||
|
#if defined(__GNUC__) && (DLL_EXPORT_VERSION < 0x600)
|
||||||
|
#ifdef WIN64
|
||||||
|
const void* __imp_rand_s = rand_s;
|
||||||
|
#else
|
||||||
|
const void* _imp_rand_s = rand_s;
|
||||||
|
#endif
|
||||||
|
#endif
|
|
@ -29,6 +29,7 @@ list(APPEND CRT_STDLIB_SOURCE
|
||||||
stdlib/obsol.c
|
stdlib/obsol.c
|
||||||
stdlib/putenv.c
|
stdlib/putenv.c
|
||||||
stdlib/rand.c
|
stdlib/rand.c
|
||||||
|
stdlib/rand_s.c
|
||||||
stdlib/rot.c
|
stdlib/rot.c
|
||||||
stdlib/senv.c
|
stdlib/senv.c
|
||||||
stdlib/swab.c
|
stdlib/swab.c
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue