function open()

in src/os/open.php [39:64]


function open(string $path, int $flags, ?int $mode = null): FileDescriptor {
  if (
    ($flags & O_RDONLY) !== O_RDONLY &&
    ($flags & O_WRONLY) !== O_WRONLY &&
    ($flags & O_RDWR) !== O_RDWR
  ) {
    _OS\throw_errno(
      Errno::EINVAL,
      'O_RDONLY, O_WRONLY, or O_RDWR must be specified',
    );
  }
  if ($mode !== null && ($flags & O_CREAT) !== O_CREAT) {
    _OS\throw_errno(
      Errno::EINVAL,
      'mode should only be specified in combination with O_CREAT',
    );
  }
  if (($flags & O_CREAT) && $mode === null) {
    _OS\throw_errno(
      Errno::EINVAL,
      'mode must be specified when O_CREAT is specified',
    );
  }
  $flags |= _OS\O_CLOEXEC;
  return _OS\wrap_impl(() ==> _OS\open($path, $flags, $mode ?? 0));
}