Protect the TEXTMETRIC struct from redefinition.
[wine/gsoc_dplay.git] / win32 / newfns.c
blobe88541867495deb8af26d45ea4e09b3352179313
1 /*
2 * Win32 miscellaneous functions
4 * Copyright 1995 Thomas Sandford (tdgsandf@prds-grn.demon.co.uk)
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 /* Misc. new functions - they should be moved into appropriate files
22 at a later date. */
24 #include "config.h"
25 #include "wine/port.h"
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
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"
44 WINE_DEFAULT_DEBUG_CHANNEL(win32);
45 WINE_DECLARE_DEBUG_CHANNEL(debug);
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
54 static void QUERYPERF_Init(void)
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
60 FILE *fp;
61 char line[256], *s, *value;
62 double cpuMHz;
64 TRACE("()\n");
66 if (IsProcessorFeaturePresent( PF_RDTSC_INSTRUCTION_AVAILABLE ))
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.
74 TRACE("rdtsc available\n");
76 fp = fopen( "/proc/cpuinfo", "r" );
77 if (fp)
79 while(fgets( line, sizeof(line), fp ))
81 /* NOTE: the ':' is the only character we can rely on */
82 if (!(value = strchr( line, ':' )))
83 continue;
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';
92 if (!strncasecmp( line, "cpu MHz", strlen( "cpu MHz" ) ))
94 if (sscanf( value, "%lf", &cpuMHz ) == 1)
96 QUERYPERF_RDTSC_Frequency = (LONGLONG)(cpuMHz * 1000000.0);
97 QUERYPERF_RDTSC_Use = TRUE;
98 TRACE("using frequency: %lldHz\n", QUERYPERF_RDTSC_Frequency);
99 break;
103 fclose(fp);
106 #endif
107 QUERYPERF_Initialized = TRUE;
111 /****************************************************************************
112 * QueryPerformanceCounter (KERNEL32.@)
114 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
116 struct timeval tv;
118 if (!QUERYPERF_Initialized)
119 QUERYPERF_Init();
121 #if defined(__i386__) && defined(__GNUC__)
122 if (QUERYPERF_RDTSC_Use)
124 /* i586 optimized version */
125 __asm__ __volatile__ ( "rdtsc"
126 : "=a" (counter->s.LowPart), "=d" (counter->s.HighPart) );
127 return TRUE;
129 /* fall back to generic routine (ie, for i386, i486) */
130 #endif
132 /* generic routine */
133 gettimeofday( &tv, NULL );
134 counter->QuadPart = (LONGLONG)tv.tv_usec + (LONGLONG)tv.tv_sec * 1000000;
135 return TRUE;
138 /****************************************************************************
139 * QueryPerformanceFrequency (KERNEL32.@)
141 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
143 if (!QUERYPERF_Initialized)
144 QUERYPERF_Init();
146 #if defined(__i386__) && defined(__GNUC__)
147 if (QUERYPERF_RDTSC_Use)
149 frequency->QuadPart = QUERYPERF_RDTSC_Frequency;
150 return TRUE;
152 #endif
154 frequency->s.LowPart = 1000000;
155 frequency->s.HighPart = 0;
156 return TRUE;
159 /****************************************************************************
160 * FlushInstructionCache (KERNEL32.@)
162 BOOL WINAPI FlushInstructionCache(HANDLE hProcess, LPCVOID lpBaseAddress, SIZE_T dwSize)
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;
169 /***********************************************************************
170 * GetSystemPowerStatus (KERNEL32.@)
172 BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS sps_ptr)
174 return FALSE; /* no power management support */
178 /***********************************************************************
179 * SetSystemPowerState (KERNEL32.@)
181 BOOL WINAPI SetSystemPowerState(BOOL suspend_or_hibernate,
182 BOOL force_flag)
184 /* suspend_or_hibernate flag: w95 does not support
185 this feature anyway */
187 for ( ;0; )
189 if ( force_flag )
192 else
196 return TRUE;
200 /******************************************************************************
201 * CreateMailslotA [KERNEL32.@]
203 HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
204 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa)
206 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_a(lpName),
207 nMaxMessageSize, lReadTimeout, sa);
208 return (HANDLE)1;
212 /******************************************************************************
213 * CreateMailslotW [KERNEL32.@] Creates a mailslot with specified name
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
221 * RETURNS
222 * Success: Handle to mailslot
223 * Failure: INVALID_HANDLE_VALUE
225 HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
226 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
228 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName),
229 nMaxMessageSize, lReadTimeout, sa);
230 return (HANDLE)1;
234 /******************************************************************************
235 * GetMailslotInfo [KERNEL32.@] Retrieves info about specified mailslot
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
244 * RETURNS
245 * Success: TRUE
246 * Failure: FALSE
248 BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
249 LPDWORD lpNextSize, LPDWORD lpMessageCount,
250 LPDWORD lpReadTimeout )
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;
261 /******************************************************************************
262 * GetCompressedFileSizeA [KERNEL32.@]
264 * NOTES
265 * This should call the W function below
267 DWORD WINAPI GetCompressedFileSizeA(
268 LPCSTR lpFileName,
269 LPDWORD lpFileSizeHigh)
271 FIXME("(...): stub\n");
272 return 0xffffffff;
276 /******************************************************************************
277 * GetCompressedFileSizeW [KERNEL32.@]
279 * RETURNS
280 * Success: Low-order doubleword of number of bytes
281 * Failure: 0xffffffff
283 DWORD WINAPI GetCompressedFileSizeW(
284 LPCWSTR lpFileName, /* [in] Pointer to name of file */
285 LPDWORD lpFileSizeHigh) /* [out] Receives high-order doubleword of size */
287 FIXME("(%s,%p): stub\n",debugstr_w(lpFileName),lpFileSizeHigh);
288 return 0xffffffff;
292 /******************************************************************************
293 * CreateIoCompletionPort (KERNEL32.@)
295 HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle,
296 HANDLE hExistingCompletionPort, DWORD dwCompletionKey,
297 DWORD dwNumberOfConcurrentThreads)
299 FIXME("(%p, %p, %08lx, %08lx): stub.\n", hFileHandle, hExistingCompletionPort, dwCompletionKey, dwNumberOfConcurrentThreads);
300 return NULL;
303 /******************************************************************************
304 * GetQueuedCompletionStatus (KERNEL32.@)
306 BOOL WINAPI GetQueuedCompletionStatus(
307 HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
308 LPDWORD lpCompletionKey, LPOVERLAPPED *lpOverlapped, DWORD dwMilliseconds
310 FIXME("(%p,%p,%p,%p,%ld), stub!\n",CompletionPort,lpNumberOfBytesTransferred,lpCompletionKey,lpOverlapped,dwMilliseconds);
311 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
312 return FALSE;
315 /******************************************************************************
316 * GetDevicePowerState (KERNEL32.@)
318 BOOL WINAPI GetDevicePowerState(HANDLE hDevice, BOOL* pfOn)
320 FIXME("(hDevice %p pfOn %p): stub\n", hDevice, pfOn);
321 return TRUE; /* no information */