summaryrefslogtreecommitdiff
path: root/src/libc/camellia.c
blob: 4e092e4870c08da053831cb248f2c2eefa5b6a13 (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>

hid_t camellia_open(const char *path, int flags) {
	hid_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 = _sys_open(buf, strlen(buf), flags);
	free(buf);

	if (ret < 0)
		errno = -ret;

	return ret;
}