From 52790ee2fb7b813ff56704a20190bd36e42e17dd Mon Sep 17 00:00:00 2001 From: Kamal Marhubi Date: Wed, 13 Apr 2016 21:55:24 -0400 Subject: unistd: Add sleep(3) --- src/unistd.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/unistd.rs b/src/unistd.rs index 4a7359cc..c7e88971 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -3,7 +3,7 @@ use {Errno, Error, Result, NixPath}; use fcntl::{fcntl, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC}; use fcntl::FcntlArg::{F_SETFD, F_SETFL}; -use libc::{self, c_char, c_void, c_int, size_t, pid_t, off_t, uid_t, gid_t}; +use libc::{self, c_char, c_void, c_int, c_uint, size_t, pid_t, off_t, uid_t, gid_t}; use std::mem; use std::ffi::CString; use std::os::unix::io::RawFd; @@ -366,6 +366,13 @@ pub fn pause() -> Result<()> { Errno::result(res).map(drop) } +#[inline] +// Per POSIX, does not fail: +// http://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html#tag_03_705_05 +pub fn sleep(seconds: libc::c_uint) -> c_uint { + unsafe { libc::sleep(seconds) } +} + #[cfg(any(target_os = "linux", target_os = "android"))] mod linux { use sys::syscall::{syscall, SYSPIVOTROOT}; -- cgit v1.2.3