HH\Lib\OS\mkstemps

Meta Engineer?

This is available as OS\mkstemps in the www repository.

Create a temporary file using a template filename, with an invariant suffix

namespace HH\Lib\OS;

function mkstemps(
  string $template,
  int $suffix_len,
): (FileDescriptor, string);

The template must contain exactly 6 X characters, followed immediately by the invariant suffix.

The length of the suffix must be specified; for example, if the template is fooXXXXXXbar, the suffix len is 3, or for fooXXXXXXbarbaz it is 6. For fooXXXXXXXXXXXXXXXXXX, any suffix len between 0 and 12 is valid.

The template may be either a relative or absolute path, however the parent directory must already exist.

The temporary file:

  • will be a new file (i.e. O_CREAT | O_EXCL)
  • be owned by the current user
  • be created with mode 0600

Parameters

  • string $template
  • int $suffix_len

Returns