about summary refs log tree commit diff
path: root/tests/openat.c
blob: d843d2f090cba0415887b16eceeb6314157e9cf7 (plain) (blame)
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 <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <fcntl.h>

int main(int argc, char** argv) {
	printf("PID: %d\n", getpid());

	int fd = syscall(SYS_openat, -100, "testfile", O_RDWR);
	printf("Openat ret: %d\n", fd);

	if (fd == -1) {
		printf("Opneat error: %s\n", strerror(errno));
	}

	int ret = syscall(SYS_write, fd, "I'm writing this :) pls.", 24);
	printf("Write ret: %d\n", ret);

	if (ret == -1) {
		printf("Write error: %s\n", strerror(errno));
	}
	
	ret = syscall(SYS_close, fd);
	printf("Close ret: %d\n", ret);

	if (ret == -1) {
		printf("Close error: %s\n", strerror(errno));
	}

	return 0;
}