function mkostemps()

in src/os/mkostemps.php [44:71]


function mkostemps(
  string $template,
  int $suffix_length,
  int $flags,
): (FileDescriptor, string) {
  _OS\arg_assert($suffix_length >= 0, 'Suffix length must not be negative');
  _OS\arg_assert(
    Str\length($template) >= $suffix_length + 6,
    'Suffix length must be at most 6 less than the length of the template',
  );
  if ($suffix_length === 0) {
    _OS\arg_assert(
      Str\ends_with($template, 'XXXXXX'),
      'Template must end with exactly 6 `X` characters',
    );
  } else if ($suffix_length > 0) {
    $base = Str\slice($template, 0, Str\length($template) - $suffix_length);
    _OS\arg_assert(
      Str\ends_with($base, 'XXXXXX'),
      'Template must be of form prefixXXXXXXsuffix - exactly 6 `X` '.
      'characters are required',
    );
  }
  // We do not want LightProcess to be observable.
  $flags |= O_CLOEXEC;

  return _OS\wrap_impl(() ==> _OS\mkostemps($template, $suffix_length, $flags));
}