summaryrefslogtreecommitdiff
path: root/lib/libc/fcntl/open.c
blob: dbdff8f9d812dc231dba6307cd70b8fe0a3fcc69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <fcntl.h>
#include <stdarg.h>
#include <syscall.h>

int open(const char *path, int oflag, ...)
{
	long ret;
	mode_t mode = 0;

	if ((oflag & O_CREAT)) {
		va_list ap;
		va_start(ap, oflag);
		mode = va_arg(ap, mode_t);
		va_end(ap);
	}

	ret = syscall(open, path, oflag, mode);

	if (ret >= 0 && (oflag & O_CLOEXEC))
		return syscall(fcntl, ret, F_SETFD, FD_CLOEXEC);

	return ret;
}