quartz: Return increasing monitor GUID on VMR7 monitor enumeration.
[wine/multimedia.git] / dlls / ntdll / misc.c
blob8bd4eb795d85e4c8a4b27dd8dc56750aa1783a5f
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 #if defined(__GNUC__) && defined(__i386__)
36 #define DO_FPU(x,y) __asm__ __volatile__( x " %0;fwait" : "=m" (y) : )
37 #define POP_FPU(x) DO_FPU("fstpl",x)
38 #endif
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) / 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;