Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
ad8cb613
Commit
ad8cb613
authored
Jan 14, 2006
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msvcrt: Reimplement rand() and srand() to use per-thread data for the
random seed.
parent
2ec3b961
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
2 deletions
+20
-2
misc.c
dlls/msvcrt/misc.c
+15
-1
msvcrt.h
dlls/msvcrt/msvcrt.h
+2
-0
msvcrt.spec
dlls/msvcrt/msvcrt.spec
+1
-1
headers.c
dlls/msvcrt/tests/headers.c
+1
-0
thread.c
dlls/msvcrt/thread.c
+1
-0
No files found.
dlls/msvcrt/misc.c
View file @
ad8cb613
...
...
@@ -39,11 +39,25 @@ void _beep( unsigned int freq, unsigned int duration)
}
/*********************************************************************
* srand (MSVCRT.@)
*/
void
MSVCRT_srand
(
unsigned
int
seed
)
{
thread_data_t
*
data
=
msvcrt_get_thread_data
();
data
->
random_seed
=
seed
;
}
/*********************************************************************
* rand (MSVCRT.@)
*/
int
MSVCRT_rand
(
void
)
{
return
(
rand
()
&
0x7fff
);
thread_data_t
*
data
=
msvcrt_get_thread_data
();
/* this is the algorithm used by MSVC, according to
* http://en.wikipedia.org/wiki/List_of_pseudorandom_number_generators */
data
->
random_seed
=
data
->
random_seed
*
214013
+
2531011
;
return
(
data
->
random_seed
>>
16
)
&
MSVCRT_RAND_MAX
;
}
/*********************************************************************
...
...
dlls/msvcrt/msvcrt.h
View file @
ad8cb613
...
...
@@ -93,6 +93,7 @@ extern DWORD msvcrt_tls_index;
struct
__thread_data
{
int
thread_errno
;
unsigned
long
thread_doserrno
;
unsigned
int
random_seed
;
/* seed for rand() */
char
*
strtok_next
;
/* next ptr for strtok() */
unsigned
char
*
mbstok_next
;
/* next ptr for mbstok() */
MSVCRT_wchar_t
*
wcstok_next
;
/* next ptr for wcstok() */
...
...
@@ -375,6 +376,7 @@ struct MSVCRT__stati64 {
#define MSVCRT_WEOF (MSVCRT_wint_t)(0xFFFF)
#define MSVCRT_EOF (-1)
#define MSVCRT_TMP_MAX 0x7fff
#define MSVCRT_RAND_MAX 0x7fff
#define MSVCRT_BUFSIZ 512
#define MSVCRT_STDIN_FILENO 0
...
...
dlls/msvcrt/msvcrt.spec
View file @
ad8cb613
...
...
@@ -695,7 +695,7 @@
@ cdecl sinh(double)
@ varargs sprintf(ptr str) MSVCRT_sprintf
@ cdecl sqrt(double)
@ cdecl srand(long)
@ cdecl srand(long)
MSVCRT_srand
@ varargs sscanf(str str) MSVCRT_sscanf
@ cdecl strcat(str str)
@ cdecl strchr(str long)
...
...
dlls/msvcrt/tests/headers.c
View file @
ad8cb613
...
...
@@ -303,6 +303,7 @@ static void test_defines(void)
CHECK_DEF
(
WEOF
);
CHECK_DEF
(
EOF
);
CHECK_DEF
(
TMP_MAX
);
CHECK_DEF
(
RAND_MAX
);
CHECK_DEF
(
BUFSIZ
);
CHECK_DEF
(
STDIN_FILENO
);
CHECK_DEF
(
STDOUT_FILENO
);
...
...
dlls/msvcrt/thread.c
View file @
ad8cb613
...
...
@@ -44,6 +44,7 @@ thread_data_t *msvcrt_get_thread_data(void)
if
(
!
(
ptr
=
HeapAlloc
(
GetProcessHeap
(),
HEAP_ZERO_MEMORY
,
sizeof
(
*
ptr
)
)))
_amsg_exit
(
_RT_THREAD
);
if
(
!
TlsSetValue
(
msvcrt_tls_index
,
ptr
))
_amsg_exit
(
_RT_THREAD
);
ptr
->
random_seed
=
1
;
}
SetLastError
(
err
);
return
ptr
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment