vbscript: Added support for title and type arguments of MsgBox.
[wine.git] / dlls / ntdll / misc.c
blobad1b43b3af858e97db1e247210183f937fb3daa1
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"
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;
74 if (!init_done)
76 uname( &buf );
77 init_done = TRUE;
79 if (sysname) *sysname = buf.sysname;
80 if (release) *release = buf.release;
81 #else
82 if (sysname) *sysname = "";
83 if (release) *release = "";
84 #endif
87 /*********************************************************************
88 * abs (NTDLL.@)
90 int CDECL NTDLL_abs( int i )
92 return abs( i );
95 /*********************************************************************
96 * labs (NTDLL.@)
98 LONG CDECL NTDLL_labs( LONG i )
100 return labs( i );
103 /*********************************************************************
104 * atan (NTDLL.@)
106 double CDECL NTDLL_atan( double d )
108 return atan( d );
111 /*********************************************************************
112 * ceil (NTDLL.@)
114 double CDECL NTDLL_ceil( double d )
116 return ceil( d );
119 /*********************************************************************
120 * cos (NTDLL.@)
122 double CDECL NTDLL_cos( double d )
124 return cos( d );
127 /*********************************************************************
128 * fabs (NTDLL.@)
130 double CDECL NTDLL_fabs( double d )
132 return fabs( d );
135 /*********************************************************************
136 * floor (NTDLL.@)
138 double CDECL NTDLL_floor( double d )
140 return floor( d );
143 /*********************************************************************
144 * log (NTDLL.@)
146 double CDECL NTDLL_log( double d )
148 return log( d );
151 /*********************************************************************
152 * pow (NTDLL.@)
154 double CDECL NTDLL_pow( double x, double y )
156 return pow( x, y );
159 /*********************************************************************
160 * sin (NTDLL.@)
162 double CDECL NTDLL_sin( double d )
164 return sin( d );
167 /*********************************************************************
168 * sqrt (NTDLL.@)
170 double CDECL NTDLL_sqrt( double d )
172 return sqrt( d );
175 /*********************************************************************
176 * tan (NTDLL.@)
178 double CDECL NTDLL_tan( double d )
180 return tan( 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 /*********************************************************************
192 * _CIcos (NTDLL.@)
194 double CDECL NTDLL__CIcos(void)
196 FPU_DOUBLE(x);
197 return NTDLL_cos(x);
200 /*********************************************************************
201 * _CIlog (NTDLL.@)
203 double CDECL NTDLL__CIlog(void)
205 FPU_DOUBLE(x);
206 return NTDLL_log(x);
209 /*********************************************************************
210 * _CIpow (NTDLL.@)
212 double CDECL NTDLL__CIpow(void)
214 FPU_DOUBLES(x,y);
215 return NTDLL_pow(x,y);
218 /*********************************************************************
219 * _CIsin (NTDLL.@)
221 double CDECL NTDLL__CIsin(void)
223 FPU_DOUBLE(x);
224 return NTDLL_sin(x);
227 /*********************************************************************
228 * _CIsqrt (NTDLL.@)
230 double CDECL NTDLL__CIsqrt(void)
232 FPU_DOUBLE(x);
233 return NTDLL_sqrt(x);
236 /*********************************************************************
237 * _ftol (NTDLL.@)
239 LONGLONG CDECL NTDLL__ftol(void)
241 FPU_DOUBLE(x);
242 return (LONGLONG)x;
245 #endif /* defined(__GNUC__) && defined(__i386__) */
247 static void
248 NTDLL_mergesort( void *arr, void *barr, size_t elemsize, int(__cdecl *compar)(const void *, const void *),
249 size_t left, size_t right )
251 if(right>left) {
252 size_t i, j, k, m;
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);
261 i++;
262 } else {
263 memcpy(X(barr,k), X(arr, j), elemsize);
264 j++;
267 if (i<=m)
268 memcpy(X(barr,k), X(arr,i), (m-i+1)*elemsize);
269 else
270 memcpy(X(barr,k), X(arr,j), (right-j+1)*elemsize);
272 memcpy(X(arr, left), X(barr, left), (right-left+1)*elemsize);
274 #undef X
277 /*********************************************************************
278 * qsort (NTDLL.@)
280 void __cdecl NTDLL_qsort( void *base, size_t nmemb, size_t size,
281 int(__cdecl *compar)(const void *, const void *) )
283 void *secondarr;
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 /*********************************************************************
291 * bsearch (NTDLL.@)
293 void * __cdecl
294 NTDLL_bsearch( const void *key, const void *base, size_t nmemb,
295 size_t size, int (__cdecl *compar)(const void *, const void *) )
297 ssize_t min = 0;
298 ssize_t max = nmemb - 1;
300 while (min <= max)
302 ssize_t cursor = min + (max - min) / 2;
303 int ret = compar(key,(const char *)base+(cursor*size));
304 if (!ret)
305 return (char*)base+(cursor*size);
306 if (ret < 0)
307 max = cursor - 1;
308 else
309 min = cursor + 1;
311 return NULL;
315 /*********************************************************************
316 * _lfind (NTDLL.@)
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;
323 for (i=0;i<n;i++)
324 if (!compar(key,(char*)base+(size*i)))
325 return (char*)base+(size*i);
326 return NULL;