Cast time_t to long for printing.
[wine] / dlls / msvcrt / misc.c
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 "config.h"
22 #include "wine/port.h"
23
24 #include <stdlib.h>
25
26 #include "msvcrt.h"
27 #include "msvcrt/stdlib.h"
28
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
32
33
34 /*********************************************************************
35  *              _beep (MSVCRT.@)
36  */
37 void _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  */
46 int MSVCRT_rand()
47 {
48   return (rand() & 0x7fff);
49 }
50
51 /*********************************************************************
52  *              _sleep (MSVCRT.@)
53  */
54 void _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  */
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*) )
66 {
67   unsigned int size = *array_size;
68   if (size)
69     do
70     {
71       if (cf(match, start) == 0)
72         return (void *)start; /* found */
73       start = (char*)start + elem_size;
74     } while (--size);
75   return NULL;
76 }
77
78 /*********************************************************************
79  *              _lsearch (MSVCRT.@)
80  */
81 void* _lsearch(const void* match, void* start,
82                unsigned int* array_size, unsigned int elem_size,
83                int (*cf)(const void*,const void*) )
84 {
85   unsigned int size = *array_size;
86   if (size)
87     do
88     {
89       if (cf(match, start) == 0)
90         return start; /* found */
91       start = (char*)start + elem_size;
92     } while (--size);
93
94   /* not found, add to end */
95   memcpy(start, match, elem_size);
96   array_size[0]++;
97   return start;
98 }
99
100 /*********************************************************************
101  *              _chkesp (MSVCRT.@)
102  *
103  * Trap to a debugger if the value of the stack pointer has changed.
104  *
105  * PARAMS
106  *  None.
107  *
108  * RETURNS
109  *  Does not return.
110  *
111  * NOTES
112  *  This function is available for iX86 only.
113  *
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.
120  */
121 #ifdef __i386__
122
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");
138
139 void MSVCRT_chkesp_fail(void)
140 {
141   ERR("Stack pointer incorrect after last function call - Bad prototype/spec entry?\n");
142   DebugBreak();
143 }
144
145 # else  /* __GNUC__ */
146 void _chkesp(void) { }
147 # endif  /* __GNUC__ */
148
149 #endif  /* __i386__ */