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"
35 LPCSTR
debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES
*oa
)
37 if (!oa
) return "<null>";
38 return wine_dbg_sprintf( "{name=%s, attr=0x%08x, hRoot=%p, sd=%p}\n",
39 debugstr_us(oa
->ObjectName
), oa
->Attributes
,
40 oa
->RootDirectory
, oa
->SecurityDescriptor
);
43 LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
45 if (!us
) return "<null>";
46 return debugstr_wn(us
->Buffer
, us
->Length
/ sizeof(WCHAR
));
49 /*********************************************************************
50 * wine_get_version (NTDLL.@)
52 const char * CDECL
NTDLL_wine_get_version(void)
54 return wine_get_version();
57 /*********************************************************************
58 * wine_get_build_id (NTDLL.@)
60 const char * CDECL
NTDLL_wine_get_build_id(void)
62 return wine_get_build_id();
65 /*********************************************************************
66 * wine_get_host_version (NTDLL.@)
68 void CDECL
NTDLL_wine_get_host_version( const char **sysname
, const char **release
)
70 #ifdef HAVE_SYS_UTSNAME_H
71 static struct utsname buf
;
72 static BOOL init_done
;
79 if (sysname
) *sysname
= buf
.sysname
;
80 if (release
) *release
= buf
.release
;
82 if (sysname
) *sysname
= "";
83 if (release
) *release
= "";
87 /*********************************************************************
90 int CDECL
NTDLL_abs( int i
)
95 /*********************************************************************
98 LONG CDECL
NTDLL_labs( LONG i
)
103 /*********************************************************************
106 double CDECL
NTDLL_atan( double d
)
111 /*********************************************************************
114 double CDECL
NTDLL_ceil( double d
)
119 /*********************************************************************
122 double CDECL
NTDLL_cos( double d
)
127 /*********************************************************************
130 double CDECL
NTDLL_fabs( double d
)
135 /*********************************************************************
138 double CDECL
NTDLL_floor( double d
)
143 /*********************************************************************
146 double CDECL
NTDLL_log( double d
)
151 /*********************************************************************
154 double CDECL
NTDLL_pow( double x
, double y
)
159 /*********************************************************************
162 double CDECL
NTDLL_sin( double d
)
167 /*********************************************************************
170 double CDECL
NTDLL_sqrt( double d
)
175 /*********************************************************************
178 double CDECL
NTDLL_tan( double d
)
183 #if defined(__GNUC__) && defined(__i386__)
185 #define FPU_DOUBLE(var) double var; \
186 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
187 #define FPU_DOUBLES(var1,var2) double var1,var2; \
188 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
189 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
191 /*********************************************************************
194 double CDECL
NTDLL__CIcos(void)
200 /*********************************************************************
203 double CDECL
NTDLL__CIlog(void)
209 /*********************************************************************
212 double CDECL
NTDLL__CIpow(void)
215 return NTDLL_pow(x
,y
);
218 /*********************************************************************
221 double CDECL
NTDLL__CIsin(void)
227 /*********************************************************************
230 double CDECL
NTDLL__CIsqrt(void)
233 return NTDLL_sqrt(x
);
236 /*********************************************************************
239 LONGLONG CDECL
NTDLL__ftol(void)
245 #endif /* defined(__GNUC__) && defined(__i386__) */
248 NTDLL_mergesort( void *arr
, void *barr
, size_t elemsize
, int(__cdecl
*compar
)(const void *, const void *),
249 size_t left
, size_t right
)
253 m
=left
+(right
-left
)/2;
254 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, left
, m
);
255 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, m
+1, right
);
257 #define X(a,i) ((char*)a+elemsize*(i))
258 for (k
=left
, i
=left
, j
=m
+1; i
<=m
&& j
<=right
; k
++) {
259 if (compar(X(arr
, i
), X(arr
,j
)) <= 0) {
260 memcpy(X(barr
,k
), X(arr
, i
), elemsize
);
263 memcpy(X(barr
,k
), X(arr
, j
), elemsize
);
268 memcpy(X(barr
,k
), X(arr
,i
), (m
-i
+1)*elemsize
);
270 memcpy(X(barr
,k
), X(arr
,j
), (right
-j
+1)*elemsize
);
272 memcpy(X(arr
, left
), X(barr
, left
), (right
-left
+1)*elemsize
);
277 /*********************************************************************
280 void __cdecl
NTDLL_qsort( void *base
, size_t nmemb
, size_t size
,
281 int(__cdecl
*compar
)(const void *, const void *) )
284 if (nmemb
< 2 || size
== 0) return;
285 secondarr
= RtlAllocateHeap (GetProcessHeap(), 0, nmemb
*size
);
286 NTDLL_mergesort( base
, secondarr
, size
, compar
, 0, nmemb
-1 );
287 RtlFreeHeap (GetProcessHeap(),0, secondarr
);
290 /*********************************************************************
294 NTDLL_bsearch( const void *key
, const void *base
, size_t nmemb
,
295 size_t size
, int (__cdecl
*compar
)(const void *, const void *) )
298 ssize_t max
= nmemb
- 1;
302 ssize_t cursor
= min
+ (max
- min
) / 2;
303 int ret
= compar(key
,(const char *)base
+(cursor
*size
));
305 return (char*)base
+(cursor
*size
);
315 /*********************************************************************
318 void * __cdecl
_lfind( const void *key
, const void *base
, unsigned int *nmemb
,
319 size_t size
, int(__cdecl
*compar
)(const void *, const void *) )
321 size_t i
, n
= *nmemb
;
324 if (!compar(key
,(char*)base
+(size
*i
)))
325 return (char*)base
+(size
*i
);