Skip to content

Commit

Permalink
Close file on creation (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgs99 authored Jun 20, 2024
1 parent a46c406 commit ed100c8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/tmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,19 @@ fs::path create_file(std::string_view prefix, std::string_view suffix) {
}

ec = std::error_code(err, std::system_category());
} else {
CloseHandle(file);
}

#else
if (mkstemps(path.data(), static_cast<int>(suffix.size())) == -1) {
const int fileDescriptor =
mkstemps(path.data(), static_cast<int>(suffix.size()));
if (fileDescriptor == -1) {
ec = std::error_code(errno, std::system_category());
} else {
close(fileDescriptor);
}

#endif
if (ec) {
throw fs::filesystem_error("Cannot create temporary file", ec);
Expand Down

0 comments on commit ed100c8

Please sign in to comment.