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)
This commit is contained in:
Andrey A. Chernov 1997-10-22 10:55:49 +00:00
parent 56728a2905
commit 9a9098177b
1 changed files with 12 additions and 6 deletions

View File

@ -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) {
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;
}