summaryrefslogtreecommitdiff
path: root/src/user/lib/camellia.c
blob: 1aa84028b8e20a0203cff3ad5f6eb50f22ba6d5e (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
#include <camellia.h>
#include <camellia/syscalls.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

handle_t camellia_open(const char *path, int flags) {
	handle_t ret;
	char *buf;
	size_t len;

	if (path == NULL)
		return errno = EINVAL, -EINVAL;
	if (flags & OPEN_CREATE)
		flags |= OPEN_WRITE;

	len = absolutepath(NULL, path, 0);
	buf = malloc(len);
	if (!buf)
		return -errno;
	absolutepath(buf, path, len);
	ret = _syscall_open(buf, strlen(buf), flags);
	free(buf);

	if (ret < 0)
		errno = -ret;

	return ret;
}