xref: /relibc/tests/fcntl/fcntl.c (revision be35961d82cd98f2a2e61c4f1869271b9f4af571)
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 
5 #include "test_helpers.h"
6 
7 int main(void) {
8     // Lose our fd and pull it again
9     {
10         int fd = creat("fcntl.out", 0777);
11         ERROR_IF(creat, fd, == -1);
12         UNEXP_IF(creat, fd, < 0);
13     }
14 
15     int newfd = open("fcntl.out", 0);
16     ERROR_IF(open, newfd, == -1);
17     UNEXP_IF(open, newfd, < 0);
18 
19     int newfd2 = fcntl(newfd, F_DUPFD, 0);
20     // TODO: The standard doesn't define errors for F_DUPFD
21 
22     printf("duped fd is %d greater than the original fd\n", newfd2 - newfd);
23 
24     int c1 = close(newfd);
25     ERROR_IF(close, c1, == -1);
26     UNEXP_IF(close, c1, != 0);
27 
28     int c2 = close(newfd2);
29     ERROR_IF(close, c2, == -1);
30     UNEXP_IF(close, c2, != 0);
31 }
32