Skip to content

Commit

Permalink
fix: unix file_open create
Browse files Browse the repository at this point in the history
  • Loading branch information
moonshadow565 committed Sep 12, 2022
1 parent 9e8b78e commit 3b09c8f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cslol-tools/lib/lol/io/sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ auto sys::file_munmap(void* data, std::size_t count) noexcept -> void {
# define last_error() std::error_code((int)errno, std::system_category())

auto sys::file_open(std::filesystem::path const& path, bool write) noexcept -> Result<std::intptr_t> {
if (write) {
std::error_code ec = {};
std::filesystem::create_directories(path.parent_path(), ec);
if (ec) [[unlikely]] {
return {ec};
}
}
int fd = write ? ::open(path.string().c_str(), O_RDWR | O_CREAT, 0644) : ::open(path.string().c_str(), O_RDONLY);
if (!handle_ok(fd)) [[unlikely]] {
return {last_error()};
Expand Down

0 comments on commit 3b09c8f

Please sign in to comment.