xref: /illumos-gate/usr/src/test/os-tests/tests/poll/epoll_test.c (revision c65ebfc7045424bd04a6c7719a27b0ad3399ad54)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2016 Joyent, Inc.
14  */
15 
16 
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <unistd.h>
20 #include <fcntl.h>
21 #include <sys/epoll.h>
22 #include <errno.h>
23 #include <assert.h>
24 
25 int
26 main()
27 {
28 	int fd, flags;
29 
30 	fd = epoll_create1(0);
31 	assert(fd >= 0);
32 
33 	flags = fcntl(fd, F_GETFD);
34 	assert(flags != -1 && (flags & FD_CLOEXEC) == 0);
35 	(void) close(fd);
36 
37 
38 	fd = epoll_create1(EPOLL_CLOEXEC);
39 	assert(fd >= 0);
40 
41 	flags = fcntl(fd, F_GETFD);
42 	assert(flags != -1 && (flags & FD_CLOEXEC) == FD_CLOEXEC);
43 	(void) close(fd);
44 
45 	fd = epoll_create1(EPOLL_CLOEXEC * 3);
46 	assert(fd == -1 && errno == EINVAL);
47 	fd = epoll_create1(EPOLL_CLOEXEC * 2);
48 	assert(fd == -1 && errno == EINVAL);
49 
50 	return (0);
51 }
52