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

import nihil.std;
import nihil.error;

namespace nihil {

/*
 * Create the given directory and any parent directories.
 */
export [[nodiscard]] auto
ensure_dir(std::filesystem::path const &dir) -> std::expected<void, error>
{
	auto err = std::error_code();

	std::filesystem::create_directories(dir, err);

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

	return {};
}

} // namespace nihil