mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2024-12-26 07:05:56 -05:00
2936c138c5
I bumped the minimum Rust version because I'm taking advantage of the rustdoc linking added in Rust 1.48: https://blog.rust-lang.org/2020/11/19/Rust-1.48.html#easier-linking-in-rustdoc
22 lines
697 B
Rust
22 lines
697 B
Rust
// This file is part of Moonfire NVR, a security camera network video recorder.
|
|
// 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.
|
|
|
|
//! Filesystem utilities.
|
|
|
|
use nix::fcntl::OFlag;
|
|
use nix::sys::stat::Mode;
|
|
use nix::NixPath;
|
|
use std::os::unix::io::{FromRawFd, RawFd};
|
|
|
|
/// Opens the given `path` within `dirfd` with the specified flags.
|
|
pub fn openat<P: ?Sized + NixPath>(
|
|
dirfd: RawFd,
|
|
path: &P,
|
|
oflag: OFlag,
|
|
mode: Mode,
|
|
) -> Result<std::fs::File, nix::Error> {
|
|
let fd = nix::fcntl::openat(dirfd, path, oflag, mode)?;
|
|
Ok(unsafe { std::fs::File::from_raw_fd(fd) })
|
|
}
|