about summary refs log tree commit diff
path: root/tests/openat.c
blob: b14f4aec62fba408bcfab0570f2ab9392ffd52a0 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#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_write, fd, "\nplease", 7);
	printf("Write ret: %d\n", ret);

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

	if (ret == -1) {
		printf("FSeek error: %s\n", strerror(errno));
	}
	
	ret = syscall(SYS_write, fd, "A", 1);
	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;
}