summaryrefslogtreecommitdiff
path: root/minix/tests/t67a.c
blob: d39835856fcca6ef88a6f851c6eba6f267a1b661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
	int fd, fd_parent;
	char buf[1];

	if (argc != 2) {
		return 1;
	}

	fd_parent = atoi(argv[1]);

	/* If we open a new file, the fd we obtain should be fd_parent + 1 */
	fd = open("open_plusplus_fd", O_CREAT|O_RDWR, 0660);
	if (fd != fd_parent + 1) {
		return 2;
	}

	/* Also, writing to fd_parent should succeed */
	if (write(fd_parent, buf, sizeof(buf)) <= 0) {
		return 3;
	}

	return 0;
}