Skip to content

Commit b543717

Browse files
kbleessschuberth
authored andcommitted
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>
1 parent 617433c commit b543717

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

compat/mingw.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,26 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
271271
return 0;
272272
}
273273

274-
/* Use mingw_lstat() instead of lstat()/stat() and
275-
* mingw_fstat() instead of fstat() on Windows.
274+
/*
275+
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
276276
*/
277277
#define off_t off64_t
278278
#define lseek _lseeki64
279-
#ifndef ALREADY_DECLARED_STAT_FUNCS
279+
280+
/* use struct stat with 64 bit st_size */
280281
#define stat _stati64
281282
int mingw_lstat(const char *file_name, struct stat *buf);
282283
int mingw_stat(const char *file_name, struct stat *buf);
283284
int mingw_fstat(int fd, struct stat *buf);
284285
#define fstat mingw_fstat
285286
#define lstat mingw_lstat
286-
#define _stati64(x,y) mingw_stat(x,y)
287+
288+
#ifndef _stati64
289+
# define _stati64(x,y) mingw_stat(x,y)
290+
#elif defined (_USE_32BIT_TIME_T)
291+
# define _stat32i64(x,y) mingw_stat(x,y)
292+
#else
293+
# define _stat64(x,y) mingw_stat(x,y)
287294
#endif
288295

289296
int mingw_utime(const char *file_name, const struct utimbuf *times);

compat/msvc.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,6 @@ static __inline int strcasecmp (const char *s1, const char *s2)
2424

2525
#undef ERROR
2626

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-
4027
#include "compat/mingw.h"
4128

42-
#undef ALREADY_DECLARED_STAT_FUNCS
43-
4429
#endif

0 commit comments

Comments
 (0)