1*c27920e4Sbluhm /* $OpenBSD: pollnval.c,v 1.2 2021/10/29 20:15:03 bluhm Exp $ */
2081b6b34Smpi
3081b6b34Smpi /*
4081b6b34Smpi * Copyright (c) 2021 Leah Neukirchen <leah@vuxu.org>
5081b6b34Smpi *
6081b6b34Smpi * Permission to use, copy, modify, and distribute this software for any
7081b6b34Smpi * purpose with or without fee is hereby granted, provided that the above
8081b6b34Smpi * copyright notice and this permission notice appear in all copies.
9081b6b34Smpi *
10081b6b34Smpi * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11081b6b34Smpi * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12081b6b34Smpi * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13081b6b34Smpi * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14081b6b34Smpi * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15081b6b34Smpi * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16081b6b34Smpi * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17081b6b34Smpi */
18081b6b34Smpi
19081b6b34Smpi #include <assert.h>
20081b6b34Smpi #include <stdio.h>
21081b6b34Smpi #include <poll.h>
22081b6b34Smpi #include <unistd.h>
23081b6b34Smpi
24081b6b34Smpi int
main(void)25081b6b34Smpi main(void)
26081b6b34Smpi {
27081b6b34Smpi struct pollfd fds[1];
28081b6b34Smpi
29*c27920e4Sbluhm /* Do not hang forever, abort with timeout. */
30*c27920e4Sbluhm alarm(10);
31*c27920e4Sbluhm
32081b6b34Smpi fds[0].fd = 0;
33081b6b34Smpi fds[0].events = POLLIN | POLLHUP;
34081b6b34Smpi close(0);
35081b6b34Smpi
36081b6b34Smpi assert(poll(fds, 1, -1) == 1);
37081b6b34Smpi assert(fds[0].revents & POLLNVAL);
38081b6b34Smpi
39081b6b34Smpi return 0;
40081b6b34Smpi }
41