Function liberate::fs::temp_name

Function Documentation

std::string liberate::fs::temp_name(std::string const &prefix = "")

Return a file name in a temporary path location.

This is useful for e.g. local, pipe or fifo connectors.

Note that the function cannot absolutely guarantee uniqeness of the file name returned; consider it a best-effort attempt.

In particular, since there is a race between generating the name and opening it for a pipe, this function falls prey to https://cwe.mitre.org/data/definitions/377.html

But since mkstemp() and other OS functions cannot themselves create a pipe with a temporary name, this is something we’ll have to live with.

Parameters

prefix[in] optional; a prefix for the generated file name.

Throws

std::runtime_error – on some failures with system APIs.

Returns

temporary file name.