Skip to content

Commit 3ecd153

Browse files
dschogitster
authored andcommitted
compat/mingw: support MSys2-based MinGW build
The excellent MSys2 project brings a substantially updated MinGW environment including newer GCC versions and new headers. To support compiling Git, let's special-case the new MinGW (tell-tale: the _MINGW64_VERSION_MAJOR constant is defined). Note: this commit only addresses compile failures, not compile warnings (that task is left for a future patch). Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9e2af08 commit 3ecd153

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

compat/mingw.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1+
#ifdef __MINGW64_VERSION_MAJOR
2+
#include <stdint.h>
3+
#include <wchar.h>
4+
typedef _sigset_t sigset_t;
5+
#endif
16
#include <winsock2.h>
27
#include <ws2tcpip.h>
38

9+
/* MinGW-w64 reports to have flockfile, but it does not actually have it. */
10+
#ifdef __MINGW64_VERSION_MAJOR
11+
#undef _POSIX_THREAD_SAFE_FUNCTIONS
12+
#endif
13+
414
/*
515
* things that are not available in header files
616
*/
717

8-
typedef int pid_t;
918
typedef int uid_t;
1019
typedef int socklen_t;
20+
#ifndef __MINGW64_VERSION_MAJOR
21+
typedef int pid_t;
1122
#define hstrerror strerror
23+
#endif
1224

1325
#define S_IFLNK 0120000 /* Symbolic link */
1426
#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
@@ -100,8 +112,10 @@ static inline int symlink(const char *oldpath, const char *newpath)
100112
{ errno = ENOSYS; return -1; }
101113
static inline int fchmod(int fildes, mode_t mode)
102114
{ errno = ENOSYS; return -1; }
115+
#ifndef __MINGW64_VERSION_MAJOR
103116
static inline pid_t fork(void)
104117
{ errno = ENOSYS; return -1; }
118+
#endif
105119
static inline unsigned int alarm(unsigned int seconds)
106120
{ return 0; }
107121
static inline int fsync(int fd)
@@ -176,8 +190,10 @@ int pipe(int filedes[2]);
176190
unsigned int sleep (unsigned int seconds);
177191
int mkstemp(char *template);
178192
int gettimeofday(struct timeval *tv, void *tz);
193+
#ifndef __MINGW64_VERSION_MAJOR
179194
struct tm *gmtime_r(const time_t *timep, struct tm *result);
180195
struct tm *localtime_r(const time_t *timep, struct tm *result);
196+
#endif
181197
int getpagesize(void); /* defined in MinGW's libgcc.a */
182198
struct passwd *getpwuid(uid_t uid);
183199
int setitimer(int type, struct itimerval *in, struct itimerval *out);
@@ -301,8 +317,10 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
301317
/*
302318
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
303319
*/
320+
#ifndef __MINGW64_VERSION_MAJOR
304321
#define off_t off64_t
305322
#define lseek _lseeki64
323+
#endif
306324

307325
/* use struct stat with 64 bit st_size */
308326
#ifdef stat
@@ -375,8 +393,12 @@ static inline char *mingw_find_last_dir_sep(const char *path)
375393
int mingw_offset_1st_component(const char *path);
376394
#define offset_1st_component mingw_offset_1st_component
377395
#define PATH_SEP ';'
396+
#ifndef __MINGW64_VERSION_MAJOR
378397
#define PRIuMAX "I64u"
379398
#define PRId64 "I64d"
399+
#else
400+
#include <inttypes.h>
401+
#endif
380402

381403
void mingw_open_html(const char *path);
382404
#define open_html mingw_open_html

0 commit comments

Comments
 (0)