Skip to content

Commit 4bb24bb

Browse files
committed
Hide file descriptor on non-linux platforms.
1 parent 4b15caa commit 4bb24bb

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/unix.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use crate::{Clock, LeapIndicator, TimeOffset, Timestamp};
2+
use std::time::Duration;
3+
#[cfg(target_os = "linux")]
24
use std::{
3-
os::unix::io::{FromRawFd, IntoRawFd, RawFd},
5+
os::unix::io::{IntoRawFd, RawFd},
46
path::Path,
5-
time::Duration,
67
};
78

89
/// A Unix OS clock
910
#[derive(Debug, Clone, Copy)]
1011
pub struct UnixClock {
1112
clock: libc::clockid_t,
13+
#[cfg(target_os = "linux")]
1214
fd: Option<RawFd>,
1315
}
1416

@@ -29,6 +31,7 @@ impl UnixClock {
2931
/// ```
3032
pub const CLOCK_REALTIME: Self = UnixClock {
3133
clock: libc::CLOCK_REALTIME,
34+
#[cfg(target_os = "linux")]
3235
fd: None,
3336
};
3437

@@ -46,6 +49,7 @@ impl UnixClock {
4649
/// Ok(())
4750
/// }
4851
/// ```
52+
#[cfg(target_os = "linux")]
4953
pub fn open(path: impl AsRef<Path>) -> std::io::Result<Self> {
5054
let file = std::fs::OpenOptions::new()
5155
.write(true)
@@ -59,6 +63,7 @@ impl UnixClock {
5963
// Consume an fd and produce a clock id. Clock id is only valid
6064
// so long as the fd is open, so the RawFd here should
6165
// not be borrowed.
66+
#[cfg(target_os = "linux")]
6267
fn safe_from_raw_fd(fd: RawFd) -> Self {
6368
let clock = ((!(fd as libc::clockid_t)) << 3) | 3;
6469

@@ -430,12 +435,6 @@ impl UnixClock {
430435
}
431436
}
432437

433-
impl FromRawFd for UnixClock {
434-
unsafe fn from_raw_fd(fd: RawFd) -> Self {
435-
Self::safe_from_raw_fd(fd)
436-
}
437-
}
438-
439438
impl Clock for UnixClock {
440439
type Error = Error;
441440

0 commit comments

Comments
 (0)