mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
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 <ramsay@ramsay1.demon.co.uk> Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
75301f9015
commit
b6f714f89a
|
@ -209,13 +209,15 @@ int mingw_getpagesize(void);
|
||||||
* mingw_fstat() instead of fstat() on Windows.
|
* mingw_fstat() instead of fstat() on Windows.
|
||||||
*/
|
*/
|
||||||
#define off_t off64_t
|
#define off_t off64_t
|
||||||
#define stat _stati64
|
|
||||||
#define lseek _lseeki64
|
#define lseek _lseeki64
|
||||||
|
#ifndef ALREADY_DECLARED_STAT_FUNCS
|
||||||
|
#define stat _stati64
|
||||||
int mingw_lstat(const char *file_name, struct stat *buf);
|
int mingw_lstat(const char *file_name, struct stat *buf);
|
||||||
int mingw_fstat(int fd, struct stat *buf);
|
int mingw_fstat(int fd, struct stat *buf);
|
||||||
#define fstat mingw_fstat
|
#define fstat mingw_fstat
|
||||||
#define lstat mingw_lstat
|
#define lstat mingw_lstat
|
||||||
#define _stati64(x,y) mingw_lstat(x,y)
|
#define _stati64(x,y) mingw_lstat(x,y)
|
||||||
|
#endif
|
||||||
|
|
||||||
int mingw_utime(const char *file_name, const struct utimbuf *times);
|
int mingw_utime(const char *file_name, const struct utimbuf *times);
|
||||||
#define utime mingw_utime
|
#define utime mingw_utime
|
||||||
|
|
|
@ -21,30 +21,22 @@ static __inline int strcasecmp (const char *s1, const char *s2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef ERROR
|
#undef ERROR
|
||||||
#undef stat
|
|
||||||
#undef _stati64
|
|
||||||
#include "compat/mingw.h"
|
|
||||||
#undef stat
|
|
||||||
#define stat _stati64
|
|
||||||
#define _stat64(x,y) mingw_lstat(x,y)
|
|
||||||
|
|
||||||
/*
|
/* Use mingw_lstat() instead of lstat()/stat() and mingw_fstat() instead
|
||||||
Even though _stati64 is normally just defined at _stat64
|
* of fstat(). We add the declaration of these functions here, suppressing
|
||||||
on Windows, we specify it here as a proper struct to avoid
|
* the corresponding declarations in mingw.h, so that we can use the
|
||||||
compiler warnings about macro redefinition due to magic in
|
* appropriate structure type (and function) names from the msvc headers.
|
||||||
mingw.h. Struct taken from ReactOS (GNU GPL license).
|
*/
|
||||||
*/
|
#define stat _stat64
|
||||||
struct _stati64 {
|
int mingw_lstat(const char *file_name, struct stat *buf);
|
||||||
_dev_t st_dev;
|
int mingw_fstat(int fd, struct stat *buf);
|
||||||
_ino_t st_ino;
|
#define fstat mingw_fstat
|
||||||
unsigned short st_mode;
|
#define lstat mingw_lstat
|
||||||
short st_nlink;
|
#define _stat64(x,y) mingw_lstat(x,y)
|
||||||
short st_uid;
|
#define ALREADY_DECLARED_STAT_FUNCS
|
||||||
short st_gid;
|
|
||||||
_dev_t st_rdev;
|
#include "compat/mingw.h"
|
||||||
__int64 st_size;
|
|
||||||
time_t st_atime;
|
#undef ALREADY_DECLARED_STAT_FUNCS
|
||||||
time_t st_mtime;
|
|
||||||
time_t st_ctime;
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue