MSVCRT_getenv: compare for the length of the key and return NULL in
[wine/dcerpc.git] / win32 / newfns.c
blobea50508ca4fb903479cf82f822d4e37e9e097c60
1 /*
2 * Win32 miscellaneous functions
4 * Copyright 1995 Thomas Sandford (tdgsandf@prds-grn.demon.co.uk)
5 */
7 /* Misc. new functions - they should be moved into appropriate files
8 at a later date. */
10 #include <stdio.h>
11 #include <string.h>
12 #include <sys/time.h>
13 #include <unistd.h>
14 #include "windef.h"
15 #include "winerror.h"
16 #include "heap.h"
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(win32);
20 DECLARE_DEBUG_CHANNEL(debug);
23 static BOOL QUERYPERF_Initialized = 0;
24 #if defined(__i386__) && defined(__GNUC__)
25 static BOOL QUERYPERF_RDTSC_Use = 0;
26 static LONGLONG QUERYPERF_RDTSC_Frequency = 0;
27 #endif
29 static void QUERYPERF_Init(void)
31 #if defined(__i386__) && defined(__GNUC__)
32 /* We are running on i386 and compiling on GCC.
33 * Do a runtime check to see if we have the rdtsc instruction available
35 FILE *fp;
36 char line[256], *s, *value;
37 double cpuMHz;
39 TRACE("()\n");
41 if (IsProcessorFeaturePresent( PF_RDTSC_INSTRUCTION_AVAILABLE ))
43 /* rdtsc is available. However, in order to use it
44 * we also need to be able to get the processor's
45 * speed. Currently we do this by reading /proc/cpuinfo
46 * which makes it Linux-specific.
49 TRACE("rdtsc available\n");
51 fp = fopen( "/proc/cpuinfo", "r" );
52 if (fp)
54 while(fgets( line, sizeof(line), fp ))
56 /* NOTE: the ':' is the only character we can rely on */
57 if (!(value = strchr( line, ':' )))
58 continue;
60 /* terminate the valuename */
61 *value++ = '\0';
62 /* skip any leading spaces */
63 while (*value == ' ') value++;
64 if ((s = strchr( value, '\n' )))
65 *s = '\0';
67 if (!strncasecmp( line, "cpu MHz", strlen( "cpu MHz" ) ))
69 if (sscanf( value, "%lf", &cpuMHz ) == 1)
71 QUERYPERF_RDTSC_Frequency = (LONGLONG)(cpuMHz * 1000000.0);
72 QUERYPERF_RDTSC_Use = TRUE;
73 TRACE("using frequency: %lldHz\n", QUERYPERF_RDTSC_Frequency);
74 break;
78 fclose(fp);
81 #endif
82 QUERYPERF_Initialized = TRUE;
86 /****************************************************************************
87 * QueryPerformanceCounter (KERNEL32.@)
89 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
91 struct timeval tv;
93 if (!QUERYPERF_Initialized)
94 QUERYPERF_Init();
96 #if defined(__i386__) && defined(__GNUC__)
97 if (QUERYPERF_RDTSC_Use)
99 /* i586 optimized version */
100 __asm__ __volatile__ ( "rdtsc"
101 : "=a" (counter->s.LowPart), "=d" (counter->s.HighPart) );
102 return TRUE;
104 /* fall back to generic routine (ie, for i386, i486) */
105 #endif
107 /* generic routine */
108 gettimeofday( &tv, NULL );
109 counter->QuadPart = (LONGLONG)tv.tv_usec + (LONGLONG)tv.tv_sec * 1000000LL;
110 return TRUE;
113 /****************************************************************************
114 * QueryPerformanceFrequency (KERNEL32.@)
116 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
118 if (!QUERYPERF_Initialized)
119 QUERYPERF_Init();
121 #if defined(__i386__) && defined(__GNUC__)
122 if (QUERYPERF_RDTSC_Use)
124 frequency->QuadPart = QUERYPERF_RDTSC_Frequency;
125 return TRUE;
127 #endif
129 frequency->s.LowPart = 1000000;
130 frequency->s.HighPart = 0;
131 return TRUE;
134 /****************************************************************************
135 * FlushInstructionCache (KERNEL32.@)
137 BOOL WINAPI FlushInstructionCache(DWORD x,DWORD y,DWORD z) {
138 if (GetVersion() & 0x80000000) return TRUE; /* not NT, always TRUE */
139 FIXME_(debug)("(0x%08lx,0x%08lx,0x%08lx): stub\n",x,y,z);
140 return TRUE;
143 /***********************************************************************
144 * GetSystemPowerStatus (KERNEL32.@)
146 BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS sps_ptr)
148 return FALSE; /* no power management support */
152 /***********************************************************************
153 * SetSystemPowerState (KERNEL32.@)
155 BOOL WINAPI SetSystemPowerState(BOOL suspend_or_hibernate,
156 BOOL force_flag)
158 /* suspend_or_hibernate flag: w95 does not support
159 this feature anyway */
161 for ( ;0; )
163 if ( force_flag )
166 else
170 return TRUE;
174 /******************************************************************************
175 * CreateMailslotA [KERNEL32.@]
177 HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
178 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa)
180 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_a(lpName),
181 nMaxMessageSize, lReadTimeout, sa);
182 return 1;
186 /******************************************************************************
187 * CreateMailslotW [KERNEL32.@] Creates a mailslot with specified name
189 * PARAMS
190 * lpName [I] Pointer to string for mailslot name
191 * nMaxMessageSize [I] Maximum message size
192 * lReadTimeout [I] Milliseconds before read time-out
193 * sa [I] Pointer to security structure
195 * RETURNS
196 * Success: Handle to mailslot
197 * Failure: INVALID_HANDLE_VALUE
199 HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
200 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
202 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName),
203 nMaxMessageSize, lReadTimeout, sa);
204 return 1;
208 /******************************************************************************
209 * GetMailslotInfo [KERNEL32.@] Retrieves info about specified mailslot
211 * PARAMS
212 * hMailslot [I] Mailslot handle
213 * lpMaxMessageSize [O] Address of maximum message size
214 * lpNextSize [O] Address of size of next message
215 * lpMessageCount [O] Address of number of messages
216 * lpReadTimeout [O] Address of read time-out
218 * RETURNS
219 * Success: TRUE
220 * Failure: FALSE
222 BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
223 LPDWORD lpNextSize, LPDWORD lpMessageCount,
224 LPDWORD lpReadTimeout )
226 FIXME("(%04x): stub\n",hMailslot);
227 if (lpMaxMessageSize) *lpMaxMessageSize = (DWORD)NULL;
228 if (lpNextSize) *lpNextSize = (DWORD)NULL;
229 if (lpMessageCount) *lpMessageCount = (DWORD)NULL;
230 if (lpReadTimeout) *lpReadTimeout = (DWORD)NULL;
231 return TRUE;
235 /******************************************************************************
236 * GetCompressedFileSizeA [KERNEL32.@]
238 * NOTES
239 * This should call the W function below
241 DWORD WINAPI GetCompressedFileSizeA(
242 LPCSTR lpFileName,
243 LPDWORD lpFileSizeHigh)
245 FIXME("(...): stub\n");
246 return 0xffffffff;
250 /******************************************************************************
251 * GetCompressedFileSizeW [KERNEL32.@]
253 * RETURNS
254 * Success: Low-order doubleword of number of bytes
255 * Failure: 0xffffffff
257 DWORD WINAPI GetCompressedFileSizeW(
258 LPCWSTR lpFileName, /* [in] Pointer to name of file */
259 LPDWORD lpFileSizeHigh) /* [out] Receives high-order doubleword of size */
261 FIXME("(%s,%p): stub\n",debugstr_w(lpFileName),lpFileSizeHigh);
262 return 0xffffffff;
266 /******************************************************************************
267 * SetComputerNameA [KERNEL32.@]
269 BOOL WINAPI SetComputerNameA( LPCSTR lpComputerName )
271 LPWSTR lpComputerNameW = HEAP_strdupAtoW(GetProcessHeap(),0,lpComputerName);
272 BOOL ret = SetComputerNameW(lpComputerNameW);
273 HeapFree(GetProcessHeap(),0,lpComputerNameW);
274 return ret;
278 /******************************************************************************
279 * SetComputerNameW [KERNEL32.@]
281 * PARAMS
282 * lpComputerName [I] Address of new computer name
284 * RETURNS STD
286 BOOL WINAPI SetComputerNameW( LPCWSTR lpComputerName )
288 FIXME("(%s): stub\n", debugstr_w(lpComputerName));
289 return TRUE;
292 /******************************************************************************
293 * CreateIoCompletionPort (KERNEL32.@)
295 HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle,
296 HANDLE hExistingCompletionPort, DWORD dwCompletionKey,
297 DWORD dwNumberOfConcurrentThreads)
299 FIXME("(%04x, %04x, %08lx, %08lx): stub.\n", hFileHandle, hExistingCompletionPort, dwCompletionKey, dwNumberOfConcurrentThreads);
300 return (HANDLE)NULL;
303 /******************************************************************************
304 * GetQueuedCompletionStatus (KERNEL32.@)
306 BOOL WINAPI GetQueuedCompletionStatus(
307 HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
308 LPDWORD lpCompletionKey, LPOVERLAPPED *lpOverlapped, DWORD dwMilliseconds
310 FIXME("(%x,%p,%p,%p,%ld), stub!\n",CompletionPort,lpNumberOfBytesTransferred,lpCompletionKey,lpOverlapped,dwMilliseconds);
311 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
312 return FALSE;