Skip to content

Commit 435bdf8

Browse files
mstormogitster
authored andcommitted
Make usage of windows.h lean and mean
Centralize the include of windows.h in git-compat-util.h, turn on WIN32_LEAN_AND_MEAN to avoid including plenty of other header files which is not needed in Git. Also ensure we load winsock2.h first, so we don't load the older winsock definitions at a later stage, since they contain duplicate definitions. When moving windows.h into git-compat-util.h, we need to protect the definition of struct pollfd in mingw.h, since this file is used by both MinGW and MSVC, and the latter defines this struct in winsock2.h. We need to keep the windows.h include in compat/win32.h, since its shared by both MinGW and Cygwin, and we're not touching Cygwin in this commit. The include in git-compat-util.h is protected with an ifdef WIN32, which is not the case when compiling for Cygwin. Signed-off-by: Marius Storm-Olsen <[email protected]> Acked-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d75f8e6 commit 435bdf8

File tree

7 files changed

+13
-12
lines changed

7 files changed

+13
-12
lines changed

compat/mingw.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <conio.h>
44
#include "../strbuf.h"
55

6+
#include <shellapi.h>
7+
68
static int err_win_to_posix(DWORD winerr)
79
{
810
int error = ENOSYS;

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ struct passwd {
4141

4242
extern char *getpass(const char *prompt);
4343

44+
#ifndef POLLIN
4445
struct pollfd {
4546
int fd; /* file descriptor */
4647
short events; /* requested events */
4748
short revents; /* returned events */
4849
};
4950
#define POLLIN 1
5051
#define POLLHUP 2
52+
#endif
5153

5254
typedef void (__cdecl *sig_handler_t)(int);
5355
struct sigaction {

compat/msvc.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
#ifndef __MSVC__HEAD
22
#define __MSVC__HEAD
33

4-
/* Define minimize windows version */
5-
#define WINVER 0x0500
6-
#define _WIN32_WINNT 0x0500
7-
#define _WIN32_WINDOWS 0x0410
8-
#define _WIN32_IE 0x0700
9-
#define NTDDI_VERSION NTDDI_WIN2KSP1
10-
#include <winsock2.h>
114
#include <direct.h>
125
#include <process.h>
136
#include <malloc.h>

compat/win32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#define WIN32_H
33

44
/* common Win32 functions for MinGW and Cygwin */
5+
#ifndef WIN32 /* Not defined by Cygwin */
56
#include <windows.h>
7+
#endif
68

79
static inline int file_attr_to_st_mode (DWORD attr)
810
{

compat/winansi.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright 2008 Peter Harris <[email protected]>
33
*/
44

5-
#include <windows.h>
65
#include "../git-compat-util.h"
76

87
/*

git-compat-util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
#define _NETBSD_SOURCE 1
6666
#define _SGI_SOURCE 1
6767

68+
#ifdef WIN32 /* Both MinGW and MSVC */
69+
#define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */
70+
#include <winsock2.h>
71+
#include <windows.h>
72+
#endif
73+
6874
#include <unistd.h>
6975
#include <stdio.h>
7076
#include <sys/stat.h>

thread-utils.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "cache.h"
22

3-
#ifdef _WIN32
4-
# define WIN32_LEAN_AND_MEAN
5-
# include <windows.h>
6-
#elif defined(hpux) || defined(__hpux) || defined(_hpux)
3+
#if defined(hpux) || defined(__hpux) || defined(_hpux)
74
# include <sys/pstat.h>
85
#endif
96

0 commit comments

Comments
 (0)