msvcrt: Implement and test rand_s.
This commit is contained in:
parent
3822f9d2e1
commit
841fc1805e
@ -6,7 +6,7 @@ VPATH = @srcdir@
|
|||||||
MODULE = msvcrt.dll
|
MODULE = msvcrt.dll
|
||||||
IMPORTLIB = msvcrt
|
IMPORTLIB = msvcrt
|
||||||
IMPORTS = kernel32 ntdll
|
IMPORTS = kernel32 ntdll
|
||||||
DELAYIMPORTS = user32
|
DELAYIMPORTS = advapi32 user32
|
||||||
|
|
||||||
C_SRCS = \
|
C_SRCS = \
|
||||||
console.c \
|
console.c \
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "msvcrt.h"
|
#include "msvcrt.h"
|
||||||
#include "wine/debug.h"
|
#include "wine/debug.h"
|
||||||
|
#include "ntsecapi.h"
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
||||||
|
|
||||||
@ -60,6 +61,19 @@ int CDECL MSVCRT_rand(void)
|
|||||||
return (data->random_seed >> 16) & MSVCRT_RAND_MAX;
|
return (data->random_seed >> 16) & MSVCRT_RAND_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* rand_s (MSVCRT.@)
|
||||||
|
*/
|
||||||
|
int CDECL MSVCRT_rand_s(unsigned int *pval)
|
||||||
|
{
|
||||||
|
if (!pval || !RtlGenRandom(pval, sizeof(*pval)))
|
||||||
|
{
|
||||||
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
||||||
|
return MSVCRT_EINVAL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* _sleep (MSVCRT.@)
|
* _sleep (MSVCRT.@)
|
||||||
*/
|
*/
|
||||||
|
@ -736,6 +736,7 @@
|
|||||||
@ cdecl qsort(ptr long long ptr) ntdll.qsort
|
@ cdecl qsort(ptr long long ptr) ntdll.qsort
|
||||||
@ cdecl raise(long) MSVCRT_raise
|
@ cdecl raise(long) MSVCRT_raise
|
||||||
@ cdecl rand() MSVCRT_rand
|
@ cdecl rand() MSVCRT_rand
|
||||||
|
@ cdecl rand_s(ptr) MSVCRT_rand_s
|
||||||
@ cdecl realloc(ptr long) MSVCRT_realloc
|
@ cdecl realloc(ptr long) MSVCRT_realloc
|
||||||
@ cdecl remove(str) MSVCRT_remove
|
@ cdecl remove(str) MSVCRT_remove
|
||||||
@ cdecl rename(str str) MSVCRT_rename
|
@ cdecl rename(str str) MSVCRT_rename
|
||||||
|
@ -16,6 +16,7 @@ CTESTS = \
|
|||||||
file.c \
|
file.c \
|
||||||
headers.c \
|
headers.c \
|
||||||
heap.c \
|
heap.c \
|
||||||
|
misc.c \
|
||||||
printf.c \
|
printf.c \
|
||||||
scanf.c \
|
scanf.c \
|
||||||
signal.c \
|
signal.c \
|
||||||
|
58
dlls/msvcrt/tests/misc.c
Normal file
58
dlls/msvcrt/tests/misc.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Unit tests for miscellaneous msvcrt functions
|
||||||
|
*
|
||||||
|
* Copyright 2010 Andrew Nguyen
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "wine/test.h"
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
static int (__cdecl *prand_s)(unsigned int *);
|
||||||
|
|
||||||
|
static void init(void)
|
||||||
|
{
|
||||||
|
HMODULE hmod = GetModuleHandleA("msvcrt.dll");
|
||||||
|
|
||||||
|
prand_s = (void *)GetProcAddress(hmod, "rand_s");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_rand_s(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
unsigned int rand;
|
||||||
|
|
||||||
|
if (!prand_s)
|
||||||
|
{
|
||||||
|
win_skip("rand_s is not available\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = EBADF;
|
||||||
|
ret = prand_s(NULL);
|
||||||
|
ok(ret == EINVAL, "Expected rand_s to return EINVAL, got %d\n", ret);
|
||||||
|
ok(errno == EINVAL, "Expected errno to return EINVAL, got %d\n", errno);
|
||||||
|
|
||||||
|
ret = prand_s(&rand);
|
||||||
|
ok(ret == 0, "Expected rand_s to return 0, got %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
START_TEST(misc)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
|
||||||
|
test_rand_s();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user