include: Add HidD_GetSerialNumberString to ddk/hidsdi.h.
[wine.git] / dlls / ntdll / misc.c
blob0f6c5dfb93b6a1faf32ec94291175c3d5cd307ea
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 "wine/library.h"
31 #include "wine/debug.h"
32 #include "ntdll_misc.h"
33 #include "wmistr.h"
34 #include "evntrace.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
38 LPCSTR debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES *oa)
40 if (!oa) return "<null>";
41 return wine_dbg_sprintf( "{name=%s, attr=0x%08x, hRoot=%p, sd=%p}\n",
42 debugstr_us(oa->ObjectName), oa->Attributes,
43 oa->RootDirectory, oa->SecurityDescriptor );
46 LPCSTR debugstr_us( const UNICODE_STRING *us )
48 if (!us) return "<null>";
49 return debugstr_wn(us->Buffer, us->Length / sizeof(WCHAR));
52 /*********************************************************************
53 * wine_get_version (NTDLL.@)
55 const char * CDECL NTDLL_wine_get_version(void)
57 return wine_get_version();
60 /*********************************************************************
61 * wine_get_build_id (NTDLL.@)
63 const char * CDECL NTDLL_wine_get_build_id(void)
65 return wine_get_build_id();
68 /*********************************************************************
69 * wine_get_host_version (NTDLL.@)
71 void CDECL NTDLL_wine_get_host_version( const char **sysname, const char **release )
73 #ifdef HAVE_SYS_UTSNAME_H
74 static struct utsname buf;
75 static BOOL init_done;
77 if (!init_done)
79 uname( &buf );
80 init_done = TRUE;
82 if (sysname) *sysname = buf.sysname;
83 if (release) *release = buf.release;
84 #else
85 if (sysname) *sysname = "";
86 if (release) *release = "";
87 #endif
90 /*********************************************************************
91 * abs (NTDLL.@)
93 int CDECL NTDLL_abs( int i )
95 return abs( i );
98 /*********************************************************************
99 * labs (NTDLL.@)
101 LONG CDECL NTDLL_labs( LONG i )
103 return labs( i );
106 /*********************************************************************
107 * atan (NTDLL.@)
109 double CDECL NTDLL_atan( double d )
111 return atan( d );
114 /*********************************************************************
115 * ceil (NTDLL.@)
117 double CDECL NTDLL_ceil( double d )
119 return ceil( d );
122 /*********************************************************************
123 * cos (NTDLL.@)
125 double CDECL NTDLL_cos( double d )
127 return cos( d );
130 /*********************************************************************
131 * fabs (NTDLL.@)
133 double CDECL NTDLL_fabs( double d )
135 return fabs( d );
138 /*********************************************************************
139 * floor (NTDLL.@)
141 double CDECL NTDLL_floor( double d )
143 return floor( d );
146 /*********************************************************************
147 * log (NTDLL.@)
149 double CDECL NTDLL_log( double d )
151 return log( d );
154 /*********************************************************************
155 * pow (NTDLL.@)
157 double CDECL NTDLL_pow( double x, double y )
159 return pow( x, y );
162 /*********************************************************************
163 * sin (NTDLL.@)
165 double CDECL NTDLL_sin( double d )
167 return sin( d );
170 /*********************************************************************
171 * sqrt (NTDLL.@)
173 double CDECL NTDLL_sqrt( double d )
175 return sqrt( d );
178 /*********************************************************************
179 * tan (NTDLL.@)
181 double CDECL NTDLL_tan( double d )
183 return tan( d );
186 #if defined(__GNUC__) && defined(__i386__)
188 #define FPU_DOUBLE(var) double var; \
189 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
190 #define FPU_DOUBLES(var1,var2) double var1,var2; \
191 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
192 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
194 /*********************************************************************
195 * _CIcos (NTDLL.@)
197 double CDECL NTDLL__CIcos(void)
199 FPU_DOUBLE(x);
200 return NTDLL_cos(x);
203 /*********************************************************************
204 * _CIlog (NTDLL.@)
206 double CDECL NTDLL__CIlog(void)
208 FPU_DOUBLE(x);
209 return NTDLL_log(x);
212 /*********************************************************************
213 * _CIpow (NTDLL.@)
215 double CDECL NTDLL__CIpow(void)
217 FPU_DOUBLES(x,y);
218 return NTDLL_pow(x,y);
221 /*********************************************************************
222 * _CIsin (NTDLL.@)
224 double CDECL NTDLL__CIsin(void)
226 FPU_DOUBLE(x);
227 return NTDLL_sin(x);
230 /*********************************************************************
231 * _CIsqrt (NTDLL.@)
233 double CDECL NTDLL__CIsqrt(void)
235 FPU_DOUBLE(x);
236 return NTDLL_sqrt(x);
239 /*********************************************************************
240 * _ftol (NTDLL.@)
242 LONGLONG CDECL NTDLL__ftol(void)
244 FPU_DOUBLE(x);
245 return (LONGLONG)x;
248 #endif /* defined(__GNUC__) && defined(__i386__) */
250 static void
251 NTDLL_mergesort( void *arr, void *barr, size_t elemsize, int(__cdecl *compar)(const void *, const void *),
252 size_t left, size_t right )
254 if(right>left) {
255 size_t i, j, k, m;
256 m=left+(right-left)/2;
257 NTDLL_mergesort( arr, barr, elemsize, compar, left, m);
258 NTDLL_mergesort( arr, barr, elemsize, compar, m+1, right);
260 #define X(a,i) ((char*)a+elemsize*(i))
261 for (k=left, i=left, j=m+1; i<=m && j<=right; k++) {
262 if (compar(X(arr, i), X(arr,j)) <= 0) {
263 memcpy(X(barr,k), X(arr, i), elemsize);
264 i++;
265 } else {
266 memcpy(X(barr,k), X(arr, j), elemsize);
267 j++;
270 if (i<=m)
271 memcpy(X(barr,k), X(arr,i), (m-i+1)*elemsize);
272 else
273 memcpy(X(barr,k), X(arr,j), (right-j+1)*elemsize);
275 memcpy(X(arr, left), X(barr, left), (right-left+1)*elemsize);
277 #undef X
280 /*********************************************************************
281 * qsort (NTDLL.@)
283 void __cdecl NTDLL_qsort( void *base, size_t nmemb, size_t size,
284 int(__cdecl *compar)(const void *, const void *) )
286 void *secondarr;
287 if (nmemb < 2 || size == 0) return;
288 secondarr = RtlAllocateHeap (GetProcessHeap(), 0, nmemb*size);
289 NTDLL_mergesort( base, secondarr, size, compar, 0, nmemb-1 );
290 RtlFreeHeap (GetProcessHeap(),0, secondarr);
293 /*********************************************************************
294 * bsearch (NTDLL.@)
296 void * __cdecl
297 NTDLL_bsearch( const void *key, const void *base, size_t nmemb,
298 size_t size, int (__cdecl *compar)(const void *, const void *) )
300 ssize_t min = 0;
301 ssize_t max = nmemb - 1;
303 while (min <= max)
305 ssize_t cursor = min + (max - min) / 2;
306 int ret = compar(key,(const char *)base+(cursor*size));
307 if (!ret)
308 return (char*)base+(cursor*size);
309 if (ret < 0)
310 max = cursor - 1;
311 else
312 min = cursor + 1;
314 return NULL;
318 /*********************************************************************
319 * _lfind (NTDLL.@)
321 void * __cdecl _lfind( const void *key, const void *base, unsigned int *nmemb,
322 size_t size, int(__cdecl *compar)(const void *, const void *) )
324 size_t i, n = *nmemb;
326 for (i=0;i<n;i++)
327 if (!compar(key,(char*)base+(size*i)))
328 return (char*)base+(size*i);
329 return NULL;
332 /*********************************************************************
333 * WinSqmIsOptedIn (NTDLL.@)
335 BOOL WINAPI WinSqmIsOptedIn(void)
337 FIXME("() stub\n");
338 return FALSE;
341 /******************************************************************************
342 * EtwRegisterTraceGuidsW (NTDLL.@)
344 * Register an event trace provider and the event trace classes that it uses
345 * to generate events.
347 * PARAMS
348 * RequestAddress [I] ControlCallback function
349 * RequestContext [I] Optional provider-defined context
350 * ControlGuid [I] GUID of the registering provider
351 * GuidCount [I] Number of elements in the TraceGuidReg array
352 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
353 * MofImagePath [I] not supported, set to NULL
354 * MofResourceName [I] not supported, set to NULL
355 * RegistrationHandle [O] Provider's registration handle
357 * RETURNS
358 * Success: ERROR_SUCCESS
359 * Failure: System error code
361 ULONG WINAPI EtwRegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
362 void *RequestContext, const GUID *ControlGuid, ULONG GuidCount,
363 TRACE_GUID_REGISTRATION *TraceGuidReg, const WCHAR *MofImagePath,
364 const WCHAR *MofResourceName, TRACEHANDLE *RegistrationHandle )
366 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress, RequestContext,
367 debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
368 debugstr_w(MofResourceName), RegistrationHandle);
370 if (TraceGuidReg)
372 ULONG i;
373 for (i = 0; i < GuidCount; i++)
375 FIXME(" register trace class %s\n", debugstr_guid(TraceGuidReg[i].Guid));
376 TraceGuidReg[i].RegHandle = (HANDLE)0xdeadbeef;
379 *RegistrationHandle = (TRACEHANDLE)0xdeadbeef;
380 return ERROR_SUCCESS;
383 /******************************************************************************
384 * EtwRegisterTraceGuidsA (NTDLL.@)
386 ULONG WINAPI EtwRegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
387 void *RequestContext, const GUID *ControlGuid, ULONG GuidCount,
388 TRACE_GUID_REGISTRATION *TraceGuidReg, const char *MofImagePath,
389 const char *MofResourceName, TRACEHANDLE *RegistrationHandle )
391 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress, RequestContext,
392 debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
393 debugstr_a(MofResourceName), RegistrationHandle);
394 return ERROR_SUCCESS;