Skip to content

Commit

Permalink
Make usage of windows.h lean and mean
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mstormo authored and gitster committed Sep 19, 2009
1 parent d75f8e6 commit 435bdf8
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions compat/mingw.c
Expand Up @@ -3,6 +3,8 @@
#include <conio.h>
#include "../strbuf.h"

#include <shellapi.h>

static int err_win_to_posix(DWORD winerr)
{
int error = ENOSYS;
Expand Down
2 changes: 2 additions & 0 deletions compat/mingw.h
Expand Up @@ -41,13 +41,15 @@ struct passwd {

extern char *getpass(const char *prompt);

#ifndef POLLIN
struct pollfd {
int fd; /* file descriptor */
short events; /* requested events */
short revents; /* returned events */
};
#define POLLIN 1
#define POLLHUP 2
#endif

typedef void (__cdecl *sig_handler_t)(int);
struct sigaction {
Expand Down
7 changes: 0 additions & 7 deletions compat/msvc.h
@@ -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>
Expand Down
2 changes: 2 additions & 0 deletions compat/win32.h
Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion compat/winansi.c
Expand Up @@ -2,7 +2,6 @@
* Copyright 2008 Peter Harris <git@peter.is-a-geek.org>
*/

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

/*
Expand Down
6 changes: 6 additions & 0 deletions git-compat-util.h
Expand Up @@ -65,6 +65,12 @@
#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>
Expand Down
5 changes: 1 addition & 4 deletions thread-utils.c
@@ -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

Expand Down

0 comments on commit 435bdf8

Please sign in to comment.