2019-07-12 14:05:36 -04:00
|
|
|
// This file is part of Moonfire NVR, a security camera network video recorder.
|
2021-02-17 16:28:48 -05:00
|
|
|
// Copyright (C) 2019 The Moonfire NVR Authors; see AUTHORS and LICENSE.txt.
|
|
|
|
// SPDX-License-Identifier: GPL-v3.0-or-later WITH GPL-3.0-linking-exception.
|
2019-07-12 14:05:36 -04:00
|
|
|
|
|
|
|
use nix::fcntl::OFlag;
|
|
|
|
use nix::sys::stat::Mode;
|
2021-02-17 01:15:54 -05:00
|
|
|
use nix::NixPath;
|
|
|
|
use std::os::unix::io::{FromRawFd, RawFd};
|
2019-07-12 14:05:36 -04:00
|
|
|
|
2021-02-17 01:15:54 -05:00
|
|
|
pub fn openat<P: ?Sized + NixPath>(
|
|
|
|
dirfd: RawFd,
|
|
|
|
path: &P,
|
|
|
|
oflag: OFlag,
|
|
|
|
mode: Mode,
|
|
|
|
) -> Result<std::fs::File, nix::Error> {
|
2019-07-12 14:05:36 -04:00
|
|
|
let fd = nix::fcntl::openat(dirfd, path, oflag, mode)?;
|
|
|
|
Ok(unsafe { std::fs::File::from_raw_fd(fd) })
|
|
|
|
}
|