5 #include <sys/resource.h>
9 /* It looks like close_range was initially implemented for FreeBSD 13
10 * but without CLOSE_RANGE_CLOEXEC
11 * That implementation got back ported to FreeBSD 12.2
12 * And then CLOSE_RANGE_CLOEXEC added to 13 but not backported
13 * so 12 has close_range but not CLOSE_RANGE_CLOEXEC */
14 #if !defined(CLOSE_RANGE_CLOEXEC)
15 #define CLOSE_RANGE_CLOEXEC 1<<2
21 // I'm assuming opens start at 3 and get recycled
22 int fd1
= open("close_range.c", O_RDONLY
);
23 int fd2
= open("close_range.vgtest", O_RDONLY
);
24 int fd3
= open("close_range.stderr.exp", O_RDONLY
);
27 close_range(fd1
, fd3
, 0);
29 close_range(fd1
, fd3
, 0);
31 fd1
= open("close_range.c", O_RDONLY
);
32 fd2
= open("close_range.vgtest", O_RDONLY
);
34 // 3 and 4 open 5 closed
35 close_range(fd1
, fd3
, 0);
37 fd1
= open("close_range.c", O_RDONLY
);
38 fd3
= open("close_range.stderr.exp", O_RDONLY
);
40 // 3 and 5 open 4 closed
41 close_range(fd1
, fd3
, 0);
43 fd1
= open("close_range.c", O_RDONLY
);
44 fd2
= open("close_range.vgtest", O_RDONLY
);
45 fd3
= open("close_range.stderr.exp", O_RDONLY
);
48 close_range(fd1
, fd3
, CLOSE_RANGE_CLOEXEC
);
49 close_range(fd1
, fd3
, 0);
51 fd1
= open("close_range.c", O_RDONLY
);
52 fd2
= open("close_range.vgtest", O_RDONLY
);
53 fd3
= open("close_range.stderr.exp", O_RDONLY
);
57 close_range(fd1
, fd3
, 2);
58 assert(errno
= EINVAL
);
62 close_range(fd3
, fd1
, 2);
63 assert(errno
= EINVAL
);
66 getrlimit(RLIMIT_NOFILE
, &rl
);
69 close_range(rl
.rlim_cur
+100, rl
.rlim_cur
+200, 0);
71 close_range(3, rl
.rlim_cur
, 0);
73 fd1
= open("close_range.c", O_RDONLY
);
74 fd2
= open("close_range.vgtest", O_RDONLY
);
75 fd3
= open("close_range.stderr.exp", O_RDONLY
);
77 close_range(3, rl
.rlim_cur
+1, 0);