xref: /minix3/minix/tests/t67b.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc #include <sys/types.h>
2*433d6423SLionel Sambuc #include <sys/wait.h>
3*433d6423SLionel Sambuc #include <errno.h>
4*433d6423SLionel Sambuc #include <fcntl.h>
5*433d6423SLionel Sambuc #include <stdio.h>
6*433d6423SLionel Sambuc #include <stdlib.h>
7*433d6423SLionel Sambuc #include <unistd.h>
8*433d6423SLionel Sambuc 
9*433d6423SLionel Sambuc int
main(int argc,char * argv[])10*433d6423SLionel Sambuc main(int argc, char *argv[])
11*433d6423SLionel Sambuc {
12*433d6423SLionel Sambuc 	int fd, fd_parent;
13*433d6423SLionel Sambuc 	char buf[1];
14*433d6423SLionel Sambuc 
15*433d6423SLionel Sambuc 	if (argc != 2) {
16*433d6423SLionel Sambuc 		return 1;
17*433d6423SLionel Sambuc 	}
18*433d6423SLionel Sambuc 
19*433d6423SLionel Sambuc 	fd_parent = atoi(argv[1]);
20*433d6423SLionel Sambuc 
21*433d6423SLionel Sambuc 	/* Writing to fd_parent should fail as it has to be closed at this
22*433d6423SLionel Sambuc 	 * point */
23*433d6423SLionel Sambuc 	if (write(fd_parent, buf, sizeof(buf)) != -1) {
24*433d6423SLionel Sambuc 		return 2;
25*433d6423SLionel Sambuc 	}
26*433d6423SLionel Sambuc 	if (errno != EBADF) {
27*433d6423SLionel Sambuc 		return 3;
28*433d6423SLionel Sambuc 	}
29*433d6423SLionel Sambuc 
30*433d6423SLionel Sambuc 	/* If we open a new file, the fd we obtain should be identical to
31*433d6423SLionel Sambuc 	 * fd_parent */
32*433d6423SLionel Sambuc 	fd = open("open_identical_fd", O_CREAT|O_RDWR, 0660);
33*433d6423SLionel Sambuc 	if (fd != fd_parent) {
34*433d6423SLionel Sambuc 		return 4;
35*433d6423SLionel Sambuc 	}
36*433d6423SLionel Sambuc 
37*433d6423SLionel Sambuc 	return 0;
38*433d6423SLionel Sambuc }
39*433d6423SLionel Sambuc 
40