aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/posix.rename.cc
blob: 9203d08d14bd4a0f83636820055ae7e658cc9b33 (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
32
33
34
/*
 * This source code is released into the public domain.
 */

module;

#include <expected>
#include <filesystem>

module nihil.posix;

import nihil.error;

namespace nihil {

/*
 * Rename a file.
 */
auto rename_file(std::filesystem::path const &oldp,
		 std::filesystem::path const &newp)
	-> std::expected<void, error>
{
	auto err = std::error_code();

	std::filesystem::rename(oldp, newp, err);

	if (err)
		return std::unexpected(error(err));

	return {};
}


} // namespace nihil