xref: /haiku/src/tests/system/kernel/null_poll_test.cpp (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
1 /*
2  * Copyright 2018, Xiang Fan, sfanxiang@gmail.com.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include <stdio.h>
7 #include <poll.h>
8 
9 
10 int main()
11 {
12 	FILE* f = fopen("/dev/null", "w");
13 	printf("f=%p\n", f);
14 	int fd = fileno(f);
15 	printf("fd=%d\n", fd);
16 
17 	struct pollfd pfd;
18 	pfd.fd = fd;
19 	pfd.events = POLLOUT;
20 	pfd.revents = 0;
21 
22 	int rv = poll(&pfd, 1, -1);
23 	printf("rv=%d\n", rv);
24 	if (rv <= 0)
25 		return 1;
26 	printf("events=%08x revents=%08x\n", pfd.events, pfd.revents);
27 	if (pfd.revents != POLLOUT)
28 		return 2;
29 
30 	return 0;
31 }
32