16512 xhci leaks oneshot interrupt IN transfers on pipe reset
[illumos-gate.git] / usr / src / test / libc-tests / tests / closefrom.c
bloba5153a660447e0c637048ee3a32af89325e29c03
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.
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.
13 * Copyright 2023 Bill Sommerfeld <sommerfeld@alum.mit.edu>
17 * Test for closefrom(). Test cases were inspired by xapian's
18 * test_closefrom1() and are somewhat incomplete (we don't test
19 * what happens when /proc/self/fd isn't available).
21 #include <err.h>
22 #include <errno.h>
23 #include <limits.h>
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <sys/debug.h>
29 int
30 main(void)
32 closefrom(INT_MAX); /* should be a no-op */
34 VERIFY3S(dup2(1, 10), ==, 10);
35 VERIFY3S(dup2(1, 11), ==, 11);
36 VERIFY3S(dup2(1, 15), ==, 15);
38 closefrom(11);
40 VERIFY3S(close(10), ==, 0);
41 VERIFY3S(close(11), ==, -1);
42 VERIFY3S(errno, ==, EBADF);
43 VERIFY3S(close(15), ==, -1);
44 VERIFY3S(errno, ==, EBADF);
46 exit(0);