msvcrt: Implement ecvt_s.
[wine] / dlls / msvcr90 / msvcr90.c
1 /*
2  * msvcr90 specific functions
3  *
4  * Copyright 2010 Detlef Riekenberg
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "stdlib.h"
24 #include "errno.h"
25 #include "malloc.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wine/debug.h"
29 #include "sys/stat.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(msvcr90);
32
33 /*********************************************************************
34  *  DllMain (MSVCR90.@)
35  */
36 BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved)
37 {
38     switch (reason)
39     {
40     case DLL_WINE_PREATTACH:
41         return FALSE;  /* prefer native version */
42
43     case DLL_PROCESS_ATTACH:
44         DisableThreadLibraryCalls(hdll);
45     }
46     return TRUE;
47 }
48
49 /*********************************************************************
50  *  _decode_pointer (MSVCR90.@)
51  *
52  * cdecl version of DecodePointer
53  *
54  */
55 void * CDECL MSVCR90_decode_pointer(void * ptr)
56 {
57     return DecodePointer(ptr);
58 }
59
60 /*********************************************************************
61  *  _encode_pointer (MSVCR90.@)
62  *
63  * cdecl version of EncodePointer
64  *
65  */
66 void * CDECL MSVCR90_encode_pointer(void * ptr)
67 {
68     return EncodePointer(ptr);
69 }
70
71 /*********************************************************************
72  *  _encoded_null (MSVCR90.@)
73  */
74 void * CDECL _encoded_null(void)
75 {
76     TRACE("\n");
77
78     return MSVCR90_encode_pointer(NULL);
79 }
80
81 /*********************************************************************
82  * _invalid_parameter_noinfo (MSVCR90.@)
83  */
84 void CDECL _invalid_parameter_noinfo(void)
85 {
86     _invalid_parameter( NULL, NULL, NULL, 0, 0 );
87 }
88
89 /*********************************************************************
90  * __sys_nerr (MSVCR90.@)
91  */
92 int* CDECL __sys_nerr(void)
93 {
94         return (int*)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_nerr");
95 }
96
97 /*********************************************************************
98  *  __sys_errlist (MSVCR90.@)
99  */
100 char** CDECL __sys_errlist(void)
101 {
102     return (char**)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_errlist");
103 }
104
105 /*********************************************************************
106  * __clean_type_info_names_internal (MSVCR90.@)
107  */
108 void CDECL __clean_type_info_names_internal(void *p)
109 {
110     FIXME("(%p) stub\n", p);
111 }
112
113 /*********************************************************************
114  * _recalloc (MSVCR90.@)
115  */
116 void* CDECL _recalloc(void* mem, size_t num, size_t size)
117 {
118     size_t old_size;
119     void *ret;
120
121     if(!mem)
122         return calloc(num, size);
123
124     size = num*size;
125     old_size = _msize(mem);
126
127     ret = realloc(mem, size);
128     if(!ret) {
129         *_errno() = ENOMEM;
130         return NULL;
131     }
132
133     if(size>old_size)
134         memset((BYTE*)mem+old_size, 0, size-old_size);
135     return ret;
136 }
137
138 /*********************************************************************
139  *              _fstat64i32 (MSVCRT.@)
140  */
141
142 static void msvcrt_stat64_to_stat64i32(const struct _stat64 *buf64, struct _stat64i32 *buf)
143 {
144     buf->st_dev   = buf64->st_dev;
145     buf->st_ino   = buf64->st_ino;
146     buf->st_mode  = buf64->st_mode;
147     buf->st_nlink = buf64->st_nlink;
148     buf->st_uid   = buf64->st_uid;
149     buf->st_gid   = buf64->st_gid;
150     buf->st_rdev  = buf64->st_rdev;
151     buf->st_size  = buf64->st_size;
152     buf->st_atime = buf64->st_atime;
153     buf->st_mtime = buf64->st_mtime;
154     buf->st_ctime = buf64->st_ctime;
155 }
156
157 int CDECL _fstat64i32(int fd, struct _stat64i32* buf)
158 {
159   int ret;
160   struct _stat64 buf64;
161
162   ret = _fstat64(fd, &buf64);
163   if (!ret)
164       msvcrt_stat64_to_stat64i32(&buf64, buf);
165   return ret;
166 }
167
168 /*********************************************************************
169  *              _stat64i32 (MSVCRT.@)
170  */
171 int CDECL _stat64i32(const char* path, struct _stat64i32 * buf)
172 {
173   int ret;
174   struct _stat64 buf64;
175
176   ret = _stat64(path, &buf64);
177   if (!ret)
178     msvcrt_stat64_to_stat64i32(&buf64, buf);
179   return ret;
180 }
181
182 /*********************************************************************
183  *              _wstat64i32 (MSVCRT.@)
184  */
185 int CDECL _wstat64i32(const wchar_t *path, struct _stat64i32 *buf)
186 {
187     int ret;
188     struct _stat64 buf64;
189
190     ret = _wstat64(path, &buf64);
191     if (!ret)
192         msvcrt_stat64_to_stat64i32(&buf64, buf);
193     return ret;
194 }