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
26 #ifdef HAVE_SYS_UTSNAME_H
27 #include <sys/utsname.h>
30 #include "wine/library.h"
31 #include "wine/debug.h"
32 #include "ntdll_misc.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
36 LPCSTR
debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES
*oa
)
38 if (!oa
) return "<null>";
39 return wine_dbg_sprintf( "{name=%s, attr=0x%08x, hRoot=%p, sd=%p}\n",
40 debugstr_us(oa
->ObjectName
), oa
->Attributes
,
41 oa
->RootDirectory
, oa
->SecurityDescriptor
);
44 LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
46 if (!us
) return "<null>";
47 return debugstr_wn(us
->Buffer
, us
->Length
/ sizeof(WCHAR
));
50 /*********************************************************************
51 * wine_get_version (NTDLL.@)
53 const char * CDECL
NTDLL_wine_get_version(void)
55 return wine_get_version();
58 /*********************************************************************
59 * wine_get_build_id (NTDLL.@)
61 const char * CDECL
NTDLL_wine_get_build_id(void)
63 return wine_get_build_id();
66 /*********************************************************************
67 * wine_get_host_version (NTDLL.@)
69 void CDECL
NTDLL_wine_get_host_version( const char **sysname
, const char **release
)
71 #ifdef HAVE_SYS_UTSNAME_H
72 static struct utsname buf
;
73 static BOOL init_done
;
80 if (sysname
) *sysname
= buf
.sysname
;
81 if (release
) *release
= buf
.release
;
83 if (sysname
) *sysname
= "";
84 if (release
) *release
= "";
88 /*********************************************************************
91 int CDECL
NTDLL_abs( int i
)
96 /*********************************************************************
99 LONG CDECL
NTDLL_labs( LONG i
)
104 /*********************************************************************
107 double CDECL
NTDLL_atan( double d
)
112 /*********************************************************************
115 double CDECL
NTDLL_ceil( double d
)
120 /*********************************************************************
123 double CDECL
NTDLL_cos( double d
)
128 /*********************************************************************
131 double CDECL
NTDLL_fabs( double d
)
136 /*********************************************************************
139 double CDECL
NTDLL_floor( double d
)
144 /*********************************************************************
147 double CDECL
NTDLL_log( double d
)
152 /*********************************************************************
155 double CDECL
NTDLL_pow( double x
, double y
)
160 /*********************************************************************
163 double CDECL
NTDLL_sin( double d
)
168 /*********************************************************************
171 double CDECL
NTDLL_sqrt( double d
)
176 /*********************************************************************
179 double CDECL
NTDLL_tan( double d
)
184 #if defined(__GNUC__) && defined(__i386__)
186 #define FPU_DOUBLE(var) double var; \
187 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
188 #define FPU_DOUBLES(var1,var2) double var1,var2; \
189 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
190 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
192 /*********************************************************************
195 double CDECL
NTDLL__CIcos(void)
201 /*********************************************************************
204 double CDECL
NTDLL__CIlog(void)
210 /*********************************************************************
213 double CDECL
NTDLL__CIpow(void)
216 return NTDLL_pow(x
,y
);
219 /*********************************************************************
222 double CDECL
NTDLL__CIsin(void)
228 /*********************************************************************
231 double CDECL
NTDLL__CIsqrt(void)
234 return NTDLL_sqrt(x
);
237 /*********************************************************************
240 LONGLONG CDECL
NTDLL__ftol(void)
246 #endif /* defined(__GNUC__) && defined(__i386__) */
249 NTDLL_mergesort( void *arr
, void *barr
, size_t elemsize
, int(__cdecl
*compar
)(const void *, const void *),
250 size_t left
, size_t right
)
254 m
=left
+(right
-left
)/2;
255 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, left
, m
);
256 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, m
+1, right
);
258 #define X(a,i) ((char*)a+elemsize*(i))
259 for (k
=left
, i
=left
, j
=m
+1; i
<=m
&& j
<=right
; k
++) {
260 if (compar(X(arr
, i
), X(arr
,j
)) <= 0) {
261 memcpy(X(barr
,k
), X(arr
, i
), elemsize
);
264 memcpy(X(barr
,k
), X(arr
, j
), elemsize
);
269 memcpy(X(barr
,k
), X(arr
,i
), (m
-i
+1)*elemsize
);
271 memcpy(X(barr
,k
), X(arr
,j
), (right
-j
+1)*elemsize
);
273 memcpy(X(arr
, left
), X(barr
, left
), (right
-left
+1)*elemsize
);
278 /*********************************************************************
281 void __cdecl
NTDLL_qsort( void *base
, size_t nmemb
, size_t size
,
282 int(__cdecl
*compar
)(const void *, const void *) )
285 if (nmemb
< 2 || size
== 0) return;
286 secondarr
= RtlAllocateHeap (GetProcessHeap(), 0, nmemb
*size
);
287 NTDLL_mergesort( base
, secondarr
, size
, compar
, 0, nmemb
-1 );
288 RtlFreeHeap (GetProcessHeap(),0, secondarr
);
291 /*********************************************************************
295 NTDLL_bsearch( const void *key
, const void *base
, size_t nmemb
,
296 size_t size
, int (__cdecl
*compar
)(const void *, const void *) )
299 ssize_t max
= nmemb
- 1;
303 ssize_t cursor
= min
+ (max
- min
) / 2;
304 int ret
= compar(key
,(const char *)base
+(cursor
*size
));
306 return (char*)base
+(cursor
*size
);
316 /*********************************************************************
319 void * __cdecl
_lfind( const void *key
, const void *base
, unsigned int *nmemb
,
320 size_t size
, int(__cdecl
*compar
)(const void *, const void *) )
322 size_t i
, n
= *nmemb
;
325 if (!compar(key
,(char*)base
+(size
*i
)))
326 return (char*)base
+(size
*i
);
330 /*********************************************************************
331 * WinSqmIsOptedIn (NTDLL.@)
333 BOOL WINAPI
WinSqmIsOptedIn(void)