Skip to content

Use std::tmpfile in create_file on Windows#215

Merged
bugdea1er merged 2 commits into
mainfrom
win-std-tmpfile
Jun 5, 2025
Merged

Use std::tmpfile in create_file on Windows#215
bugdea1er merged 2 commits into
mainfrom
win-std-tmpfile

Conversation

@bugdea1er
Copy link
Copy Markdown
Owner

Instead of dealing with signals, file permissions and such, delegate it to std::tmpfile

After creating the file, we can simply std::freopen the file with the desired openmode

Part of #193 for Windows

@bugdea1er bugdea1er requested a review from Copilot June 5, 2025 14:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

A Windows-specific refactor to use std::tmpfile for temporary file creation and then reopen it with the requested mode, removing manual signal/permission handling.

  • Introduce a create_file(mode, ec) overload that delegates to std::tmpfile and uses Windows APIs to recover the file path and reopen it.
  • Simplify the existing create_file(mode) on Windows to call the new overload and convert errors to std::filesystem_error.
  • Update tests to drop the hardlink count assertion under the Windows branch.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
tests/file.cpp Removed the hardlink-count check from the Windows test path.
src/create.cpp Added _CRT_SECURE_NO_WARNINGS, included platform headers, and implemented the std::tmpfile–based create_file.
Comments suppressed due to low confidence (1)

tests/file.cpp:77

  • [nitpick] The hardlink-count assertion was removed from the Windows test path, potentially reducing coverage of link-related behavior. If ensuring no hardlinks is still important, consider adding a Windows-specific check or replacing this assertion with an equivalent check.
EXPECT_EQ(file_info.nNumberOfLinks, 0);    // Has no hardlinks

Comment thread src/create.cpp
Repository owner deleted a comment from Copilot AI Jun 5, 2025
Repository owner deleted a comment from Copilot AI Jun 5, 2025
Repository owner deleted a comment from Copilot AI Jun 5, 2025
@bugdea1er bugdea1er merged commit b2f87e5 into main Jun 5, 2025
16 checks passed
@bugdea1er bugdea1er deleted the win-std-tmpfile branch June 5, 2025 14:58
bugdea1er added a commit that referenced this pull request Jun 5, 2025
Smae as #215, but for POSIX: do not
deal with signals and stuff, delegate it to the `std::tmpfile`

Closes #193
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants