aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/posix.open.cc
blob: 9ef653836bb074d500606ccc53fee976ee9e82b7 (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
/*
 * This source code is released into the public domain.
 */

module;

#include <expected>
#include <filesystem>
#include <system_error>

#include <fcntl.h>
#include <unistd.h>

module nihil.posix;

import nihil.error;
import :fd;

namespace nihil {

auto open(std::filesystem::path const &filename, int flags, int mode)
	-> std::expected<fd, error>
{
	auto fdno = ::open(filename.c_str(), flags, mode);
	if (fdno != -1)
		return fd(fdno);

	return std::unexpected(error(std::errc(errno)));
}

} // namespace nihil