Skip to content

FileOpenTemp

Description

Open a unique temporary file for read+write. The name is the 16-hex-digit of Prng64() – no caller-supplied prefix, no kernel entropy per call. Open is O_RDWR | O_CREAT | O_EXCL | 0600, so two callers racing can never collide – one wins, the other retries with a new draw. The file lands in the process’s current working directory.

Two forms via argument-count overload (allocator backs out_path):

  • FileOpenTemp(out_path) – inside a Scope; allocator is

MisraScope.

  • FileOpenTemp(out_path, allocator) – explicit allocator.

Parameters

Name Direction Description
out_path out Fresh Str * – receives the resolved 16-char hex name. Caller StrDeinits when done; the on-disk file is NOT auto-removed (use FileRemove(out_path)).

Success

Returns an open File with FileIsOpen true.

Failure

Returns a File where FileIsOpen is false.

Usage example (Cross-references)

Usage examples (Cross-references)
    // caller can read it back and remove it.
    static bool write_test_file(Zstr text, Str *out_path, Allocator *alloc) {
        File f = FileOpenTemp(out_path, alloc);
        if (!FileIsOpen(&f)) {
            return false;
Last updated on