Use the right buffer size in SYSPARAMS_Load instead of some random
[wine] / win32 / newfns.c
1 /*
2  * Win32 miscellaneous functions
3  *
4  * Copyright 1995 Thomas Sandford (tdgsandf@prds-grn.demon.co.uk)
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 /* Misc. new functions - they should be moved into appropriate files
22 at a later date. */
23
24 #include "config.h"
25 #include "wine/port.h"
26
27 #include <stdio.h>
28 #include <string.h>
29 #ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
31 #endif
32 #ifdef HAVE_UNISTD_H
33 # include <unistd.h>
34 #endif
35
36 #define NONAMELESSUNION
37 #define NONAMELESSSTRUCT
38 #include "windef.h"
39 #include "winbase.h"
40 #include "winnls.h"
41 #include "winerror.h"
42 #include "wine/debug.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(win32);
45 WINE_DECLARE_DEBUG_CHANNEL(debug);
46
47
48 static BOOL     QUERYPERF_Initialized           = 0;
49 #if defined(__i386__) && defined(__GNUC__)
50 static BOOL     QUERYPERF_RDTSC_Use             = 0;
51 static LONGLONG QUERYPERF_RDTSC_Frequency       = 0;
52 #endif
53
54 static void QUERYPERF_Init(void)
55 {
56 #if defined(__i386__) && defined(__GNUC__)
57     /* We are running on i386 and compiling on GCC.
58      * Do a runtime check to see if we have the rdtsc instruction available
59      */
60     FILE                *fp;
61     char                line[256], *s, *value;
62     double              cpuMHz;
63
64     TRACE("()\n");
65
66     if (IsProcessorFeaturePresent( PF_RDTSC_INSTRUCTION_AVAILABLE ))
67     {
68         /* rdtsc is available.  However, in order to use it
69          * we also need to be able to get the processor's
70          * speed.  Currently we do this by reading /proc/cpuinfo
71          * which makes it Linux-specific.
72          */
73
74         TRACE("rdtsc available\n");
75
76         fp = fopen( "/proc/cpuinfo", "r" );
77         if (fp)
78         {
79             while(fgets( line, sizeof(line), fp ))
80             {
81                 /* NOTE: the ':' is the only character we can rely on */
82                 if (!(value = strchr( line, ':' )))
83                     continue;
84
85                 /* terminate the valuename */
86                 *value++ = '\0';
87                 /* skip any leading spaces */
88                 while (*value == ' ') value++;
89                 if ((s = strchr( value, '\n' )))
90                     *s = '\0';
91
92                 if (!strncasecmp( line, "cpu MHz", strlen( "cpu MHz" ) ))
93                 {
94                     if (sscanf( value, "%lf", &cpuMHz ) == 1)
95                     {
96                         QUERYPERF_RDTSC_Frequency = (LONGLONG)(cpuMHz * 1000000.0);
97                         QUERYPERF_RDTSC_Use = TRUE;
98                         TRACE("using frequency: %lldHz\n", QUERYPERF_RDTSC_Frequency);
99                         break;
100                     }
101                 }
102             }
103             fclose(fp);
104         }
105     }
106 #endif
107     QUERYPERF_Initialized = TRUE;
108 }
109
110
111 /****************************************************************************
112  *              QueryPerformanceCounter (KERNEL32.@)
113  */
114 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
115 {
116     struct timeval tv;
117
118     if (!QUERYPERF_Initialized)
119         QUERYPERF_Init();
120
121 #if defined(__i386__) && defined(__GNUC__)
122     if (QUERYPERF_RDTSC_Use)
123     {
124         /* i586 optimized version */
125         __asm__ __volatile__ ( "rdtsc"
126                                : "=a" (counter->s.LowPart), "=d" (counter->s.HighPart) );
127         return TRUE;
128     }
129     /* fall back to generic routine (ie, for i386, i486) */
130 #endif
131
132     /* generic routine */
133     gettimeofday( &tv, NULL );
134     counter->QuadPart = (LONGLONG)tv.tv_usec + (LONGLONG)tv.tv_sec * 1000000;
135     return TRUE;
136 }
137
138 /****************************************************************************
139  *              QueryPerformanceFrequency (KERNEL32.@)
140  */
141 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
142 {
143     if (!QUERYPERF_Initialized)
144         QUERYPERF_Init();
145
146 #if defined(__i386__) && defined(__GNUC__)
147     if (QUERYPERF_RDTSC_Use)
148     {
149         frequency->QuadPart = QUERYPERF_RDTSC_Frequency;
150         return TRUE;
151     }
152 #endif
153
154     frequency->s.LowPart        = 1000000;
155     frequency->s.HighPart       = 0;
156     return TRUE;
157 }
158
159 /****************************************************************************
160  *              FlushInstructionCache (KERNEL32.@)
161  */
162 BOOL WINAPI FlushInstructionCache(HANDLE hProcess, LPCVOID lpBaseAddress, SIZE_T dwSize)
163 {
164     if (GetVersion() & 0x80000000) return TRUE; /* not NT, always TRUE */
165     FIXME_(debug)("(0x%08lx,%p,0x%08lx): stub\n",(DWORD)hProcess, lpBaseAddress, dwSize);
166     return TRUE;
167 }
168
169 /***********************************************************************
170  *           GetSystemPowerStatus      (KERNEL32.@)
171  */
172 BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS sps_ptr)
173 {
174     return FALSE;   /* no power management support */
175 }
176
177
178 /***********************************************************************
179  *           SetSystemPowerState      (KERNEL32.@)
180  */
181 BOOL WINAPI SetSystemPowerState(BOOL suspend_or_hibernate,
182                                   BOOL force_flag)
183 {
184     /* suspend_or_hibernate flag: w95 does not support
185        this feature anyway */
186
187     for ( ;0; )
188     {
189         if ( force_flag )
190         {
191         }
192         else
193         {
194         }
195     }
196     return TRUE;
197 }
198
199
200 /******************************************************************************
201  * CreateMailslotA [KERNEL32.@]
202  */
203 HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
204                                    DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa)
205 {
206     FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_a(lpName),
207           nMaxMessageSize, lReadTimeout, sa);
208     return (HANDLE)1;
209 }
210
211
212 /******************************************************************************
213  * CreateMailslotW [KERNEL32.@]  Creates a mailslot with specified name
214  *
215  * PARAMS
216  *    lpName          [I] Pointer to string for mailslot name
217  *    nMaxMessageSize [I] Maximum message size
218  *    lReadTimeout    [I] Milliseconds before read time-out
219  *    sa              [I] Pointer to security structure
220  *
221  * RETURNS
222  *    Success: Handle to mailslot
223  *    Failure: INVALID_HANDLE_VALUE
224  */
225 HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
226                                    DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
227 {
228     FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName),
229           nMaxMessageSize, lReadTimeout, sa);
230     return (HANDLE)1;
231 }
232
233
234 /******************************************************************************
235  * GetMailslotInfo [KERNEL32.@]  Retrieves info about specified mailslot
236  *
237  * PARAMS
238  *    hMailslot        [I] Mailslot handle
239  *    lpMaxMessageSize [O] Address of maximum message size
240  *    lpNextSize       [O] Address of size of next message
241  *    lpMessageCount   [O] Address of number of messages
242  *    lpReadTimeout    [O] Address of read time-out
243  *
244  * RETURNS
245  *    Success: TRUE
246  *    Failure: FALSE
247  */
248 BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
249                                LPDWORD lpNextSize, LPDWORD lpMessageCount,
250                                LPDWORD lpReadTimeout )
251 {
252     FIXME("(%p): stub\n",hMailslot);
253     if (lpMaxMessageSize) *lpMaxMessageSize = (DWORD)NULL;
254     if (lpNextSize) *lpNextSize = (DWORD)NULL;
255     if (lpMessageCount) *lpMessageCount = (DWORD)NULL;
256     if (lpReadTimeout) *lpReadTimeout = (DWORD)NULL;
257     return TRUE;
258 }
259
260
261 /******************************************************************************
262  * GetCompressedFileSizeA [KERNEL32.@]
263  *
264  * NOTES
265  *    This should call the W function below
266  */
267 DWORD WINAPI GetCompressedFileSizeA(
268     LPCSTR lpFileName,
269     LPDWORD lpFileSizeHigh)
270 {
271     FIXME("(...): stub\n");
272     return 0xffffffff;
273 }
274
275
276 /******************************************************************************
277  * GetCompressedFileSizeW [KERNEL32.@]
278  *
279  * RETURNS
280  *    Success: Low-order doubleword of number of bytes
281  *    Failure: 0xffffffff
282  */
283 DWORD WINAPI GetCompressedFileSizeW(
284     LPCWSTR lpFileName,     /* [in]  Pointer to name of file */
285     LPDWORD lpFileSizeHigh) /* [out] Receives high-order doubleword of size */
286 {
287     FIXME("(%s,%p): stub\n",debugstr_w(lpFileName),lpFileSizeHigh);
288     return 0xffffffff;
289 }
290
291
292 /******************************************************************************
293  *              CreateIoCompletionPort (KERNEL32.@)
294  */
295 HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle,
296 HANDLE hExistingCompletionPort, DWORD dwCompletionKey,
297 DWORD dwNumberOfConcurrentThreads)
298 {
299     FIXME("(%p, %p, %08lx, %08lx): stub.\n", hFileHandle, hExistingCompletionPort, dwCompletionKey, dwNumberOfConcurrentThreads);
300     return NULL;
301 }
302
303 /******************************************************************************
304  *              GetQueuedCompletionStatus (KERNEL32.@)
305  */
306 BOOL WINAPI GetQueuedCompletionStatus(
307     HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
308     LPDWORD lpCompletionKey, LPOVERLAPPED *lpOverlapped, DWORD dwMilliseconds
309 ) {
310     FIXME("(%p,%p,%p,%p,%ld), stub!\n",CompletionPort,lpNumberOfBytesTransferred,lpCompletionKey,lpOverlapped,dwMilliseconds);
311     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
312     return FALSE;
313 }
314
315 /******************************************************************************
316  *           GetDevicePowerState   (KERNEL32.@)
317  */
318 BOOL WINAPI GetDevicePowerState(HANDLE hDevice, BOOL* pfOn)
319 {
320     FIXME("(hDevice %p pfOn %p): stub\n", hDevice, pfOn);
321     return TRUE; /* no information */
322 }