RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / rust / coreutils-rs / src / bin / sleep.rs
622 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! sleep N -- wait N seconds (or `sleep 250ms`). The kernel blocks the
//! thread until the timer says it's time; no CPU is used meanwhile.
#![no_std]
#![no_main]

#[macro_use]
#[path = "ulib.rs"]
mod ulib;

use ulib::*;

fn main() -> i64 {
    let a = arg(1).unwrap_or("");
    let ms = match a.strip_suffix("ms") {
        Some(n) => n.parse::<u64>().ok(),
        None => a.parse::<u64>().ok().map(|s| s * 1000),
    };
    match ms {
        Some(ms) => {
            sleep_ms(ms);
            0
        }
        None => {
            eprintln!("usage: sleep seconds | sleep 250ms");
            2
        }
    }
}