diff --git a/sys_util/src/lib.rs b/sys_util/src/lib.rs index 185489c00f..141c8b5886 100644 --- a/sys_util/src/lib.rs +++ b/sys_util/src/lib.rs @@ -29,6 +29,7 @@ mod mmap; mod passwd; mod poll; mod priority; +mod raw_fd; mod seek_hole; mod shm; pub mod signal; @@ -53,6 +54,7 @@ pub use passwd::*; pub use poll::*; pub use poll_token_derive::*; pub use priority::*; +pub use raw_fd::*; pub use shm::*; pub use signal::*; pub use signalfd::*; diff --git a/sys_util/src/raw_fd.rs b/sys_util/src/raw_fd.rs new file mode 100644 index 0000000000..05a762f289 --- /dev/null +++ b/sys_util/src/raw_fd.rs @@ -0,0 +1,16 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Utility file to provide a slightly safer Fd type that cannot be confused with c_int. +// Also useful for situations that require something that is `AsRawFd` but +// where we don't want to store more than the fd. + +use std::os::unix::io::{AsRawFd, RawFd}; + +pub struct Fd(pub RawFd); +impl AsRawFd for Fd { + fn as_raw_fd(&self) -> RawFd { + self.0 + } +}