mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-30 13:44:55 +00:00
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:
parent
56728a2905
commit
9a9098177b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=30646
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue