FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / none / tests / double_close_range.c
blob5c593fd112287825df60cf4347a516148a77a2c8
1 #define _GNU_SOURCE
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #if defined(__linux__)
7 #include <linux/close_range.h>
8 #endif
10 int main ()
12 // Create a new file descriptor that we immediately close.
13 // This is of course fine.
14 int fd = dup (2);
15 if (fd != -1){
16 fprintf(stderr, "close fd %d\n", fd);
17 close (fd);
20 // Shouldn't warn, we are closing everything
21 // This is a special case for close_range if the last
22 // argument is ~0U (infinity).
23 fprintf(stderr, "Closing range (%d, %d).\n", fd, ~0U);
24 close_range(fd, ~0U, 0);
26 int fd5 = dup2(1, 5);
27 int fd7 = dup2(2, 7);
28 fprintf(stderr, "Closing range (%d, %d).\n", fd5, fd7);
29 close_range(5, 7, 0);
31 // Should warn, we close a small range
32 fprintf(stderr, "Double closing range (%d, %d).\n", fd5, fd7);
33 close_range(5, 7, 0);
35 return 0;