compat/poll: prepare for targeting Windows Vista
Windows Vista (and later) actually have a working poll(), but we still cannot use it because it only works on sockets. So let's detect when we are targeting Windows Vista and undefine those constants, and define `pollfd` so that we can declare our own pollfd struct. We also need to make sure that we override those constants *after* `winsock2.h` has been `#include`d (otherwise we would not really override those constants). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Oct 3, 2018 at 12:43 UTC
d7e357fb9c702979d5b3a7d9faa869844a12e4d9
2 files changed
+18
-3
compat/poll/poll.c
+3
-3
@@ -29,9 +29,6 @@
29
30
#include <sys/types.h>
31
32
-/* Specification. */
33
-#include <poll.h>
34
-
32
#include <errno.h>
33
#include <limits.h>
34
#include <assert.h>
@@ -55,6 +52,9 @@
52
# include <unistd.h>
53
#endif
54
55
+/* Specification. */
56
+#include "poll.h"
57
+
58
#ifdef HAVE_SYS_IOCTL_H
59
# include <sys/ioctl.h>
60
#endif
compat/poll/poll.h
+15
@@ -21,6 +21,21 @@
21
#ifndef _GL_POLL_H
22
#define _GL_POLL_H
23
24
+#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600
25
+/* Vista has its own, socket-only poll() */
26
+#undef POLLIN
27
+#undef POLLPRI
28
+#undef POLLOUT
29
+#undef POLLERR
30
+#undef POLLHUP
31
+#undef POLLNVAL
32
+#undef POLLRDNORM
33
+#undef POLLRDBAND
34
+#undef POLLWRNORM
35
+#undef POLLWRBAND
36
+#define pollfd compat_pollfd
37
+#endif
38
+
39
/* fake a poll(2) environment */
40
#define POLLIN 0x0001 /* any readable data available */
41
#define POLLPRI 0x0002 /* OOB/Urgent readable data */