aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/unlink.ccm
blob: d6c47cd2d06e009d599d116f7824f6d8ece21e6c (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
// This source code is released into the public domain.
module;

#include <unistd.h>

export module nihil.posix:unlink;

// unlink: simple wrapper around ::unlink()

import nihil.std;
import nihil.error;
import nihil.util;

namespace nihil {

export [[nodiscard]] auto unlink(std::filesystem::path const &path)
	-> std::expected<void, error>
{
	auto guard = save_errno();

	auto const ret = ::unlink(path.string().c_str());
	if (ret == 0)
		return {};

	return std::unexpected(error(sys_error()));
}

} // namespace nihil