| 1 |
/* Header for poll(2) emulation |
| 2 |
Contributed by Paolo Bonzini. |
| 3 |
|
| 4 |
Copyright 2001-2003, 2007, 2009-2026 Free Software Foundation, Inc. |
| 5 |
|
| 6 |
This file is part of gnulib. |
| 7 |
|
| 8 |
This file is free software: you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU Lesser General Public License as |
| 10 |
published by the Free Software Foundation; either version 2.1 of the |
| 11 |
License, or (at your option) any later version. |
| 12 |
|
| 13 |
This file is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU Lesser General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU Lesser General Public License |
| 19 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#ifndef _@GUARD_PREFIX@_POLL_H |
| 22 |
|
| 23 |
#if __GNUC__ >= 3 |
| 24 |
@PRAGMA_SYSTEM_HEADER@ |
| 25 |
#endif |
| 26 |
@PRAGMA_COLUMNS@ |
| 27 |
|
| 28 |
/* The include_next requires a split double-inclusion guard. */ |
| 29 |
#if @HAVE_POLL_H@ |
| 30 |
# @INCLUDE_NEXT@ @NEXT_POLL_H@ |
| 31 |
#endif |
| 32 |
|
| 33 |
#ifndef _@GUARD_PREFIX@_POLL_H |
| 34 |
#define _@GUARD_PREFIX@_POLL_H |
| 35 |
|
| 36 |
/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ |
| 37 |
#if !_GL_CONFIG_H_INCLUDED |
| 38 |
#error "Please include config.h first." |
| 39 |
#endif |
| 40 |
|
| 41 |
/* On native Windows, get the 'struct pollfd' type and the POLL* macro |
| 42 |
definitions before we override them. mingw defines them in <winsock2.h> |
| 43 |
if _WIN32_WINNT >= 0x0600. */ |
| 44 |
#if @HAVE_WINSOCK2_H@ |
| 45 |
# include <winsock2.h> |
| 46 |
#endif |
| 47 |
|
| 48 |
|
| 49 |
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ |
| 50 |
|
| 51 |
/* The definition of _GL_WARN_ON_USE is copied here. */ |
| 52 |
|
| 53 |
|
| 54 |
#if !@HAVE_POLL_H@ |
| 55 |
|
| 56 |
# if @HAVE_WINSOCK2_H@ |
| 57 |
/* Override the definitions from <winsock2.h>. */ |
| 58 |
# undef POLLIN |
| 59 |
# undef POLLPRI |
| 60 |
# undef POLLOUT |
| 61 |
# undef POLLERR |
| 62 |
# undef POLLHUP |
| 63 |
# undef POLLNVAL |
| 64 |
# undef POLLRDNORM |
| 65 |
# undef POLLRDBAND |
| 66 |
# undef POLLWRNORM |
| 67 |
# undef POLLWRBAND |
| 68 |
# define pollfd rpl_pollfd |
| 69 |
# endif |
| 70 |
|
| 71 |
/* fake a poll(2) environment */ |
| 72 |
# define POLLIN 0x0001 /* any readable data available */ |
| 73 |
# define POLLPRI 0x0002 /* OOB/Urgent readable data */ |
| 74 |
# define POLLOUT 0x0004 /* file descriptor is writable */ |
| 75 |
# define POLLERR 0x0008 /* some poll error occurred */ |
| 76 |
# define POLLHUP 0x0010 /* file descriptor was "hung up" */ |
| 77 |
# define POLLNVAL 0x0020 /* requested events "invalid" */ |
| 78 |
# define POLLRDNORM 0x0040 |
| 79 |
# define POLLRDBAND 0x0080 |
| 80 |
# define POLLWRNORM 0x0100 |
| 81 |
# define POLLWRBAND 0x0200 |
| 82 |
|
| 83 |
# if !GNULIB_defined_poll_types |
| 84 |
|
| 85 |
struct pollfd |
| 86 |
{ |
| 87 |
int fd; /* which file descriptor to poll */ |
| 88 |
short events; /* events we are interested in */ |
| 89 |
short revents; /* events found on return */ |
| 90 |
}; |
| 91 |
|
| 92 |
typedef unsigned long nfds_t; |
| 93 |
|
| 94 |
# define GNULIB_defined_poll_types 1 |
| 95 |
# endif |
| 96 |
|
| 97 |
/* Define INFTIM only if doing so conforms to POSIX. */ |
| 98 |
# if !defined (_POSIX_C_SOURCE) && !defined (_XOPEN_SOURCE) |
| 99 |
# define INFTIM (-1) |
| 100 |
# endif |
| 101 |
|
| 102 |
#endif |
| 103 |
|
| 104 |
|
| 105 |
#if @GNULIB_POLL@ |
| 106 |
# if @REPLACE_POLL@ |
| 107 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 108 |
# undef poll |
| 109 |
# define poll rpl_poll |
| 110 |
# endif |
| 111 |
_GL_FUNCDECL_RPL (poll, int, (struct pollfd *pfd, nfds_t nfd, int timeout), ); |
| 112 |
_GL_CXXALIAS_RPL (poll, int, (struct pollfd *pfd, nfds_t nfd, int timeout)); |
| 113 |
# else |
| 114 |
# if !@HAVE_POLL@ |
| 115 |
_GL_FUNCDECL_SYS (poll, int, (struct pollfd *pfd, nfds_t nfd, int timeout), ); |
| 116 |
# endif |
| 117 |
_GL_CXXALIAS_SYS (poll, int, (struct pollfd *pfd, nfds_t nfd, int timeout)); |
| 118 |
# endif |
| 119 |
_GL_CXXALIASWARN (poll); |
| 120 |
#elif defined GNULIB_POSIXCHECK |
| 121 |
# if HAVE_RAW_DECL_POLL |
| 122 |
_GL_WARN_ON_USE (poll, "poll is unportable - " |
| 123 |
"use gnulib module poll for portability"); |
| 124 |
# endif |
| 125 |
#endif |
| 126 |
|
| 127 |
|
| 128 |
#endif /* _@GUARD_PREFIX@_POLL_H */ |
| 129 |
#endif /* _@GUARD_PREFIX@_POLL_H */ |