mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-12-25 04:14:06 +00:00
Add "Fd" wrapper for RawFd type.
This allows more type-safe usage of RawFds (preventing confusion with other c_ints) and provides a lightweight type that is usable in arguments to methods that take parameters of type AsRawFd. BUG=None TEST=Built. Change-Id: Ibdeb03b0e759577385b05acb25ce76d51f2188c6 Reviewed-on: https://chromium-review.googlesource.com/1396495 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Miriam Zimmerman <mutexlox@chromium.org> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
This commit is contained in:
parent
70eb15dbb7
commit
3a794ccb25
2 changed files with 18 additions and 0 deletions
|
@ -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::*;
|
||||
|
|
16
sys_util/src/raw_fd.rs
Normal file
16
sys_util/src/raw_fd.rs
Normal file
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue