From a9cf7baf68bff744ba95ca8a2a02cbed6233696d Mon Sep 17 00:00:00 2001 From: Arcterus Date: Sat, 14 Jun 2014 23:56:59 -0700 Subject: [PATCH] sleep: handle infinity --- sleep/sleep.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sleep/sleep.rs b/sleep/sleep.rs index 5f07ac40f..b67d1ba85 100644 --- a/sleep/sleep.rs +++ b/sleep/sleep.rs @@ -14,9 +14,10 @@ extern crate getopts; extern crate libc; -use std::num; +use std::f64; use std::os; use std::io::{print, timer}; +use std::u64; #[path = "../common/util.rs"] mod util; @@ -79,7 +80,7 @@ fn sleep(args: Vec) { if suffix_time == 0 { 0.0 } else { - match num::from_str_radix::((arg.as_slice()), 10) { + match from_str::(arg.as_slice()) { Some(m) => m, None => { crash!(1, "Invalid time interval '{}'", arg.to_string()) @@ -88,7 +89,7 @@ fn sleep(args: Vec) { }; result + num * suffix_time as f64 }); - timer::sleep((sleep_time * 1000.0) as u64); + timer::sleep(if sleep_time == f64::INFINITY { u64::MAX } else { (sleep_time * 1000.0) as u64 }); } fn match_suffix(arg: &str) -> Result<(String, int), String> { @@ -100,6 +101,8 @@ fn match_suffix(arg: &str) -> Result<(String, int), String> { val => { if !val.is_alphabetic() { return Ok((arg.to_string(), 1)) + } else if arg == "inf" || arg == "infinity" { + return Ok(("inf".to_string(), 1)) } else { return Err(format!("Invalid time interval '{}'", arg)) }