Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ dependencies = [

[[package]]
name = "libc"
version = "0.2.178"
version = "0.2.183"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ miniz_oxide = { version = "0.8.0", optional = true, default-features = false }
addr2line = { version = "0.25.0", optional = true, default-features = false }

[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.178", default-features = false, features = [
libc = { version = "0.2.183", default-features = false, features = [
'rustc-dep-of-std',
], public = true }

Expand Down
7 changes: 6 additions & 1 deletion library/std/src/sys/fs/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,12 @@ fn file_time_to_timespec(time: Option<SystemTime>) -> io::Result<libc::timespec>
io::ErrorKind::InvalidInput,
"timestamp is too small to set as a file time",
)),
None => Ok(libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }),
None => Ok({
let mut ts = libc::timespec::default();
ts.tv_sec = 0;
ts.tv_nsec = libc::UTIME_OMIT as _;
ts
}),
}
}

Expand Down
17 changes: 12 additions & 5 deletions library/std/src/sys/pal/unix/time.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::mem;
use core::num::niche_types::Nanoseconds;

use crate::io;
Expand All @@ -6,8 +7,12 @@ use crate::time::Duration;
const NSEC_PER_SEC: u64 = 1_000_000_000;

#[allow(dead_code)] // Used for pthread condvar timeouts
pub const TIMESPEC_MAX: libc::timespec =
libc::timespec { tv_sec: <libc::time_t>::MAX, tv_nsec: 1_000_000_000 - 1 };
pub const TIMESPEC_MAX: libc::timespec = {
let mut ts = unsafe { mem::zeroed::<libc::timespec>() };
ts.tv_sec = <libc::time_t>::MAX;
ts.tv_nsec = 1_000_000_000 - 1;
ts
};

// This additional constant is only used when calling
// `libc::pthread_cond_timedwait`.
Expand Down Expand Up @@ -164,9 +169,11 @@ impl Timespec {

#[allow(dead_code)]
pub fn to_timespec(&self) -> Option<libc::timespec> {
Some(libc::timespec {
tv_sec: self.tv_sec.try_into().ok()?,
tv_nsec: self.tv_nsec.as_inner().try_into().ok()?,
Some({
let mut ts = libc::timespec::default();
ts.tv_sec = self.tv_sec.try_into().ok()?;
ts.tv_nsec = self.tv_nsec.as_inner().try_into().ok()?;
ts
})
}

Expand Down
8 changes: 4 additions & 4 deletions library/std/src/sys/thread/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,10 @@ pub fn sleep(dur: Duration) {
// nanosleep will fill in `ts` with the remaining time.
unsafe {
while secs > 0 || nsecs > 0 {
let mut ts = libc::timespec {
tv_sec: cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t,
tv_nsec: nsecs,
};
let mut ts = libc::timespec::default();
ts.tv_sec = cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t;
ts.tv_nsec = nsecs;

secs -= ts.tv_sec as u64;
let ts_ptr = &raw mut ts;
let r = nanosleep(ts_ptr, ts_ptr);
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/time/unsupported.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::time::Duration;

Comment on lines -1 to -2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, looks like an accidental removal

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub struct Instant(Duration);

Expand Down
Loading