xref: /openbsd-src/regress/sys/kern/poll/pollretval.c (revision 6c9a98a4f49803cc6f09892b8442bf06757228f6)
1 /*	$OpenBSD: pollretval.c,v 1.2 2021/12/26 13:32:05 bluhm Exp $	*/
2 
3 #include <stdio.h>
4 #include <poll.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include <err.h>
8 
9 int
main(void)10 main(void)
11 {
12 	struct pollfd pfd[100];
13 	int i, r, r2 = 0;
14 
15 	for (i = 0; i < 100; i++) {
16 	    pfd[i].fd = 0;
17 	    pfd[i].events = arc4random() % 0x177;
18 	}
19 
20 	r = poll(pfd, 100, INFTIM);
21 
22 	if (r == -1)
23 		errx(1, "poll failed unexpectedly");
24 
25 	for (i = 0; i < 100; i++)
26 		if (pfd[i].revents)
27 			r2++;
28 	if (r != r2)
29 		errx(1, "poll return value %d miscounts .revents %d", r, r2);
30 
31 	return 0;
32 }
33