MSVC: fix stat definition hell

In msvc.h, there's a couple of stat related functions defined diffently from mingw.h. When we remove these definitions, the only problem we get is "warning C4005: '_stati64' : macro redefinition" for this line in mingw.h: #define _stati64(x,y) mingw_stat(x,y) The reason is that as of MSVCR80.dll (distributed with MSVC 2005), the original _stati64 family of functions was renamed to _stat32i64, and the former function names became macros (pointing to the appropriate function based on the definition of _USE_32BIT_TIME_T). Defining _stati64 works on MinGW because MinGW by default compiles against the MSVCRT.DLL that is part of Windows (i.e. _stati64 is a function rather than a macro). Note: MinGW *can* compile for newer MSVC runtime versions, and MSVC apparently can also compile for the Windows MSVCRT.DLL via the DDK (see http://www.syndicateofideas.com/posts/fighting-the-msvcrt-dll-hell ). Remove the stat definitions from msvc.h, as they are not compiler related. In mingw.h, determine the runtime version in use from the definitions of _stati64 and _USE_32BIT_TIME_T, and define stat() accordingly. This also fixes that stat() in MSVC builds still resolves to mingw_lstat() instead of mingw_stat(). Signed-off-by: Karsten Blees <blees@dcon.de> Acked-by: Sebastian Schuberth <sschuberth@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karsten Blees committed Sep 11, 2013 at 01:23 UTC a2374f58e86777258c11ed2d7855a28cd4219648
2 files changed +11 -19
compat/mingw.h
+11 -4
@@ -264,19 +264,26 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
264 return 0;
265 }
266
267 -/* Use mingw_lstat() instead of lstat()/stat() and
268 - * mingw_fstat() instead of fstat() on Windows.
267 +/*
268 + * Use mingw specific stat()/lstat()/fstat() implementations on Windows.
269 */
270 #define off_t off64_t
271 #define lseek _lseeki64
272 -#ifndef ALREADY_DECLARED_STAT_FUNCS
272 +
273 +/* use struct stat with 64 bit st_size */
274 #define stat _stati64
275 int mingw_lstat(const char *file_name, struct stat *buf);
276 int mingw_stat(const char *file_name, struct stat *buf);
277 int mingw_fstat(int fd, struct stat *buf);
278 #define fstat mingw_fstat
279 #define lstat mingw_lstat
279 -#define _stati64(x,y) mingw_stat(x,y)
280 +
281 +#ifndef _stati64
282 +# define _stati64(x,y) mingw_stat(x,y)
283 +#elif defined (_USE_32BIT_TIME_T)
284 +# define _stat32i64(x,y) mingw_stat(x,y)
285 +#else
286 +# define _stat64(x,y) mingw_stat(x,y)
287 #endif
288
289 int mingw_utime(const char *file_name, const struct utimbuf *times);
compat/msvc.h
-15
@@ -24,21 +24,6 @@ static __inline int strcasecmp (const char *s1, const char *s2)
24
25 #undef ERROR
26
27 -/* Use mingw_lstat() instead of lstat()/stat() and mingw_fstat() instead
28 - * of fstat(). We add the declaration of these functions here, suppressing
29 - * the corresponding declarations in mingw.h, so that we can use the
30 - * appropriate structure type (and function) names from the msvc headers.
31 - */
32 -#define stat _stat64
33 -int mingw_lstat(const char *file_name, struct stat *buf);
34 -int mingw_fstat(int fd, struct stat *buf);
35 -#define fstat mingw_fstat
36 -#define lstat mingw_lstat
37 -#define _stat64(x,y) mingw_lstat(x,y)
38 -#define ALREADY_DECLARED_STAT_FUNCS
39 -
27 #include "compat/mingw.h"
28
42 -#undef ALREADY_DECLARED_STAT_FUNCS
43 -
29 #endif