# [PATCH] Fixed compilation with Visual Studio by including poll.h

6 messages from 2012-04-20 to 2012-04-20. Participants: Sven Strickroth, Jeff King, Junio C Hamano, Erik Faye-Lund.
Thread: https://gitlist.dev/t/30298

## Sven Strickroth, 2012-04-20 20:37

Subject: [PATCH] Fixed compilation with Visual Studio by including poll.h
Message-ID: <4F91C8FF.7070402@tu-clausthal.de>
URL: https://gitlist.dev/e/4F91C8FF.7070402%40tu-clausthal.de

```
upload-archive.c and upload-pack.c use pollfd struct and POLLIN constant
which are defined in poll.h. However, poll.h is not included.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
---
 builtin/upload-archive.c |    1 +
 upload-pack.c            |    1 +
 2 files changed, 2 insertions(+)

diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index b928beb..6226bbb 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2006 Franck Bui-Huu
  */
+#include "poll.h"
 #include "cache.h"
 #include "builtin.h"
 #include "archive.h"
diff --git a/upload-pack.c b/upload-pack.c
index bb08e2e..79f9f8f 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,3 +1,4 @@
+#include "poll.h"
 #include "cache.h"
 #include "refs.h"
 #include "pkt-line.h"
-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server

```

## Jeff King, 2012-04-20 20:47

Subject: Re: [PATCH] Fixed compilation with Visual Studio by including poll.h
Message-ID: <20120420204722.GD13103@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20120420204722.GD13103%40sigill.intra.peff.net
In-Reply-To: <4F91C8FF.7070402@tu-clausthal.de>

```
On Fri, Apr 20, 2012 at 10:37:19PM +0200, Sven Strickroth wrote:

> upload-archive.c and upload-pack.c use pollfd struct and POLLIN constant
> which are defined in poll.h. However, poll.h is not included.

This should already be included by git-compat-util.h:

  $ grep -C1 poll.h git-compat-util.h
  #ifndef NO_SYS_POLL_H
  #include <sys/poll.h>
  #else
  #include <poll.h>
  #endif

It looks like we will prefer sys/poll.h if it exists. The official XSI
location is "poll.h", but I guess in practice they are equivalent on
most systems if you have both (certainly on Linux, poll.h just includes
sys/poll.h).

Does your environments have a sys/poll.h that exists isn't sufficient to
use poll? Maybe we need to tweak git-compat-util to include both if they
both exist.

-Peff

```

## Sven Strickroth, 2012-04-20 21:26

Subject: Re: [PATCH] Fixed compilation with Visual Studio by including poll.h
Message-ID: <4F91D489.8050402@tu-clausthal.de>
URL: https://gitlist.dev/e/4F91D489.8050402%40tu-clausthal.de
In-Reply-To: <20120420204722.GD13103@sigill.intra.peff.net>

```
Windows does not have sys/poll.h. I have to use the one from compat/win32.

The problem is that
    NO_SYS_POLL_H
is defined in compat/msvc.h in my environment.
And in git-compat-util.h
    #ifndef NO_SYS_POLL_H
    #include <sys/poll.h>
    #else
    #include <poll.h>
    #endif
is before
    #elif defined(_MSC_VER)
    #include "compat/msvc.h"
. Moving it down, solves the issue for me. (Suppose this is a fix for my
scenario only).

diff --git a/git-compat-util.h b/git-compat-util.h
index ed11ad8..a96849c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -111,11 +111,6 @@
 #include <regex.h>
 #include <utime.h>
 #include <syslog.h>
-#ifndef NO_SYS_POLL_H
-#include <sys/poll.h>
-#else
-#include <poll.h>
-#endif
 #if defined(__MINGW32__)
 /* pull in Windows compatibility stuff */
 #include "compat/mingw.h"
@@ -152,6 +147,11 @@
 #define _ALL_SOURCE 1
 #endif
 #endif
+#ifndef NO_SYS_POLL_H
+#include <sys/poll.h>
+#else
+#include <poll.h>
+#endif

 #ifndef NO_LIBGEN_H
 #include <libgen.h>
-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server

```

## Junio C Hamano, 2012-04-20 21:51

Subject: Re: [PATCH] Fixed compilation with Visual Studio by including poll.h
Message-ID: <xmqqty0ekr5t.fsf@junio.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqty0ekr5t.fsf%40junio.mtv.corp.google.com
In-Reply-To: <20120420204722.GD13103@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> On Fri, Apr 20, 2012 at 10:37:19PM +0200, Sven Strickroth wrote:
>
>> upload-archive.c and upload-pack.c use pollfd struct and POLLIN constant
>> which are defined in poll.h. However, poll.h is not included.
>
> This should already be included by git-compat-util.h:

Thanks for a bit of sanity.

>   $ grep -C1 poll.h git-compat-util.h
>   #ifndef NO_SYS_POLL_H
>   #include <sys/poll.h>
>   #else
>   #include <poll.h>
>   #endif
>
> It looks like we will prefer sys/poll.h if it exists. The official XSI
> location is "poll.h", but I guess in practice they are equivalent on
> most systems if you have both (certainly on Linux, poll.h just includes
> sys/poll.h).

There actually is no preference between the two from _our_ side. It is
up to the builder to know and define necessary make variables.

> Does your environments have a sys/poll.h that exists isn't sufficient to
> use poll? Maybe we need to tweak git-compat-util to include both if they
> both exist.

Both?  I guess, but I suspect that on most sane systems one would
include the other if there are both provided (iow, just so that you can
complile sources written both for XSI and for systems in the field).

```

## Erik Faye-Lund, 2012-04-20 21:58

Subject: Re: [PATCH] Fixed compilation with Visual Studio by including poll.h
Message-ID: <CABPQNSb7NeHOnOy-zmNMA3Jp143oCYqsGjK=+uatsS9bYaN5hA@mail.gmail.com>
URL: https://gitlist.dev/e/CABPQNSb7NeHOnOy-zmNMA3Jp143oCYqsGjK%3D%2BuatsS9bYaN5hA%40mail.gmail.com
In-Reply-To: <4F91D489.8050402@tu-clausthal.de>

```
On Fri, Apr 20, 2012 at 11:26 PM, Sven Strickroth
<sven.strickroth@tu-clausthal.de> wrote:
> Windows does not have sys/poll.h. I have to use the one from compat/win32.
>
> The problem is that
>    NO_SYS_POLL_H
> is defined in compat/msvc.h in my environment.
> And in git-compat-util.h
>    #ifndef NO_SYS_POLL_H
>    #include <sys/poll.h>
>    #else
>    #include <poll.h>
>    #endif
> is before
>    #elif defined(_MSC_VER)
>    #include "compat/msvc.h"
> . Moving it down, solves the issue for me. (Suppose this is a fix for my
> scenario only).
>

NO_SYS_POLL_H shouldn't be defined in compat/msvc.h, it should be
defined by the build-system. Our Makefile already does this inside the
"ifeq ($(uname_S),Windows)"-block.

How are you building Git?

```

## Jeff King, 2012-04-20 23:23

Subject: Re: [PATCH] Fixed compilation with Visual Studio by including poll.h
Message-ID: <20120420232319.GA14109@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20120420232319.GA14109%40sigill.intra.peff.net
In-Reply-To: <xmqqty0ekr5t.fsf@junio.mtv.corp.google.com>

```
On Fri, Apr 20, 2012 at 02:51:58PM -0700, Junio C Hamano wrote:

> > It looks like we will prefer sys/poll.h if it exists. The official XSI
> > location is "poll.h", but I guess in practice they are equivalent on
> > most systems if you have both (certainly on Linux, poll.h just includes
> > sys/poll.h).
> 
> There actually is no preference between the two from _our_ side. It is
> up to the builder to know and define necessary make variables.

I say "prefer" only because if you set nothing, you get "sys/poll.h". So
it is up to the builder to say "no, I do not have that non-standard
location. Use the standard one instead". Which seems a little backwards.

Of course "standard" here is just what POSIX says; sys/poll.h may be
much more standard in the real world (I don't know).

> > Does your environments have a sys/poll.h that exists isn't sufficient to
> > use poll? Maybe we need to tweak git-compat-util to include both if they
> > both exist.
> 
> Both?  I guess, but I suspect that on most sane systems one would
> include the other if there are both provided (iow, just so that you can
> complile sources written both for XSI and for systems in the field).

I would think one or the other would be fine. But the fact that Sven's
patch works makes me think that he has sys/poll.h, but it is not
sufficient. Hopefully including "poll.h" would be enough, but it's not
clear to me.

-Peff

```
