Changed wsock32 to use the new iphlpapi for interface and route
[wine/wine64.git] / dlls / msvcrt / misc.c
blob24bb0f75ace1da76de49e3b7ebab7d1b9d2ab121
1 /*
2 * msvcrt.dll misc functions
4 * Copyright 2000 Jon Griffiths
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.
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.
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdlib.h>
26 #include "msvcrt.h"
27 #include "msvcrt/stdlib.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
34 /*********************************************************************
35 * _beep (MSVCRT.@)
37 void _beep( unsigned int freq, unsigned int duration)
39 TRACE(":Freq %d, Duration %d\n",freq,duration);
40 Beep(freq, duration);
43 /*********************************************************************
44 * rand (MSVCRT.@)
46 int MSVCRT_rand()
48 return (rand() & 0x7fff);
51 /*********************************************************************
52 * _sleep (MSVCRT.@)
54 void _sleep(unsigned long timeout)
56 TRACE("_sleep for %ld milliseconds\n",timeout);
57 Sleep((timeout)?timeout:1);
60 /*********************************************************************
61 * _lfind (MSVCRT.@)
63 void* _lfind(const void* match, const void* start,
64 unsigned int* array_size, unsigned int elem_size,
65 int (*cf)(const void*,const void*) )
67 unsigned int size = *array_size;
68 if (size)
71 if (cf(match, start) == 0)
72 return (void *)start; /* found */
73 start = (char*)start + elem_size;
74 } while (--size);
75 return NULL;
78 /*********************************************************************
79 * _lsearch (MSVCRT.@)
81 void* _lsearch(const void* match, void* start,
82 unsigned int* array_size, unsigned int elem_size,
83 int (*cf)(const void*,const void*) )
85 unsigned int size = *array_size;
86 if (size)
89 if (cf(match, start) == 0)
90 return start; /* found */
91 start = (char*)start + elem_size;
92 } while (--size);
94 /* not found, add to end */
95 memcpy(start, match, elem_size);
96 array_size[0]++;
97 return start;
100 /*********************************************************************
101 * _chkesp (MSVCRT.@)
103 * Trap to a debugger if the value of the stack pointer has changed.
105 * PARAMS
106 * None.
108 * RETURNS
109 * Does not return.
111 * NOTES
112 * This function is available for iX86 only.
114 * When VC++ generates debug code, it stores the value of the stack pointer
115 * before calling any external function, and checks the value following
116 * the call. It then calls this function, which will trap if the values are
117 * not the same. Usually this means that the prototype used to call
118 * the function is incorrect. It can also mean that the .spec entry has
119 * the wrong calling convention or parameters.
121 #ifdef __i386__
123 # ifdef __GNUC__
124 __ASM_GLOBAL_FUNC(_chkesp,
125 "jnz 1f\n\t"
126 "ret\n"
127 "1:\tpushl %ebp\n\t"
128 "movl %esp,%ebp\n\t"
129 "pushl %eax\n\t"
130 "pushl %ecx\n\t"
131 "pushl %edx\n\t"
132 "call " __ASM_NAME("MSVCRT_chkesp_fail") "\n\t"
133 "popl %edx\n\t"
134 "popl %ecx\n\t"
135 "popl %eax\n\t"
136 "popl %ebp\n\t"
137 "ret");
139 void MSVCRT_chkesp_fail(void)
141 ERR("Stack pointer incorrect after last function call - Bad prototype/spec entry?\n");
142 DebugBreak();
145 # else /* __GNUC__ */
146 void _chkesp(void) { }
147 # endif /* __GNUC__ */
149 #endif /* __i386__ */