Make usage of windows.h lean and mean
authorMarius Storm-Olsen <mstormo@gmail.com>
Wed, 16 Sep 2009 08:20:26 +0000 (10:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 19 Sep 2009 03:00:42 +0000 (20:00 -0700)
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 <mstormo@gmail.com>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c
compat/mingw.h
compat/msvc.h
compat/win32.h
compat/winansi.c
git-compat-util.h
thread-utils.c

index 34ee427bafad4f964def8e503ebcb15c266eb320..6b5b5b2c7011a89c0415ebb89406c4a3ac53e9a9 100644 (file)
@@ -3,6 +3,8 @@
 #include <conio.h>
 #include "../strbuf.h"
 
+#include <shellapi.h>
+
 static int err_win_to_posix(DWORD winerr)
 {
        int error = ENOSYS;
index bcd23b0a4570377465e77f30831c9163e9d6bbda..5b5258bcebbbead7e4ed15a4dea7bf755739b98e 100644 (file)
@@ -41,6 +41,7 @@ struct passwd {
 
 extern char *getpass(const char *prompt);
 
+#ifndef POLLIN
 struct pollfd {
        int fd;           /* file descriptor */
        short events;     /* requested events */
@@ -48,6 +49,7 @@ struct pollfd {
 };
 #define POLLIN 1
 #define POLLHUP 2
+#endif
 
 typedef void (__cdecl *sig_handler_t)(int);
 struct sigaction {
index 6daf313e8c83e87b8450e077dae019e14704a8f2..53a6d30c02597bd5095582181419b333b7bffccb 100644 (file)
@@ -1,13 +1,6 @@
 #ifndef __MSVC__HEAD
 #define __MSVC__HEAD
 
-/* Define minimize windows version */
-#define WINVER 0x0500
-#define _WIN32_WINNT 0x0500
-#define _WIN32_WINDOWS 0x0410
-#define _WIN32_IE 0x0700
-#define NTDDI_VERSION NTDDI_WIN2KSP1
-#include <winsock2.h>
 #include <direct.h>
 #include <process.h>
 #include <malloc.h>
index e8c178d8cdc9e2f729cade3e6ee37461c5dfe90f..8ce91048deffc17bdf8d51672ddaa0c867052ac5 100644 (file)
@@ -2,7 +2,9 @@
 #define WIN32_H
 
 /* common Win32 functions for MinGW and Cygwin */
+#ifndef WIN32         /* Not defined by Cygwin */
 #include <windows.h>
+#endif
 
 static inline int file_attr_to_st_mode (DWORD attr)
 {
index 9217c24b43f7546815079d540304aa71821df926..dedce2104eaf5cefbb1abef1b7921eb99c67a75e 100644 (file)
@@ -2,7 +2,6 @@
  * Copyright 2008 Peter Harris <git@peter.is-a-geek.org>
  */
 
-#include <windows.h>
 #include "../git-compat-util.h"
 
 /*
index 8ea444fdc01c791c2a299b340d42261101124496..8d6e29cdeadfe146f4542c0b2b8ba803dedd2293 100644 (file)
 #define _NETBSD_SOURCE 1
 #define _SGI_SOURCE 1
 
+#ifdef WIN32 /* Both MinGW and MSVC */
+#define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */
+#include <winsock2.h>
+#include <windows.h>
+#endif
+
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/stat.h>
index 55e7e2904eb5f95cedaec2520ddd1d158ee93c7a..4f9c829c2df319e386b6b5d4f5c23818cc21c979 100644 (file)
@@ -1,9 +1,6 @@
 #include "cache.h"
 
-#ifdef _WIN32
-#  define WIN32_LEAN_AND_MEAN
-#  include <windows.h>
-#elif defined(hpux) || defined(__hpux) || defined(_hpux)
+#if defined(hpux) || defined(__hpux) || defined(_hpux)
 #  include <sys/pstat.h>
 #endif