wined3d: Pass a wined3d_resource_desc structure to wined3d_texture_create_3d().
[wine/multimedia.git] / dlls / msvcr100 / msvcr100.c
blobd425455287244aa9820981be683829dc8c0b6673
1 /*
2 * msvcr100 specific functions
4 * Copyright 2010 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include <stdarg.h>
24 #include "stdio.h"
25 #include "stdlib.h"
26 #include "errno.h"
27 #include "malloc.h"
28 #include "limits.h"
29 #include "sys/stat.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
36 #define INVALID_PMT(x,err) (*_errno() = (err), _invalid_parameter(NULL, NULL, NULL, 0, 0))
37 #define CHECK_PMT_ERR(x,err) ((x) || (INVALID_PMT( 0, (err) ), FALSE))
38 #define CHECK_PMT(x) CHECK_PMT_ERR((x), EINVAL)
40 #ifdef __i386__ /* thiscall functions are i386-specific */
42 #define THISCALL(func) __thiscall_ ## func
43 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
44 #define __thiscall __stdcall
45 #define DEFINE_THISCALL_WRAPPER(func,args) \
46 extern void THISCALL(func)(void); \
47 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
48 "popl %eax\n\t" \
49 "pushl %ecx\n\t" \
50 "pushl %eax\n\t" \
51 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
53 #else /* __i386__ */
55 #define THISCALL(func) func
56 #define THISCALL_NAME(func) __ASM_NAME(#func)
57 #define __thiscall __cdecl
58 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
60 #endif /* __i386__ */
62 struct __type_info_node
64 void *memPtr;
65 struct __type_info_node* next;
68 typedef struct __type_info
70 const void *vtable;
71 char *name; /* Unmangled name, allocated lazily */
72 char mangled[32]; /* Variable length, but we declare it large enough for static RTTI */
73 } type_info;
75 typedef void* (__cdecl *malloc_func_t)(size_t);
76 typedef void (__cdecl *free_func_t)(void*);
78 extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int);
80 /*********************************************************************
81 * stat64_to_stat32 [internal]
83 static void stat64_to_stat32(const struct _stat64 *buf64, struct _stat32 *buf)
85 buf->st_dev = buf64->st_dev;
86 buf->st_ino = buf64->st_ino;
87 buf->st_mode = buf64->st_mode;
88 buf->st_nlink = buf64->st_nlink;
89 buf->st_uid = buf64->st_uid;
90 buf->st_gid = buf64->st_gid;
91 buf->st_rdev = buf64->st_rdev;
92 buf->st_size = buf64->st_size;
93 buf->st_atime = buf64->st_atime;
94 buf->st_mtime = buf64->st_mtime;
95 buf->st_ctime = buf64->st_ctime;
98 /*********************************************************************
99 * wmemcpy_s (MSVCR100.@)
101 int CDECL wmemcpy_s(wchar_t *dest, size_t numberOfElements, const wchar_t *src, size_t count)
103 TRACE("(%p %lu %p %lu)\n", dest, (unsigned long)numberOfElements, src, (unsigned long)count);
105 if (!count)
106 return 0;
108 if (!CHECK_PMT(dest != NULL)) return EINVAL;
110 if (!CHECK_PMT(src != NULL)) {
111 memset(dest, 0, numberOfElements*sizeof(wchar_t));
112 return EINVAL;
114 if (!CHECK_PMT_ERR(count <= numberOfElements, ERANGE)) {
115 memset(dest, 0, numberOfElements*sizeof(wchar_t));
116 return ERANGE;
119 memcpy(dest, src, sizeof(wchar_t)*count);
120 return 0;
123 /*********************************************************************
124 * wmemmove_s (MSVCR100.@)
126 int CDECL wmemmove_s(wchar_t *dest, size_t numberOfElements, const wchar_t *src, size_t count)
128 TRACE("(%p %lu %p %lu)\n", dest, (unsigned long)numberOfElements, src, (unsigned long)count);
130 if (!count)
131 return 0;
133 /* Native does not seem to conform to 6.7.1.2.3 in
134 * http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1225.pdf
135 * in that it does not zero the output buffer on constraint violation.
137 if (!CHECK_PMT(dest != NULL)) return EINVAL;
138 if (!CHECK_PMT(src != NULL)) return EINVAL;
139 if (!CHECK_PMT_ERR(count <= numberOfElements, ERANGE)) return ERANGE;
141 memmove(dest, src, sizeof(wchar_t)*count);
142 return 0;
145 /*********************************************************************
146 * _encoded_null (MSVCR100.@)
148 void * CDECL _encoded_null(void)
150 TRACE("\n");
152 return EncodePointer(NULL);
155 /*********************************************************************
156 * _invalid_parameter_noinfo (MSVCR100.@)
158 void CDECL _invalid_parameter_noinfo(void)
160 _invalid_parameter( NULL, NULL, NULL, 0, 0 );
163 /*********************************************************************
164 * __sys_nerr (MSVCR100.@)
166 int* CDECL __sys_nerr(void)
168 return (int*)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_nerr");
171 /*********************************************************************
172 * __sys_errlist (MSVCR100.@)
174 char** CDECL __sys_errlist(void)
176 return (char**)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_errlist");
179 /*********************************************************************
180 * __clean_type_info_names_internal (MSVCR100.@)
182 void CDECL __clean_type_info_names_internal(void *p)
184 FIXME("(%p) stub\n", p);
187 /*********************************************************************
188 * _recalloc (MSVCR100.@)
190 void* CDECL _recalloc(void* mem, size_t num, size_t size)
192 size_t old_size;
193 void *ret;
195 if(!mem)
196 return calloc(num, size);
198 size = num*size;
199 old_size = _msize(mem);
201 ret = realloc(mem, size);
202 if(!ret) {
203 *_errno() = ENOMEM;
204 return NULL;
207 if(size>old_size)
208 memset((BYTE*)ret+old_size, 0, size-old_size);
209 return ret;
212 /*********************************************************************
213 * _stat32 (MSVCR100.@)
215 int CDECL _stat32(const char *path, struct _stat32* buf)
217 int ret;
218 struct _stat64 buf64;
220 ret = _stat64(path, &buf64);
221 if (!ret)
222 stat64_to_stat32(&buf64, buf);
223 return ret;
226 /*********************************************************************
227 * _wstat32 (MSVCR100.@)
229 int CDECL _wstat32(const wchar_t *path, struct _stat32* buf)
231 int ret;
232 struct _stat64 buf64;
234 ret = _wstat64(path, &buf64);
235 if (!ret)
236 stat64_to_stat32(&buf64, buf);
237 return ret;
240 static void stat64_to_stat32i64(const struct _stat64 *buf64, struct _stat32i64 *buf)
242 buf->st_dev = buf64->st_dev;
243 buf->st_ino = buf64->st_ino;
244 buf->st_mode = buf64->st_mode;
245 buf->st_nlink = buf64->st_nlink;
246 buf->st_uid = buf64->st_uid;
247 buf->st_gid = buf64->st_gid;
248 buf->st_rdev = buf64->st_rdev;
249 buf->st_size = buf64->st_size;
250 buf->st_atime = buf64->st_atime;
251 buf->st_mtime = buf64->st_mtime;
252 buf->st_ctime = buf64->st_ctime;
255 /*********************************************************************
256 * _stat32i64 (MSVCR100.@)
258 int CDECL _stat32i64(const char *path, struct _stat32i64* buf)
260 int ret;
261 struct _stat64 buf64;
263 ret = _stat64(path, &buf64);
264 if (!ret)
265 stat64_to_stat32i64(&buf64, buf);
266 return ret;
269 /*********************************************************************
270 * _wstat32i64 (MSVCR100.@)
272 int CDECL _wstat32i64(const wchar_t *path, struct _stat32i64* buf)
274 int ret;
275 struct _stat64 buf64;
277 ret = _wstat64(path, &buf64);
278 if (!ret)
279 stat64_to_stat32i64(&buf64, buf);
280 return ret;
283 static void stat64_to_stat64i32(const struct _stat64 *buf64, struct _stat64i32 *buf)
285 buf->st_dev = buf64->st_dev;
286 buf->st_ino = buf64->st_ino;
287 buf->st_mode = buf64->st_mode;
288 buf->st_nlink = buf64->st_nlink;
289 buf->st_uid = buf64->st_uid;
290 buf->st_gid = buf64->st_gid;
291 buf->st_rdev = buf64->st_rdev;
292 buf->st_size = buf64->st_size;
293 buf->st_atime = buf64->st_atime;
294 buf->st_mtime = buf64->st_mtime;
295 buf->st_ctime = buf64->st_ctime;
298 /*********************************************************************
299 * _stat64i32 (MSVCR100.@)
301 int CDECL _stat64i32(const char* path, struct _stat64i32 * buf)
303 int ret;
304 struct _stat64 buf64;
306 ret = _stat64(path, &buf64);
307 if (!ret)
308 stat64_to_stat64i32(&buf64, buf);
309 return ret;
312 /*********************************************************************
313 * _wstat64i32 (MSVCR100.@)
315 int CDECL _wstat64i32(const wchar_t *path, struct _stat64i32 *buf)
317 int ret;
318 struct _stat64 buf64;
320 ret = _wstat64(path, &buf64);
321 if (!ret)
322 stat64_to_stat64i32(&buf64, buf);
323 return ret;
326 /*********************************************************************
327 * _atoflt (MSVCR100.@)
329 int CDECL _atoflt( _CRT_FLOAT *value, char *str )
331 return _atoflt_l( value, str, NULL );
334 /*********************************************************************
335 * ?_name_internal_method@type_info@@QBEPBDPAU__type_info_node@@@Z (MSVCR100.@)
337 DEFINE_THISCALL_WRAPPER(type_info_name_internal_method,8)
338 const char * __thiscall type_info_name_internal_method(type_info * _this, struct __type_info_node *node)
340 static int once;
342 if (node && !once++) FIXME("type_info_node parameter ignored\n");
344 if (!_this->name)
346 /* Create and set the demangled name */
347 /* Note: mangled name in type_info struct always starts with a '.', while
348 * it isn't valid for mangled name.
349 * Is this '.' really part of the mangled name, or has it some other meaning ?
351 char* name = __unDName(0, _this->mangled + 1, 0, malloc, free, 0x2800);
352 if (name)
354 unsigned int len = strlen(name);
356 /* It seems _unDName may leave blanks at the end of the demangled name */
357 while (len && name[--len] == ' ')
358 name[len] = '\0';
360 if (InterlockedCompareExchangePointer((void**)&_this->name, name, NULL))
362 /* Another thread set this member since we checked above - use it */
363 free(name);
367 TRACE("(%p) returning %s\n", _this, _this->name);
368 return _this->name;
371 /*********************************************************************
372 * _CRT_RTC_INIT (MSVCR100.@)
374 void* CDECL _CRT_RTC_INIT(void *unk1, void *unk2, int unk3, int unk4, int unk5)
376 TRACE("%p %p %x %x %x\n", unk1, unk2, unk3, unk4, unk5);
377 return NULL;
380 /*********************************************************************
381 * _CRT_RTC_INITW (MSVCR100.@)
383 void* CDECL _CRT_RTC_INITW(void *unk1, void *unk2, int unk3, int unk4, int unk5)
385 TRACE("%p %p %x %x %x\n", unk1, unk2, unk3, unk4, unk5);
386 return NULL;
389 /*********************************************************************
390 * _vswprintf_p (MSVCR100.@)
392 int CDECL _vswprintf_p(wchar_t *buffer, size_t length, const wchar_t *format, __ms_va_list args)
394 return _vswprintf_p_l(buffer, length, format, NULL, args);
397 /*********************************************************************
398 * _vscwprintf_p (MSVCR100.@)
400 int CDECL _vscwprintf_p(const wchar_t *format, __ms_va_list args)
402 return _vscwprintf_p_l(format, NULL, args);
405 /*********************************************************************
406 * _byteswap_ushort (MSVCR100.@)
408 unsigned short CDECL _byteswap_ushort(unsigned short s)
410 return (s<<8) + (s>>8);
413 /*********************************************************************
414 * _byteswap_ulong (MSVCR100.@)
416 ULONG CDECL _byteswap_ulong(ULONG l)
418 return (l<<24) + ((l<<8)&0xFF0000) + ((l>>8)&0xFF00) + (l>>24);
421 /*********************************************************************
422 * _byteswap_uint64 (MSVCR100.@)
424 unsigned __int64 CDECL _byteswap_uint64(unsigned __int64 i)
426 return (i<<56) + ((i&0xFF00)<<40) + ((i&0xFF0000)<<24) + ((i&0xFF000000)<<8) +
427 ((i>>8)&0xFF000000) + ((i>>24)&0xFF0000) + ((i>>40)&0xFF00) + (i>>56);
430 /*********************************************************************
431 * _sprintf_p (MSVCR100.@)
433 int CDECL _sprintf_p(char *buffer, size_t length, const char *format, ...)
435 __ms_va_list valist;
436 int r;
438 __ms_va_start(valist, format);
439 r = _vsprintf_p_l(buffer, length, format, NULL, valist);
440 __ms_va_end(valist);
442 return r;
445 /*********************************************************************
446 * _get_timezone (MSVCR100.@)
448 int CDECL _get_timezone(LONG *timezone)
450 if(!CHECK_PMT(timezone != NULL)) return EINVAL;
452 *timezone = *(LONG*)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_timezone");
453 return 0;
456 /*********************************************************************
457 * _get_daylight (MSVCR100.@)
459 int CDECL _get_daylight(int *hours)
461 if(!CHECK_PMT(hours != NULL)) return EINVAL;
463 *hours = *(int*)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_daylight");
464 return 0;
467 /* copied from dlls/msvcrt/heap.c */
468 #define SAVED_PTR(x) ((void *)((DWORD_PTR)((char *)x - sizeof(void *)) & \
469 ~(sizeof(void *) - 1)))
471 /*********************************************************************
472 * _aligned_msize (MSVCR100.@)
474 size_t CDECL _aligned_msize(void *p, size_t alignment, size_t offset)
476 void **alloc_ptr;
478 if(!CHECK_PMT(p)) return -1;
480 if(alignment < sizeof(void*))
481 alignment = sizeof(void*);
483 alloc_ptr = SAVED_PTR(p);
484 return _msize(*alloc_ptr)-alignment-sizeof(void*);
487 int CDECL MSVCR100_atoi(const char *str)
489 return _atoi_l(str, NULL);
492 /*********************************************************************
493 * DllMain (MSVCR100.@)
495 BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved)
497 switch (reason)
499 case DLL_WINE_PREATTACH:
500 return FALSE; /* prefer native version */
502 case DLL_PROCESS_ATTACH:
503 DisableThreadLibraryCalls(hdll);
504 _set_printf_count_output(0);
506 return TRUE;