From 9a9098177b3fe7d0df13181222da7db246113961 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Wed, 22 Oct 1997 10:55:49 +0000 Subject: [PATCH] Changes in spirit of OpenGroup Singe Unix specs: 1) Limit max allowed argument to 1000000 2) Change return type from void to int to indicate premature termination (by signal) --- lib/libc/gen/usleep.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c index 5141d363edf9..03df4953de52 100644 --- a/lib/libc/gen/usleep.c +++ b/lib/libc/gen/usleep.c @@ -36,21 +36,27 @@ static char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93"; #endif static char rcsid[] = - "$Id$"; + "$Id: usleep.c,v 1.19 1997/10/17 09:40:08 ache Exp $"; #endif /* LIBC_SCCS and not lint */ +#include #include #include -void +int usleep(useconds) unsigned int useconds; { struct timespec time_to_sleep; - if (useconds) { - time_to_sleep.tv_nsec = (useconds % 1000000) * 1000; - time_to_sleep.tv_sec = useconds / 1000000; - (void)nanosleep(&time_to_sleep, NULL); + if (useconds >= 1000000) { + errno = EINVAL; + return -1; } + if (useconds) { + time_to_sleep.tv_nsec = useconds * 1000; + time_to_sleep.tv_sec = 0; + return nanosleep(&time_to_sleep, NULL); + } + return 0; }