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

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

namespace nihil {

// Rename a file (or directory).
export [[nodiscard]] auto
rename(std::filesystem::path const &oldp, std::filesystem::path const &newp)
	-> std::expected<void, error>
{
	auto guard = save_errno();

	auto const ret = std::rename(oldp.string().c_str(), newp.string().c_str());
	if (ret == -1)
		return std::unexpected(error(sys_error()));

	return {};
}

} // namespace nihil