1 /*
2 * msvcrt.dll misc functions
3 *
4 * Copyright 2000 Jon Griffiths
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdlib.h>
25
26 #include "msvcrt.h"
27 #include "wine/debug.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
30
31
32 /*********************************************************************
33 * _beep (MSVCRT.@)
34 */
35 void CDECL _beep( unsigned int freq, unsigned int duration)
36 {
37 TRACE(":Freq %d, Duration %d\n",freq,duration);
38 Beep(freq, duration);
39 }
40
41 /*********************************************************************
42 * srand (MSVCRT.@)
43 */
44 void CDECL MSVCRT_srand( unsigned int seed )
45 {
46 thread_data_t *data = msvcrt_get_thread_data();
47 data->random_seed = seed;
48 }
49
50 /*********************************************************************
51 * rand (MSVCRT.@)
52 */
53 int CDECL MSVCRT_rand(void)
54 {
55 thread_data_t *data = msvcrt_get_thread_data();
56
57 /* this is the algorithm used by MSVC, according to
58 * http://en.wikipedia.org/wiki/List_of_pseudorandom_number_generators */
59 data->random_seed = data->random_seed * 214013 + 2531011;
60 return (data->random_seed >> 16) & MSVCRT_RAND_MAX;
61 }
62
63 /*********************************************************************
64 * _sleep (MSVCRT.@)
65 */
66 void CDECL MSVCRT__sleep(MSVCRT_ulong timeout)
67 {
68 TRACE("_sleep for %d milliseconds\n",timeout);
69 Sleep((timeout)?timeout:1);
70 }
71
72 /*********************************************************************
73 * _lfind (MSVCRT.@)
74 */
75 void* CDECL _lfind(const void* match, const void* start,
76 unsigned int* array_size, unsigned int elem_size,
77 int (*cf)(const void*,const void*) )
78 {
79 unsigned int size = *array_size;
80 if (size)
81 do
82 {
83 if (cf(match, start) == 0)
84 return (void *)start; /* found */
85 start = (const char *)start + elem_size;
86 } while (--size);
87 return NULL;
88 }
89
90 /*********************************************************************
91 * _lsearch (MSVCRT.@)
92 */
93 void* CDECL _lsearch(const void* match, void* start,
94 unsigned int* array_size, unsigned int elem_size,
95 int (*cf)(const void*,const void*) )
96 {
97 unsigned int size = *array_size;
98 if (size)
99 do
100 {
101 if (cf(match, start) == 0)
102 return start; /* found */
103 start = (char*)start + elem_size;
104 } while (--size);
105
106 /* not found, add to end */
107 memcpy(start, match, elem_size);
108 array_size[0]++;
109 return start;
110 }
111
112 /*********************************************************************
113 * _chkesp (MSVCRT.@)
114 *
115 * Trap to a debugger if the value of the stack pointer has changed.
116 *
117 * PARAMS
118 * None.
119 *
120 * RETURNS
121 * Does not return.
122 *
123 * NOTES
124 * This function is available for iX86 only.
125 *
126 * When VC++ generates debug code, it stores the value of the stack pointer
127 * before calling any external function, and checks the value following
128 * the call. It then calls this function, which will trap if the values are
129 * not the same. Usually this means that the prototype used to call
130 * the function is incorrect. It can also mean that the .spec entry has
131 * the wrong calling convention or parameters.
132 */
133 #ifdef __i386__
134
135 # ifdef __GNUC__
136
137 __ASM_GLOBAL_FUNC(_chkesp,
138 "jnz 1f\n\t"
139 "ret\n"
140 "1:\tpushl %ebp\n\t"
141 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
142 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
143 "movl %esp,%ebp\n\t"
144 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
145 "subl $12,%esp\n\t"
146 "pushl %eax\n\t"
147 "pushl %ecx\n\t"
148 "pushl %edx\n\t"
149 "call " __ASM_NAME("MSVCRT_chkesp_fail") "\n\t"
150 "popl %edx\n\t"
151 "popl %ecx\n\t"
152 "popl %eax\n\t"
153 "leave\n\t"
154 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
155 __ASM_CFI(".cfi_same_value %ebp\n\t")
156 "ret")
157
158 void CDECL MSVCRT_chkesp_fail(void)
159 {
160 ERR("Stack pointer incorrect after last function call - Bad prototype/spec entry?\n");
161 DebugBreak();
162 }
163
164 # else /* __GNUC__ */
165
166 /**********************************************************************/
167
168 void CDECL _chkesp(void)
169 {
170 }
171
172 # endif /* __GNUC__ */
173
174 #endif /* __i386__ */
175
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.