source: trunk/src/msvcrt/misc.c@ 10005

Last change on this file since 10005 was 10005, checked in by sandervl, 22 years ago

PF: MSVCRT update

File size: 4.7 KB
Line 
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "msvcrt.h"
22#include <stdlib.h>
23#include <string.h>
24#include <math.h>
25#include "emxheader.h"
26#include "msvcrt/stdlib.h"
27
28
29#include "wine/debug.h"
30
31WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
32
33
34/*********************************************************************
35 * _beep (MSVCRT.@)
36 */
37void _beep( unsigned int freq, unsigned int duration)
38{
39 TRACE(":Freq %d, Duration %d\n",freq,duration);
40 Beep(freq, duration);
41}
42
43/*********************************************************************
44 * rand (MSVCRT.@)
45 */
46int MSVCRT_rand()
47{
48 return (rand() & 0x7fff);
49}
50
51/*********************************************************************
52 * _sleep (MSVCRT.@)
53 */
54void MSVCRT__sleep(unsigned long timeout)
55{
56 TRACE("_sleep for %ld milliseconds\n",timeout);
57 Sleep((timeout)?timeout:1);
58}
59
60/*********************************************************************
61 * _lfind (MSVCRT.@)
62 */
63void* MSVCRT__lfind(const void* match, const void* start,
64 unsigned int* array_size, unsigned int elem_size,
65 MSVCRT_compar_fn_t cf)
66{
67 unsigned int size = *array_size;
68 dprintf(("MSVCRT: _lfind"));
69 if (size)
70 do
71 {
72 if (cf(match, start) == 0)
73 return (void *)start; /* found */
74 start = (char*)start + elem_size;
75 } while (--size);
76 return NULL;
77}
78
79/*********************************************************************
80 * _lsearch (MSVCRT.@)
81 */
82void* MSVCRT__lsearch(const void* match, void* start,
83 unsigned int* array_size, unsigned int elem_size,
84 MSVCRT_compar_fn_t cf)
85{
86 unsigned int size = *array_size;
87 dprintf(("MSVCRT: _lsearch"));
88 if (size)
89 do
90 {
91 if (cf(match, start) == 0)
92 return start; /* found */
93 start = (char*)start + elem_size;
94 } while (--size);
95
96 /* not found, add to end */
97 memcpy(start, match, elem_size);
98 array_size[0]++;
99 return start;
100}
101
102
103/*********************************************************************
104 * _chkesp (MSVCRT.@)
105 *
106 * Trap to a debugger if the value of the stack pointer has changed.
107 *
108 * PARAMS
109 * None.
110 *
111 * RETURNS
112 * Does not return.
113 *
114 * NOTES
115 * This function is available for iX86 only.
116 *
117 * When VC++ generates debug code, it stores the value of the stack pointer
118 * before calling any external function, and checks the value following
119 * the call. It then calls this function, which will trap if the values are
120 * not the same. Usually this means that the prototype used to call
121 * the function is incorrect. It can also mean that the .spec entry has
122 * the wrong calling convention or parameters.
123 */
124#ifdef __i386__
125
126# ifdef __GNUC__
127__ASM_GLOBAL_FUNC(_chkesp,
128 "jnz 1f\n\t"
129 "ret\n"
130 "1:\tpushl %ebp\n\t"
131 "movl %esp,%ebp\n\t"
132 "pushl %eax\n\t"
133 "pushl %ecx\n\t"
134 "pushl %edx\n\t"
135 "call " __ASM_NAME("MSVCRT_chkesp_fail") "\n\t"
136 "popl %edx\n\t"
137 "popl %ecx\n\t"
138 "popl %eax\n\t"
139 "popl %ebp\n\t"
140 "ret");
141
142void MSVCRT_chkesp_fail(void)
143{
144 ERR("Stack pointer incorrect after last function call - Bad prototype/spec entry?\n");
145 DebugBreak();
146}
147
148# else /* __GNUC__ */
149void _chkesp(void) { }
150# endif /* __GNUC__ */
151
152#endif /* __i386__ */
153
154
155
156#ifdef __WIN32OS2__
157#if defined(__GNUC__) && defined(__i386__)
158#define DO_FPU(x,y) __asm__ __volatile__( x " %0;fwait" : "=m" (y) : )
159#define POP_FPU(x) DO_FPU("fstpl",x)
160#endif
161
162/*********************************************************************
163 * _ftol (NTDLL.@)
164 *
165 * VERSION
166 * [GNUC && i386]
167 */
168double _emx_rint (double);
169
170#if defined(__GNUC__) && defined(__i386__)
171LONGLONG __cdecl _ftol(double fl)
172{
173 /* don't just do DO_FPU("fistp",retval), because the rounding
174 * mode must also be set to "round towards zero"... */
175 POP_FPU(fl);
176 return (LONGLONG)(fl);
177
178}
179#endif /* defined(__GNUC__) && defined(__i386__) */
180#endif
Note: See TracBrowser for help on using the repository browser.