_open_osfhandle: set at least the _IOREAD flag.
[wine/multimedia.git] / win32 / newfns.c
blob80219c6ba121a8b98183f7794007ae4a713f3ce8
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 <stdio.h>
25 #include <string.h>
26 #include <sys/time.h>
27 #include <unistd.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31 #include "winerror.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(win32);
35 WINE_DECLARE_DEBUG_CHANNEL(debug);
38 static BOOL QUERYPERF_Initialized = 0;
39 #if defined(__i386__) && defined(__GNUC__)
40 static BOOL QUERYPERF_RDTSC_Use = 0;
41 static LONGLONG QUERYPERF_RDTSC_Frequency = 0;
42 #endif
44 static void QUERYPERF_Init(void)
46 #if defined(__i386__) && defined(__GNUC__)
47 /* We are running on i386 and compiling on GCC.
48 * Do a runtime check to see if we have the rdtsc instruction available
50 FILE *fp;
51 char line[256], *s, *value;
52 double cpuMHz;
54 TRACE("()\n");
56 if (IsProcessorFeaturePresent( PF_RDTSC_INSTRUCTION_AVAILABLE ))
58 /* rdtsc is available. However, in order to use it
59 * we also need to be able to get the processor's
60 * speed. Currently we do this by reading /proc/cpuinfo
61 * which makes it Linux-specific.
64 TRACE("rdtsc available\n");
66 fp = fopen( "/proc/cpuinfo", "r" );
67 if (fp)
69 while(fgets( line, sizeof(line), fp ))
71 /* NOTE: the ':' is the only character we can rely on */
72 if (!(value = strchr( line, ':' )))
73 continue;
75 /* terminate the valuename */
76 *value++ = '\0';
77 /* skip any leading spaces */
78 while (*value == ' ') value++;
79 if ((s = strchr( value, '\n' )))
80 *s = '\0';
82 if (!strncasecmp( line, "cpu MHz", strlen( "cpu MHz" ) ))
84 if (sscanf( value, "%lf", &cpuMHz ) == 1)
86 QUERYPERF_RDTSC_Frequency = (LONGLONG)(cpuMHz * 1000000.0);
87 QUERYPERF_RDTSC_Use = TRUE;
88 TRACE("using frequency: %lldHz\n", QUERYPERF_RDTSC_Frequency);
89 break;
93 fclose(fp);
96 #endif
97 QUERYPERF_Initialized = TRUE;
101 /****************************************************************************
102 * QueryPerformanceCounter (KERNEL32.@)
104 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
106 struct timeval tv;
108 if (!QUERYPERF_Initialized)
109 QUERYPERF_Init();
111 #if defined(__i386__) && defined(__GNUC__)
112 if (QUERYPERF_RDTSC_Use)
114 /* i586 optimized version */
115 __asm__ __volatile__ ( "rdtsc"
116 : "=a" (counter->s.LowPart), "=d" (counter->s.HighPart) );
117 return TRUE;
119 /* fall back to generic routine (ie, for i386, i486) */
120 #endif
122 /* generic routine */
123 gettimeofday( &tv, NULL );
124 counter->QuadPart = (LONGLONG)tv.tv_usec + (LONGLONG)tv.tv_sec * 1000000LL;
125 return TRUE;
128 /****************************************************************************
129 * QueryPerformanceFrequency (KERNEL32.@)
131 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
133 if (!QUERYPERF_Initialized)
134 QUERYPERF_Init();
136 #if defined(__i386__) && defined(__GNUC__)
137 if (QUERYPERF_RDTSC_Use)
139 frequency->QuadPart = QUERYPERF_RDTSC_Frequency;
140 return TRUE;
142 #endif
144 frequency->s.LowPart = 1000000;
145 frequency->s.HighPart = 0;
146 return TRUE;
149 /****************************************************************************
150 * FlushInstructionCache (KERNEL32.@)
152 BOOL WINAPI FlushInstructionCache(HANDLE hProcess, LPCVOID lpBaseAddress, DWORD dwSize)
154 if (GetVersion() & 0x80000000) return TRUE; /* not NT, always TRUE */
155 FIXME_(debug)("(0x%08lx,%p,0x%08lx): stub\n",(DWORD)hProcess, lpBaseAddress, dwSize);
156 return TRUE;
159 /***********************************************************************
160 * GetSystemPowerStatus (KERNEL32.@)
162 BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS sps_ptr)
164 return FALSE; /* no power management support */
168 /***********************************************************************
169 * SetSystemPowerState (KERNEL32.@)
171 BOOL WINAPI SetSystemPowerState(BOOL suspend_or_hibernate,
172 BOOL force_flag)
174 /* suspend_or_hibernate flag: w95 does not support
175 this feature anyway */
177 for ( ;0; )
179 if ( force_flag )
182 else
186 return TRUE;
190 /******************************************************************************
191 * CreateMailslotA [KERNEL32.@]
193 HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
194 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa)
196 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_a(lpName),
197 nMaxMessageSize, lReadTimeout, sa);
198 return 1;
202 /******************************************************************************
203 * CreateMailslotW [KERNEL32.@] Creates a mailslot with specified name
205 * PARAMS
206 * lpName [I] Pointer to string for mailslot name
207 * nMaxMessageSize [I] Maximum message size
208 * lReadTimeout [I] Milliseconds before read time-out
209 * sa [I] Pointer to security structure
211 * RETURNS
212 * Success: Handle to mailslot
213 * Failure: INVALID_HANDLE_VALUE
215 HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
216 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
218 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName),
219 nMaxMessageSize, lReadTimeout, sa);
220 return 1;
224 /******************************************************************************
225 * GetMailslotInfo [KERNEL32.@] Retrieves info about specified mailslot
227 * PARAMS
228 * hMailslot [I] Mailslot handle
229 * lpMaxMessageSize [O] Address of maximum message size
230 * lpNextSize [O] Address of size of next message
231 * lpMessageCount [O] Address of number of messages
232 * lpReadTimeout [O] Address of read time-out
234 * RETURNS
235 * Success: TRUE
236 * Failure: FALSE
238 BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
239 LPDWORD lpNextSize, LPDWORD lpMessageCount,
240 LPDWORD lpReadTimeout )
242 FIXME("(%04x): stub\n",hMailslot);
243 if (lpMaxMessageSize) *lpMaxMessageSize = (DWORD)NULL;
244 if (lpNextSize) *lpNextSize = (DWORD)NULL;
245 if (lpMessageCount) *lpMessageCount = (DWORD)NULL;
246 if (lpReadTimeout) *lpReadTimeout = (DWORD)NULL;
247 return TRUE;
251 /******************************************************************************
252 * GetCompressedFileSizeA [KERNEL32.@]
254 * NOTES
255 * This should call the W function below
257 DWORD WINAPI GetCompressedFileSizeA(
258 LPCSTR lpFileName,
259 LPDWORD lpFileSizeHigh)
261 FIXME("(...): stub\n");
262 return 0xffffffff;
266 /******************************************************************************
267 * GetCompressedFileSizeW [KERNEL32.@]
269 * RETURNS
270 * Success: Low-order doubleword of number of bytes
271 * Failure: 0xffffffff
273 DWORD WINAPI GetCompressedFileSizeW(
274 LPCWSTR lpFileName, /* [in] Pointer to name of file */
275 LPDWORD lpFileSizeHigh) /* [out] Receives high-order doubleword of size */
277 FIXME("(%s,%p): stub\n",debugstr_w(lpFileName),lpFileSizeHigh);
278 return 0xffffffff;
282 /******************************************************************************
283 * SetComputerNameA [KERNEL32.@]
285 BOOL WINAPI SetComputerNameA( LPCSTR lpComputerName )
287 BOOL ret;
288 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpComputerName, -1, NULL, 0 );
289 LPWSTR nameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
291 MultiByteToWideChar( CP_ACP, 0, lpComputerName, -1, nameW, len );
292 ret = SetComputerNameW( nameW );
293 HeapFree( GetProcessHeap(), 0, nameW );
294 return ret;
298 /******************************************************************************
299 * SetComputerNameW [KERNEL32.@]
301 * PARAMS
302 * lpComputerName [I] Address of new computer name
304 * RETURNS STD
306 BOOL WINAPI SetComputerNameW( LPCWSTR lpComputerName )
308 FIXME("(%s): stub\n", debugstr_w(lpComputerName));
309 return TRUE;
312 /******************************************************************************
313 * CreateIoCompletionPort (KERNEL32.@)
315 HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle,
316 HANDLE hExistingCompletionPort, DWORD dwCompletionKey,
317 DWORD dwNumberOfConcurrentThreads)
319 FIXME("(%04x, %04x, %08lx, %08lx): stub.\n", hFileHandle, hExistingCompletionPort, dwCompletionKey, dwNumberOfConcurrentThreads);
320 return (HANDLE)NULL;
323 /******************************************************************************
324 * GetQueuedCompletionStatus (KERNEL32.@)
326 BOOL WINAPI GetQueuedCompletionStatus(
327 HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
328 LPDWORD lpCompletionKey, LPOVERLAPPED *lpOverlapped, DWORD dwMilliseconds
330 FIXME("(%x,%p,%p,%p,%ld), stub!\n",CompletionPort,lpNumberOfBytesTransferred,lpCompletionKey,lpOverlapped,dwMilliseconds);
331 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
332 return FALSE;