From 6516695519229830ecc96b54f76a1a2371de86fd Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jackpot51@gmail.com> Date: Fri, 16 Dec 2022 17:39:30 -0700 Subject: [PATCH] Format --- src/header/stdio/lookaheadreader.rs | 5 +---- src/header/time/mod.rs | 17 +++++++---------- src/platform/pte.rs | 7 +++++-- src/sync/semaphore.rs | 12 ++++++------ 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/header/stdio/lookaheadreader.rs b/src/header/stdio/lookaheadreader.rs index 54abfd19..e3ec30cf 100644 --- a/src/header/stdio/lookaheadreader.rs +++ b/src/header/stdio/lookaheadreader.rs @@ -1,8 +1,5 @@ use super::{fseek_locked, ftell_locked, FILE, SEEK_SET}; -use crate::{ - core_io::Read, - platform::types::off_t, -}; +use crate::{core_io::Read, platform::types::off_t}; struct LookAheadBuffer { buf: *const u8, pos: isize, diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index a2071e58..785feb30 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -163,8 +163,8 @@ pub extern "C" fn clock() -> clock_t { } let ts = unsafe { ts.assume_init() }; - let clocks = ts.tv_sec * CLOCKS_PER_SEC as i64 - + (ts.tv_nsec / (1_000_000_000 / CLOCKS_PER_SEC)) as i64; + let clocks = + ts.tv_sec * CLOCKS_PER_SEC as i64 + (ts.tv_nsec / (1_000_000_000 / CLOCKS_PER_SEC)) as i64; match clock_t::try_from(clocks) { Ok(ok) => ok, Err(_err) => -1, @@ -368,10 +368,9 @@ pub unsafe extern "C" fn mktime(t: *mut tm) -> time_t { day += MONTH_DAYS[leap][month as usize] as i64; } - ( - -(day * (60 * 60 * 24) - - (((*t).tm_hour as i64) * (60 * 60) + ((*t).tm_min as i64) * 60 + (*t).tm_sec as i64)) - ) as time_t + (-(day * (60 * 60 * 24) + - (((*t).tm_hour as i64) * (60 * 60) + ((*t).tm_min as i64) * 60 + (*t).tm_sec as i64))) + as time_t } else { while year > 1970 { year -= 1; @@ -383,12 +382,10 @@ pub unsafe extern "C" fn mktime(t: *mut tm) -> time_t { day += MONTH_DAYS[leap][month as usize] as i64; } - ( - day * (60 * 60 * 24) + (day * (60 * 60 * 24) + ((*t).tm_hour as i64) * (60 * 60) + ((*t).tm_min as i64) * 60 - + (*t).tm_sec as i64 - ) as time_t + + (*t).tm_sec as i64) as time_t } } diff --git a/src/platform/pte.rs b/src/platform/pte.rs index 049f6868..7519150c 100644 --- a/src/platform/pte.rs +++ b/src/platform/pte.rs @@ -8,13 +8,16 @@ use core::{ }; use crate::{ - header::{sys_mman, time::{CLOCK_MONOTONIC, clock_gettime, timespec}}, + header::{ + sys_mman, + time::{clock_gettime, timespec, CLOCK_MONOTONIC}, + }, ld_so::{ linker::Linker, tcb::{Master, Tcb}, }, platform::{ - types::{c_int, c_uint, c_long, c_void, pid_t, size_t, time_t}, + types::{c_int, c_long, c_uint, c_void, pid_t, size_t, time_t}, Pal, Sys, }, sync::{Mutex, Semaphore}, diff --git a/src/sync/semaphore.rs b/src/sync/semaphore.rs index a12ceb17..aa38929f 100644 --- a/src/sync/semaphore.rs +++ b/src/sync/semaphore.rs @@ -3,7 +3,7 @@ use super::AtomicLock; use crate::{ - header::time::{CLOCK_MONOTONIC, clock_gettime, timespec}, + header::time::{clock_gettime, timespec, CLOCK_MONOTONIC}, platform::{types::*, Pal, Sys}, }; @@ -33,13 +33,13 @@ impl Semaphore { value, value - 1, Ordering::SeqCst, - Ordering::SeqCst + Ordering::SeqCst, ) { Ok(_) => { // Acquired return Ok(()); } - Err(_) => () + Err(_) => (), } // Try again (as long as value > 0) continue; @@ -47,11 +47,11 @@ impl Semaphore { if let Some(timeout) = timeout_opt { let mut time = timespec::default(); clock_gettime(CLOCK_MONOTONIC, &mut time); - if (time.tv_sec > timeout.tv_sec) || - (time.tv_sec == timeout.tv_sec && time.tv_nsec >= timeout.tv_nsec) + if (time.tv_sec > timeout.tv_sec) + || (time.tv_sec == timeout.tv_sec && time.tv_nsec >= timeout.tv_nsec) { //Timeout happened, return error - return Err(()) + return Err(()); } else { // Use futex to wait for the next change, with a relative timeout let mut relative = timespec { -- GitLab