Skip to content

Add a mode flags optionset to FileHandle.#1597

Merged
grynspan merged 1 commit intomainfrom
jgrynspan/file-handle-mode
Feb 27, 2026
Merged

Add a mode flags optionset to FileHandle.#1597
grynspan merged 1 commit intomainfrom
jgrynspan/file-handle-mode

Conversation

@grynspan
Copy link
Contributor

This PR adds an OptionSet-conforming type to FileHandle so that we don't have to hard-code mode strings we pass to fopen().

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This PR adds an `OptionSet`-conforming type to `FileHandle` so that we don't
have to hard-code mode strings we pass to `fopen()`.
@grynspan grynspan added this to the Swift 6.4.0 (main) milestone Feb 27, 2026
@grynspan grynspan self-assigned this Feb 27, 2026
@grynspan grynspan added the tech-debt 💾 reduces technical debt label Feb 27, 2026
// Note "x" in the mode string which indicates that the file should be
// created and opened exclusively. The underlying `fopen()` call will thus
// fail with `EEXIST` if a file exists at `filePath`.
let file = try FileHandle(atPath: filePath, mode: "wxeb")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"e" (O_CLOEXEC) is implied by default with the new optionset; you have to request inheritance explicitly instead (which we don't ever do currently).

@grynspan grynspan merged commit 4b38ab0 into main Feb 27, 2026
26 checks passed
@grynspan grynspan deleted the jgrynspan/file-handle-mode branch February 27, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tech-debt 💾 reduces technical debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants