Don't unlock null lock.
[cake.git] / test / clib / fcntl.c
blobf87a1f729023dacb87efb967590f438dea5f1e37
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "test.h"
6 int fd = -1;
7 int fd2 = -1;
9 int main()
11 fd = mkstemp("T:lseekXXXXXX");
12 TEST((fd != -1));
14 /* Check if F_GETFD and F_SETFD is working */
15 TEST((fcntl(fd, F_GETFD) == 0));
16 TEST((fcntl(fd, F_SETFD, FD_CLOEXEC) == 0));
17 TEST((fcntl(fd, F_GETFD) == FD_CLOEXEC));
18 TEST((fcntl(fd, F_SETFD, 0) == 0));
19 TEST((fcntl(fd, F_GETFD) == 0));
21 int fd2 = dup(fd);
22 TEST((fd2 != -1));
24 /* Check if descriptor flags are independent for duped descriptors */
25 TEST((fcntl(fd2, F_GETFD) == 0));
26 TEST((fcntl(fd2, F_SETFD, FD_CLOEXEC) == 0));
27 TEST((fcntl(fd2, F_GETFD) == FD_CLOEXEC));
28 TEST((fcntl(fd, F_GETFD) == 0));
29 TEST((fcntl(fd, F_SETFD, FD_CLOEXEC) == 0));
30 TEST((fcntl(fd2, F_SETFD, 0) == 0));
31 TEST((fcntl(fd, F_GETFD) == FD_CLOEXEC));
33 cleanup();
34 return OK;
37 void cleanup()
39 if(fd != -1)
40 close(fd);
41 if(fd2 != -1)
42 close(fd2);