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 |
|
---|
24 | #include "msvcrt/stdlib.h"
|
---|
25 |
|
---|
26 |
|
---|
27 | #include "wine/debug.h"
|
---|
28 |
|
---|
29 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
---|
30 |
|
---|
31 |
|
---|
32 | /*********************************************************************
|
---|
33 | * _beep (MSVCRT.@)
|
---|
34 | */
|
---|
35 | void _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 | * rand (MSVCRT.@)
|
---|
43 | */
|
---|
44 | int MSVCRT_rand()
|
---|
45 | {
|
---|
46 | return (rand() & 0x7fff);
|
---|
47 | }
|
---|
48 |
|
---|
49 | /*********************************************************************
|
---|
50 | * _sleep (MSVCRT.@)
|
---|
51 | */
|
---|
52 | void _sleep(unsigned long timeout)
|
---|
53 | {
|
---|
54 | TRACE("_sleep for %ld milliseconds\n",timeout);
|
---|
55 | Sleep((timeout)?timeout:1);
|
---|
56 | }
|
---|
57 |
|
---|
58 | /*********************************************************************
|
---|
59 | * _lfind (MSVCRT.@)
|
---|
60 | */
|
---|
61 | void* _lfind(const void* match, const void* start,
|
---|
62 | unsigned int* array_size, unsigned int elem_size,
|
---|
63 | MSVCRT_compar_fn_t cf)
|
---|
64 | {
|
---|
65 | unsigned int size = *array_size;
|
---|
66 | if (size)
|
---|
67 | do
|
---|
68 | {
|
---|
69 | if (cf(match, start) == 0)
|
---|
70 | return (void *)start; /* found */
|
---|
71 | start = (char*)start + elem_size;
|
---|
72 | } while (--size);
|
---|
73 | return NULL;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /*********************************************************************
|
---|
77 | * _lsearch (MSVCRT.@)
|
---|
78 | */
|
---|
79 | void* _lsearch(const void* match, void* start,
|
---|
80 | unsigned int* array_size, unsigned int elem_size,
|
---|
81 | MSVCRT_compar_fn_t cf)
|
---|
82 | {
|
---|
83 | unsigned int size = *array_size;
|
---|
84 | if (size)
|
---|
85 | do
|
---|
86 | {
|
---|
87 | if (cf(match, start) == 0)
|
---|
88 | return start; /* found */
|
---|
89 | start = (char*)start + elem_size;
|
---|
90 | } while (--size);
|
---|
91 |
|
---|
92 | /* not found, add to end */
|
---|
93 | memcpy(start, match, elem_size);
|
---|
94 | array_size[0]++;
|
---|
95 | return start;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /*********************************************************************
|
---|
99 | * _chkesp (MSVCRT.@)
|
---|
100 | */
|
---|
101 | void _chkesp(void)
|
---|
102 | {
|
---|
103 |
|
---|
104 | }
|
---|
105 |
|
---|
106 | #ifdef __WIN32OS2__
|
---|
107 | #if defined(__GNUC__) && defined(__i386__)
|
---|
108 | #define DO_FPU(x,y) __asm__ __volatile__( x " %0;fwait" : "=m" (y) : )
|
---|
109 | #define POP_FPU(x) DO_FPU("fstpl",x)
|
---|
110 | #endif
|
---|
111 |
|
---|
112 | /*********************************************************************
|
---|
113 | * _ftol (NTDLL.@)
|
---|
114 | *
|
---|
115 | * VERSION
|
---|
116 | * [GNUC && i386]
|
---|
117 | */
|
---|
118 | #if defined(__GNUC__) && defined(__i386__)
|
---|
119 | LONG __cdecl _ftol(void)
|
---|
120 | {
|
---|
121 | /* don't just do DO_FPU("fistp",retval), because the rounding
|
---|
122 | * mode must also be set to "round towards zero"... */
|
---|
123 | double fl;
|
---|
124 | POP_FPU(fl);
|
---|
125 | return (LONG)fl;
|
---|
126 | }
|
---|
127 | #endif /* defined(__GNUC__) && defined(__i386__) */
|
---|
128 | #endif
|
---|