msvcr90: Implement _stat32, _fstat32, _wstat32.
[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  *  msvcr90_stat64_to_stat32 [internal]
35  */
36 static void msvcr90_stat64_to_stat32(const struct _stat64 *buf64, struct _stat32 *buf)
37 {
38     buf->st_dev   = buf64->st_dev;
39     buf->st_ino   = buf64->st_ino;
40     buf->st_mode  = buf64->st_mode;
41     buf->st_nlink = buf64->st_nlink;
42     buf->st_uid   = buf64->st_uid;
43     buf->st_gid   = buf64->st_gid;
44     buf->st_rdev  = buf64->st_rdev;
45     buf->st_size  = buf64->st_size;
46     buf->st_atime = buf64->st_atime;
47     buf->st_mtime = buf64->st_mtime;
48     buf->st_ctime = buf64->st_ctime;
49 }
50
51 /*********************************************************************
52  *  DllMain (MSVCR90.@)
53  */
54 BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved)
55 {
56     switch (reason)
57     {
58     case DLL_WINE_PREATTACH:
59         return FALSE;  /* prefer native version */
60
61     case DLL_PROCESS_ATTACH:
62         DisableThreadLibraryCalls(hdll);
63     }
64     return TRUE;
65 }
66
67 /*********************************************************************
68  *  _decode_pointer (MSVCR90.@)
69  *
70  * cdecl version of DecodePointer
71  *
72  */
73 void * CDECL MSVCR90_decode_pointer(void * ptr)
74 {
75     return DecodePointer(ptr);
76 }
77
78 /*********************************************************************
79  *  _encode_pointer (MSVCR90.@)
80  *
81  * cdecl version of EncodePointer
82  *
83  */
84 void * CDECL MSVCR90_encode_pointer(void * ptr)
85 {
86     return EncodePointer(ptr);
87 }
88
89 /*********************************************************************
90  *  _encoded_null (MSVCR90.@)
91  */
92 void * CDECL _encoded_null(void)
93 {
94     TRACE("\n");
95
96     return MSVCR90_encode_pointer(NULL);
97 }
98
99 /*********************************************************************
100  * _invalid_parameter_noinfo (MSVCR90.@)
101  */
102 void CDECL _invalid_parameter_noinfo(void)
103 {
104     _invalid_parameter( NULL, NULL, NULL, 0, 0 );
105 }
106
107 /*********************************************************************
108  * __sys_nerr (MSVCR90.@)
109  */
110 int* CDECL __sys_nerr(void)
111 {
112         return (int*)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_nerr");
113 }
114
115 /*********************************************************************
116  *  __sys_errlist (MSVCR90.@)
117  */
118 char** CDECL __sys_errlist(void)
119 {
120     return (char**)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_errlist");
121 }
122
123 /*********************************************************************
124  * __clean_type_info_names_internal (MSVCR90.@)
125  */
126 void CDECL __clean_type_info_names_internal(void *p)
127 {
128     FIXME("(%p) stub\n", p);
129 }
130
131 /*********************************************************************
132  * _recalloc (MSVCR90.@)
133  */
134 void* CDECL _recalloc(void* mem, size_t num, size_t size)
135 {
136     size_t old_size;
137     void *ret;
138
139     if(!mem)
140         return calloc(num, size);
141
142     size = num*size;
143     old_size = _msize(mem);
144
145     ret = realloc(mem, size);
146     if(!ret) {
147         *_errno() = ENOMEM;
148         return NULL;
149     }
150
151     if(size>old_size)
152         memset((BYTE*)mem+old_size, 0, size-old_size);
153     return ret;
154 }
155
156 /*********************************************************************
157  *  _fstat32 (MSVCR90.@)
158  */
159 int CDECL _fstat32(int fd, struct _stat32* buf)
160 {
161   int ret;
162   struct _stat64 buf64;
163
164   ret = _fstat64(fd, &buf64);
165   if (!ret)
166       msvcr90_stat64_to_stat32(&buf64, buf);
167   return ret;
168 }
169
170 /*********************************************************************
171  *  _stat32 (MSVCR90.@)
172  */
173 int CDECL _stat32(const char *path, struct _stat32* buf)
174 {
175   int ret;
176   struct _stat64 buf64;
177
178   ret = _stat64(path, &buf64);
179   if (!ret)
180       msvcr90_stat64_to_stat32(&buf64, buf);
181   return ret;
182 }
183
184 /*********************************************************************
185  *  _wstat32 (MSVCR90.@)
186  */
187 int CDECL _wstat32(const wchar_t *path, struct _stat32* buf)
188 {
189   int ret;
190   struct _stat64 buf64;
191
192   ret = _wstat64(path, &buf64);
193   if (!ret)
194       msvcr90_stat64_to_stat32(&buf64, buf);
195   return ret;
196 }
197
198 /*********************************************************************
199  *              _fstat64i32 (MSVCRT.@)
200  */
201
202 static void msvcrt_stat64_to_stat64i32(const struct _stat64 *buf64, struct _stat64i32 *buf)
203 {
204     buf->st_dev   = buf64->st_dev;
205     buf->st_ino   = buf64->st_ino;
206     buf->st_mode  = buf64->st_mode;
207     buf->st_nlink = buf64->st_nlink;
208     buf->st_uid   = buf64->st_uid;
209     buf->st_gid   = buf64->st_gid;
210     buf->st_rdev  = buf64->st_rdev;
211     buf->st_size  = buf64->st_size;
212     buf->st_atime = buf64->st_atime;
213     buf->st_mtime = buf64->st_mtime;
214     buf->st_ctime = buf64->st_ctime;
215 }
216
217 int CDECL _fstat64i32(int fd, struct _stat64i32* buf)
218 {
219   int ret;
220   struct _stat64 buf64;
221
222   ret = _fstat64(fd, &buf64);
223   if (!ret)
224       msvcrt_stat64_to_stat64i32(&buf64, buf);
225   return ret;
226 }
227
228 /*********************************************************************
229  *              _stat64i32 (MSVCRT.@)
230  */
231 int CDECL _stat64i32(const char* path, struct _stat64i32 * buf)
232 {
233   int ret;
234   struct _stat64 buf64;
235
236   ret = _stat64(path, &buf64);
237   if (!ret)
238     msvcrt_stat64_to_stat64i32(&buf64, buf);
239   return ret;
240 }
241
242 /*********************************************************************
243  *              _wstat64i32 (MSVCRT.@)
244  */
245 int CDECL _wstat64i32(const wchar_t *path, struct _stat64i32 *buf)
246 {
247     int ret;
248     struct _stat64 buf64;
249
250     ret = _wstat64(path, &buf64);
251     if (!ret)
252         msvcrt_stat64_to_stat64i32(&buf64, buf);
253     return ret;
254 }
255
256 /*********************************************************************
257  *              _atoflt  (MSVCR90.@)
258  */
259 int CDECL _atoflt( _CRT_FLOAT *value, char *str )
260 {
261     return _atoflt_l( value, str, NULL );
262 }