Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / msvcr90 / msvcr90.c
blob99ae9ed1312e1f5243b4316b0416c79b78fc79a0
1 /*
2 * msvcr90 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 "stdlib.h"
25 #include "stdio.h"
26 #include "errno.h"
27 #include "malloc.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wine/debug.h"
31 #include "sys/stat.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msvcr90);
35 #ifdef __i386__ /* thiscall functions are i386-specific */
37 #define THISCALL(func) __thiscall_ ## func
38 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
39 #define __thiscall __stdcall
40 #define DEFINE_THISCALL_WRAPPER(func,args) \
41 extern void THISCALL(func)(void); \
42 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
43 "popl %eax\n\t" \
44 "pushl %ecx\n\t" \
45 "pushl %eax\n\t" \
46 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
48 #else /* __i386__ */
50 #define THISCALL(func) func
51 #define THISCALL_NAME(func) __ASM_NAME(#func)
52 #define __thiscall __cdecl
53 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
55 #endif /* __i386__ */
57 struct __type_info_node
59 void *memPtr;
60 struct __type_info_node* next;
63 typedef struct __type_info
65 const void *vtable;
66 char *name; /* Unmangled name, allocated lazily */
67 char mangled[32]; /* Variable length, but we declare it large enough for static RTTI */
68 } type_info;
70 typedef void* (__cdecl *malloc_func_t)(size_t);
71 typedef void (__cdecl *free_func_t)(void*);
73 extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int);
75 /*********************************************************************
76 * msvcr90_stat64_to_stat32 [internal]
78 static void msvcr90_stat64_to_stat32(const struct _stat64 *buf64, struct _stat32 *buf)
80 buf->st_dev = buf64->st_dev;
81 buf->st_ino = buf64->st_ino;
82 buf->st_mode = buf64->st_mode;
83 buf->st_nlink = buf64->st_nlink;
84 buf->st_uid = buf64->st_uid;
85 buf->st_gid = buf64->st_gid;
86 buf->st_rdev = buf64->st_rdev;
87 buf->st_size = buf64->st_size;
88 buf->st_atime = buf64->st_atime;
89 buf->st_mtime = buf64->st_mtime;
90 buf->st_ctime = buf64->st_ctime;
93 /*********************************************************************
94 * DllMain (MSVCR90.@)
96 BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved)
98 switch (reason)
100 case DLL_WINE_PREATTACH:
101 return FALSE; /* prefer native version */
103 case DLL_PROCESS_ATTACH:
104 DisableThreadLibraryCalls(hdll);
105 _set_printf_count_output(0);
107 return TRUE;
110 /*********************************************************************
111 * _decode_pointer (MSVCR90.@)
113 * cdecl version of DecodePointer
116 void * CDECL MSVCR90_decode_pointer(void * ptr)
118 return DecodePointer(ptr);
121 /*********************************************************************
122 * _encode_pointer (MSVCR90.@)
124 * cdecl version of EncodePointer
127 void * CDECL MSVCR90_encode_pointer(void * ptr)
129 return EncodePointer(ptr);
132 /*********************************************************************
133 * _encoded_null (MSVCR90.@)
135 void * CDECL _encoded_null(void)
137 TRACE("\n");
139 return MSVCR90_encode_pointer(NULL);
142 /*********************************************************************
143 * _invalid_parameter_noinfo (MSVCR90.@)
145 void CDECL _invalid_parameter_noinfo(void)
147 _invalid_parameter( NULL, NULL, NULL, 0, 0 );
150 /*********************************************************************
151 * __sys_nerr (MSVCR90.@)
153 int* CDECL __sys_nerr(void)
155 return (int*)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_nerr");
158 /*********************************************************************
159 * __sys_errlist (MSVCR90.@)
161 char** CDECL __sys_errlist(void)
163 return (char**)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_errlist");
166 /*********************************************************************
167 * __clean_type_info_names_internal (MSVCR90.@)
169 void CDECL __clean_type_info_names_internal(void *p)
171 FIXME("(%p) stub\n", p);
174 /*********************************************************************
175 * _recalloc (MSVCR90.@)
177 void* CDECL _recalloc(void* mem, size_t num, size_t size)
179 size_t old_size;
180 void *ret;
182 if(!mem)
183 return calloc(num, size);
185 size = num*size;
186 old_size = _msize(mem);
188 ret = realloc(mem, size);
189 if(!ret) {
190 *_errno() = ENOMEM;
191 return NULL;
194 if(size>old_size)
195 memset((BYTE*)ret+old_size, 0, size-old_size);
196 return ret;
199 /*********************************************************************
200 * _fstat32 (MSVCR90.@)
202 int CDECL _fstat32(int fd, struct _stat32* buf)
204 int ret;
205 struct _stat64 buf64;
207 ret = _fstat64(fd, &buf64);
208 if (!ret)
209 msvcr90_stat64_to_stat32(&buf64, buf);
210 return ret;
213 /*********************************************************************
214 * _stat32 (MSVCR90.@)
216 int CDECL _stat32(const char *path, struct _stat32* buf)
218 int ret;
219 struct _stat64 buf64;
221 ret = _stat64(path, &buf64);
222 if (!ret)
223 msvcr90_stat64_to_stat32(&buf64, buf);
224 return ret;
227 /*********************************************************************
228 * _wstat32 (MSVCR90.@)
230 int CDECL _wstat32(const wchar_t *path, struct _stat32* buf)
232 int ret;
233 struct _stat64 buf64;
235 ret = _wstat64(path, &buf64);
236 if (!ret)
237 msvcr90_stat64_to_stat32(&buf64, buf);
238 return ret;
241 /*********************************************************************
242 * _fstat64i32 (MSVCRT.@)
245 static void msvcrt_stat64_to_stat64i32(const struct _stat64 *buf64, struct _stat64i32 *buf)
247 buf->st_dev = buf64->st_dev;
248 buf->st_ino = buf64->st_ino;
249 buf->st_mode = buf64->st_mode;
250 buf->st_nlink = buf64->st_nlink;
251 buf->st_uid = buf64->st_uid;
252 buf->st_gid = buf64->st_gid;
253 buf->st_rdev = buf64->st_rdev;
254 buf->st_size = buf64->st_size;
255 buf->st_atime = buf64->st_atime;
256 buf->st_mtime = buf64->st_mtime;
257 buf->st_ctime = buf64->st_ctime;
260 int CDECL _fstat64i32(int fd, struct _stat64i32* buf)
262 int ret;
263 struct _stat64 buf64;
265 ret = _fstat64(fd, &buf64);
266 if (!ret)
267 msvcrt_stat64_to_stat64i32(&buf64, buf);
268 return ret;
271 /*********************************************************************
272 * _stat64i32 (MSVCRT.@)
274 int CDECL _stat64i32(const char* path, struct _stat64i32 * buf)
276 int ret;
277 struct _stat64 buf64;
279 ret = _stat64(path, &buf64);
280 if (!ret)
281 msvcrt_stat64_to_stat64i32(&buf64, buf);
282 return ret;
285 /*********************************************************************
286 * _wstat64i32 (MSVCRT.@)
288 int CDECL _wstat64i32(const wchar_t *path, struct _stat64i32 *buf)
290 int ret;
291 struct _stat64 buf64;
293 ret = _wstat64(path, &buf64);
294 if (!ret)
295 msvcrt_stat64_to_stat64i32(&buf64, buf);
296 return ret;
299 /*********************************************************************
300 * _atoflt (MSVCR90.@)
302 int CDECL _atoflt( _CRT_FLOAT *value, char *str )
304 return _atoflt_l( value, str, NULL );
307 /*********************************************************************
308 * ?_name_internal_method@type_info@@QBEPBDPAU__type_info_node@@@Z (MSVCR90.@)
310 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_name_internal_method,8)
311 const char * __thiscall MSVCRT_type_info_name_internal_method(type_info * _this, struct __type_info_node *node)
313 static int once;
315 if (node && !once++) FIXME("type_info_node parameter ignored\n");
317 if (!_this->name)
319 /* Create and set the demangled name */
320 /* Note: mangled name in type_info struct always starts with a '.', while
321 * it isn't valid for mangled name.
322 * Is this '.' really part of the mangled name, or has it some other meaning ?
324 char* name = __unDName(0, _this->mangled + 1, 0, malloc, free, 0x2800);
325 if (name)
327 unsigned int len = strlen(name);
329 /* It seems _unDName may leave blanks at the end of the demangled name */
330 while (len && name[--len] == ' ')
331 name[len] = '\0';
333 if (InterlockedCompareExchangePointer((void**)&_this->name, name, NULL))
335 /* Another thread set this member since we checked above - use it */
336 free(name);
340 TRACE("(%p) returning %s\n", _this, _this->name);
341 return _this->name;
344 /*********************************************************************
345 * _CRT_RTC_INIT (MSVCR90.@)
347 void* CDECL _CRT_RTC_INIT(void *unk1, void *unk2, int unk3, int unk4, int unk5)
349 TRACE("%p %p %x %x %x\n", unk1, unk2, unk3, unk4, unk5);
350 return NULL;
353 /*********************************************************************
354 * _CRT_RTC_INITW (MSVCR90.@)
356 void* CDECL _CRT_RTC_INITW(void *unk1, void *unk2, int unk3, int unk4, int unk5)
358 TRACE("%p %p %x %x %x\n", unk1, unk2, unk3, unk4, unk5);
359 return NULL;
362 /*********************************************************************
363 * _vswprintf_p (MSVCR90.@)
365 int CDECL MSVCR90__vswprintf_p(wchar_t *buffer, size_t length, const wchar_t *format, __ms_va_list args)
367 return _vswprintf_p_l(buffer, length, format, NULL, args);
370 /*********************************************************************
371 * _byteswap_ushort (MSVCR90.@)
373 unsigned short CDECL _byteswap_ushort(unsigned short s)
375 return (s<<8) + (s>>8);
378 /*********************************************************************
379 * _byteswap_ulong (MSVCR90.@)
381 ULONG CDECL _byteswap_ulong(ULONG l)
383 return (l<<24) + ((l<<8)&0xFF0000) + ((l>>8)&0xFF00) + (l>>24);
386 /*********************************************************************
387 * _byteswap_uint64 (MSVCR90.@)
389 unsigned __int64 CDECL _byteswap_uint64(unsigned __int64 i)
391 return (i<<56) + ((i&0xFF00)<<40) + ((i&0xFF0000)<<24) + ((i&0xFF000000)<<8) +
392 ((i>>8)&0xFF000000) + ((i>>24)&0xFF0000) + ((i>>40)&0xFF00) + (i>>56);