diff options
author | ache <ache@FreeBSD.org> | 1997-10-22 10:55:49 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1997-10-22 10:55:49 +0000 |
commit | 6591ace30df695776afa477387833fabdc74ac40 (patch) | |
tree | 1e15b3761d43e43e134f1857c8513eaa2ca45a1c /lib | |
parent | 1eff2f520cc557b5a426d13e46337d039c5b7953 (diff) | |
download | FreeBSD-src-6591ace30df695776afa477387833fabdc74ac40.zip FreeBSD-src-6591ace30df695776afa477387833fabdc74ac40.tar.gz |
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)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/usleep.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c index 5141d36..03df495 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 <errno.h> #include <time.h> #include <unistd.h> -void +int usleep(useconds) unsigned int useconds; { struct timespec time_to_sleep; + if (useconds >= 1000000) { + errno = EINVAL; + return -1; + } if (useconds) { - time_to_sleep.tv_nsec = (useconds % 1000000) * 1000; - time_to_sleep.tv_sec = useconds / 1000000; - (void)nanosleep(&time_to_sleep, NULL); + time_to_sleep.tv_nsec = useconds * 1000; + time_to_sleep.tv_sec = 0; + return nanosleep(&time_to_sleep, NULL); } + return 0; } |