Skip to content

Commit b6f714f

Browse files
Ramsay Jonesgitster
authored andcommitted
MSVC: Fix an "incompatible pointer types" compiler warning
In particular, the following warning is issued while compiling compat/msvc.c: ...mingw.c(223) : warning C4133: 'function' : incompatible \ types - from '_stati64 *' to '_stat64 *' which relates to a call of _fstati64() in the mingw_fstat() function definition. This is caused by various layers of macro magic and attempts to avoid macro redefinition compiler warnings. For example, the call to _fstati64() mentioned above is actually a call to _fstat64(), and expects a pointer to a struct _stat64 rather than the struct _stati64 which is passed to mingw_fstat(). The definition of struct _stati64 given in compat/msvc.h had the same "shape" as the definition of struct _stat64, so the call to _fstat64() does not actually cause any runtime errors, but the structure types are indeed incompatible. In order to avoid the compiler warning, we add declarations for the mingw_lstat() and mingw_fstat() functions and supporting macros to msvc.h, suppressing the corresponding declarations in mingw.h, so that we can use the appropriate structure type (and function) names from the msvc headers. Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75301f9 commit b6f714f

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

compat/mingw.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,15 @@ int mingw_getpagesize(void);
209209
* mingw_fstat() instead of fstat() on Windows.
210210
*/
211211
#define off_t off64_t
212-
#define stat _stati64
213212
#define lseek _lseeki64
213+
#ifndef ALREADY_DECLARED_STAT_FUNCS
214+
#define stat _stati64
214215
int mingw_lstat(const char *file_name, struct stat *buf);
215216
int mingw_fstat(int fd, struct stat *buf);
216217
#define fstat mingw_fstat
217218
#define lstat mingw_lstat
218219
#define _stati64(x,y) mingw_lstat(x,y)
220+
#endif
219221

220222
int mingw_utime(const char *file_name, const struct utimbuf *times);
221223
#define utime mingw_utime

compat/msvc.h

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,22 @@ static __inline int strcasecmp (const char *s1, const char *s2)
2121
}
2222

2323
#undef ERROR
24-
#undef stat
25-
#undef _stati64
26-
#include "compat/mingw.h"
27-
#undef stat
28-
#define stat _stati64
24+
25+
/* Use mingw_lstat() instead of lstat()/stat() and mingw_fstat() instead
26+
* of fstat(). We add the declaration of these functions here, suppressing
27+
* the corresponding declarations in mingw.h, so that we can use the
28+
* appropriate structure type (and function) names from the msvc headers.
29+
*/
30+
#define stat _stat64
31+
int mingw_lstat(const char *file_name, struct stat *buf);
32+
int mingw_fstat(int fd, struct stat *buf);
33+
#define fstat mingw_fstat
34+
#define lstat mingw_lstat
2935
#define _stat64(x,y) mingw_lstat(x,y)
36+
#define ALREADY_DECLARED_STAT_FUNCS
37+
38+
#include "compat/mingw.h"
39+
40+
#undef ALREADY_DECLARED_STAT_FUNCS
3041

31-
/*
32-
Even though _stati64 is normally just defined at _stat64
33-
on Windows, we specify it here as a proper struct to avoid
34-
compiler warnings about macro redefinition due to magic in
35-
mingw.h. Struct taken from ReactOS (GNU GPL license).
36-
*/
37-
struct _stati64 {
38-
_dev_t st_dev;
39-
_ino_t st_ino;
40-
unsigned short st_mode;
41-
short st_nlink;
42-
short st_uid;
43-
short st_gid;
44-
_dev_t st_rdev;
45-
__int64 st_size;
46-
time_t st_atime;
47-
time_t st_mtime;
48-
time_t st_ctime;
49-
};
5042
#endif

0 commit comments

Comments
 (0)