mshtml: Don't crash creating a URI if we have no document.
[wine.git] / dlls / ntdll / misc.c
blobf540c4ba2d8fba167549387be22a88cf47aae478
1 /*
2 * Helper functions for ntdll
4 * Copyright 2000 Juergen Schmied
5 * Copyright 2010 Marcus Meissner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #include <time.h>
25 #include <math.h>
26 #ifdef HAVE_SYS_UTSNAME_H
27 #include <sys/utsname.h>
28 #endif
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "wine/library.h"
33 #include "wine/debug.h"
34 #include "ntdll_misc.h"
35 #include "wmistr.h"
36 #include "evntrace.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
40 LPCSTR debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES *oa)
42 if (!oa) return "<null>";
43 return wine_dbg_sprintf( "{name=%s, attr=0x%08x, hRoot=%p, sd=%p}\n",
44 debugstr_us(oa->ObjectName), oa->Attributes,
45 oa->RootDirectory, oa->SecurityDescriptor );
48 LPCSTR debugstr_us( const UNICODE_STRING *us )
50 if (!us) return "<null>";
51 return debugstr_wn(us->Buffer, us->Length / sizeof(WCHAR));
54 /*********************************************************************
55 * wine_get_version (NTDLL.@)
57 const char * CDECL NTDLL_wine_get_version(void)
59 return wine_get_version();
62 /*********************************************************************
63 * wine_get_build_id (NTDLL.@)
65 const char * CDECL NTDLL_wine_get_build_id(void)
67 return wine_get_build_id();
70 /*********************************************************************
71 * wine_get_host_version (NTDLL.@)
73 void CDECL NTDLL_wine_get_host_version( const char **sysname, const char **release )
75 #ifdef HAVE_SYS_UTSNAME_H
76 static struct utsname buf;
77 static BOOL init_done;
79 if (!init_done)
81 uname( &buf );
82 init_done = TRUE;
84 if (sysname) *sysname = buf.sysname;
85 if (release) *release = buf.release;
86 #else
87 if (sysname) *sysname = "";
88 if (release) *release = "";
89 #endif
92 /*********************************************************************
93 * abs (NTDLL.@)
95 int CDECL NTDLL_abs( int i )
97 return abs( i );
100 /*********************************************************************
101 * labs (NTDLL.@)
103 LONG CDECL NTDLL_labs( LONG i )
105 return labs( i );
108 /*********************************************************************
109 * atan (NTDLL.@)
111 double CDECL NTDLL_atan( double d )
113 return atan( d );
116 /*********************************************************************
117 * ceil (NTDLL.@)
119 double CDECL NTDLL_ceil( double d )
121 return ceil( d );
124 /*********************************************************************
125 * cos (NTDLL.@)
127 double CDECL NTDLL_cos( double d )
129 return cos( d );
132 /*********************************************************************
133 * fabs (NTDLL.@)
135 double CDECL NTDLL_fabs( double d )
137 return fabs( d );
140 /*********************************************************************
141 * floor (NTDLL.@)
143 double CDECL NTDLL_floor( double d )
145 return floor( d );
148 /*********************************************************************
149 * log (NTDLL.@)
151 double CDECL NTDLL_log( double d )
153 return log( d );
156 /*********************************************************************
157 * pow (NTDLL.@)
159 double CDECL NTDLL_pow( double x, double y )
161 return pow( x, y );
164 /*********************************************************************
165 * sin (NTDLL.@)
167 double CDECL NTDLL_sin( double d )
169 return sin( d );
172 /*********************************************************************
173 * sqrt (NTDLL.@)
175 double CDECL NTDLL_sqrt( double d )
177 return sqrt( d );
180 /*********************************************************************
181 * tan (NTDLL.@)
183 double CDECL NTDLL_tan( double d )
185 return tan( d );
188 #if defined(__GNUC__) && defined(__i386__)
190 #define FPU_DOUBLE(var) double var; \
191 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
192 #define FPU_DOUBLES(var1,var2) double var1,var2; \
193 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
194 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
196 /*********************************************************************
197 * _CIcos (NTDLL.@)
199 double CDECL NTDLL__CIcos(void)
201 FPU_DOUBLE(x);
202 return NTDLL_cos(x);
205 /*********************************************************************
206 * _CIlog (NTDLL.@)
208 double CDECL NTDLL__CIlog(void)
210 FPU_DOUBLE(x);
211 return NTDLL_log(x);
214 /*********************************************************************
215 * _CIpow (NTDLL.@)
217 double CDECL NTDLL__CIpow(void)
219 FPU_DOUBLES(x,y);
220 return NTDLL_pow(x,y);
223 /*********************************************************************
224 * _CIsin (NTDLL.@)
226 double CDECL NTDLL__CIsin(void)
228 FPU_DOUBLE(x);
229 return NTDLL_sin(x);
232 /*********************************************************************
233 * _CIsqrt (NTDLL.@)
235 double CDECL NTDLL__CIsqrt(void)
237 FPU_DOUBLE(x);
238 return NTDLL_sqrt(x);
241 /*********************************************************************
242 * _ftol (NTDLL.@)
244 LONGLONG CDECL NTDLL__ftol(void)
246 FPU_DOUBLE(x);
247 return (LONGLONG)x;
250 #endif /* defined(__GNUC__) && defined(__i386__) */
252 static void
253 NTDLL_mergesort( void *arr, void *barr, size_t elemsize, int(__cdecl *compar)(const void *, const void *),
254 size_t left, size_t right )
256 if(right>left) {
257 size_t i, j, k, m;
258 m=left+(right-left)/2;
259 NTDLL_mergesort( arr, barr, elemsize, compar, left, m);
260 NTDLL_mergesort( arr, barr, elemsize, compar, m+1, right);
262 #define X(a,i) ((char*)a+elemsize*(i))
263 for (k=left, i=left, j=m+1; i<=m && j<=right; k++) {
264 if (compar(X(arr, i), X(arr,j)) <= 0) {
265 memcpy(X(barr,k), X(arr, i), elemsize);
266 i++;
267 } else {
268 memcpy(X(barr,k), X(arr, j), elemsize);
269 j++;
272 if (i<=m)
273 memcpy(X(barr,k), X(arr,i), (m-i+1)*elemsize);
274 else
275 memcpy(X(barr,k), X(arr,j), (right-j+1)*elemsize);
277 memcpy(X(arr, left), X(barr, left), (right-left+1)*elemsize);
279 #undef X
282 /*********************************************************************
283 * qsort (NTDLL.@)
285 void __cdecl NTDLL_qsort( void *base, size_t nmemb, size_t size,
286 int(__cdecl *compar)(const void *, const void *) )
288 void *secondarr;
289 if (nmemb < 2 || size == 0) return;
290 secondarr = RtlAllocateHeap (GetProcessHeap(), 0, nmemb*size);
291 NTDLL_mergesort( base, secondarr, size, compar, 0, nmemb-1 );
292 RtlFreeHeap (GetProcessHeap(),0, secondarr);
295 /*********************************************************************
296 * bsearch (NTDLL.@)
298 void * __cdecl
299 NTDLL_bsearch( const void *key, const void *base, size_t nmemb,
300 size_t size, int (__cdecl *compar)(const void *, const void *) )
302 ssize_t min = 0;
303 ssize_t max = nmemb - 1;
305 while (min <= max)
307 ssize_t cursor = min + (max - min) / 2;
308 int ret = compar(key,(const char *)base+(cursor*size));
309 if (!ret)
310 return (char*)base+(cursor*size);
311 if (ret < 0)
312 max = cursor - 1;
313 else
314 min = cursor + 1;
316 return NULL;
320 /*********************************************************************
321 * _lfind (NTDLL.@)
323 void * __cdecl _lfind( const void *key, const void *base, unsigned int *nmemb,
324 size_t size, int(__cdecl *compar)(const void *, const void *) )
326 size_t i, n = *nmemb;
328 for (i=0;i<n;i++)
329 if (!compar(key,(char*)base+(size*i)))
330 return (char*)base+(size*i);
331 return NULL;
334 /******************************************************************************
335 * WinSqmEndSession (NTDLL.@)
337 NTSTATUS WINAPI WinSqmEndSession(HANDLE session)
339 FIXME("(%p): stub\n", session);
340 return STATUS_NOT_IMPLEMENTED;
343 /*********************************************************************
344 * WinSqmIsOptedIn (NTDLL.@)
346 BOOL WINAPI WinSqmIsOptedIn(void)
348 FIXME("(): stub\n");
349 return FALSE;
352 /******************************************************************************
353 * WinSqmStartSession (NTDLL.@)
355 HANDLE WINAPI WinSqmStartSession(GUID *sessionguid, DWORD sessionid, DWORD unknown1)
357 FIXME("(%p, 0x%x, 0x%x): stub\n", sessionguid, sessionid, unknown1);
358 return INVALID_HANDLE_VALUE;
361 /******************************************************************************
362 * EtwRegisterTraceGuidsW (NTDLL.@)
364 * Register an event trace provider and the event trace classes that it uses
365 * to generate events.
367 * PARAMS
368 * RequestAddress [I] ControlCallback function
369 * RequestContext [I] Optional provider-defined context
370 * ControlGuid [I] GUID of the registering provider
371 * GuidCount [I] Number of elements in the TraceGuidReg array
372 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
373 * MofImagePath [I] not supported, set to NULL
374 * MofResourceName [I] not supported, set to NULL
375 * RegistrationHandle [O] Provider's registration handle
377 * RETURNS
378 * Success: ERROR_SUCCESS
379 * Failure: System error code
381 ULONG WINAPI EtwRegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
382 void *RequestContext, const GUID *ControlGuid, ULONG GuidCount,
383 TRACE_GUID_REGISTRATION *TraceGuidReg, const WCHAR *MofImagePath,
384 const WCHAR *MofResourceName, TRACEHANDLE *RegistrationHandle )
386 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress, RequestContext,
387 debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
388 debugstr_w(MofResourceName), RegistrationHandle);
390 if (TraceGuidReg)
392 ULONG i;
393 for (i = 0; i < GuidCount; i++)
395 FIXME(" register trace class %s\n", debugstr_guid(TraceGuidReg[i].Guid));
396 TraceGuidReg[i].RegHandle = (HANDLE)0xdeadbeef;
399 *RegistrationHandle = (TRACEHANDLE)0xdeadbeef;
400 return ERROR_SUCCESS;
403 /******************************************************************************
404 * EtwRegisterTraceGuidsA (NTDLL.@)
406 ULONG WINAPI EtwRegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
407 void *RequestContext, const GUID *ControlGuid, ULONG GuidCount,
408 TRACE_GUID_REGISTRATION *TraceGuidReg, const char *MofImagePath,
409 const char *MofResourceName, TRACEHANDLE *RegistrationHandle )
411 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress, RequestContext,
412 debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
413 debugstr_a(MofResourceName), RegistrationHandle);
414 return ERROR_SUCCESS;