Skip to content

Commit a2374f5

Browse files
kbleesgitster
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 <[email protected]> Acked-by: Sebastian Schuberth <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 61542f7 commit a2374f5

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
@@ -264,19 +264,26 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
264264
return 0;
265265
}
266266

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.
269269
*/
270270
#define off_t off64_t
271271
#define lseek _lseeki64
272-
#ifndef ALREADY_DECLARED_STAT_FUNCS
272+
273+
/* use struct stat with 64 bit st_size */
273274
#define stat _stati64
274275
int mingw_lstat(const char *file_name, struct stat *buf);
275276
int mingw_stat(const char *file_name, struct stat *buf);
276277
int mingw_fstat(int fd, struct stat *buf);
277278
#define fstat mingw_fstat
278279
#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)
280287
#endif
281288

282289
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)