std.fs.open_private

std.fs

open_private(path) -> fd, err

Create a new file only its owner can read

Creates path write-only and close-on-exec, and returns the raw fd. The file is born with mode 0600, so no other user can open it in the gap a later chmod would leave. The umask can only narrow that mode.

An existing path is refused with "File exists", and so is a symlink, even one to a missing file. Wrap the fd with fdopen(fd, "w") to get a FILE*, or close it with close. A file that must outlast a power loss is synced, and so is its directory: sync shows the steps.