Per XPG4.2:

* Change argument to type useconds_t, return an int.
* If an interval of 1,000,000 or more microseconds was requested, fail with
  -1/EINVAL.
This commit is contained in:
kleink 1997-11-24 19:56:30 +00:00
parent c4f2dabf21
commit a57dd5b211
2 changed files with 39 additions and 10 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: usleep.3,v 1.7 1997/11/02 07:23:09 mycroft Exp $
.\" $NetBSD: usleep.3,v 1.8 1997/11/24 19:56:30 kleink Exp $
.\"
.\" Copyright (c) 1986, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -41,8 +41,8 @@
.Nd suspend execution for interval of microseconds
.Sh SYNOPSIS
.Fd #include <unistd.h>
.Ft void
.Fn usleep "unsigned int microseconds"
.Ft int
.Fn usleep "useconds_t microseconds"
.Sh DESCRIPTION
The
.Fn usleep
@ -54,13 +54,34 @@ have elapsed or a signal is delivered to the calling process and its
action is to invoke a signal catching function or to terminate the
process. The suspension time may be longer than requested due to the
scheduling of other activity by the system.
.Pp
The
.Fa microseconds
argument must be less than 1,000,000. If The value of
.Fa microseconds
is 0, then the call has no effect.
.Sh RETURN VALUE
On successful completition,
.Fn usleep
returns 0. Otherwhise, it returns -1 and sets errno to indicate the error.
.Sh ERRORS
The
.Fn usleep
function returns no value.
function may fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The
.Fa microseconds
interval specified 1,000,000 or more microseconds.
.El
.Sh SEE ALSO
.Xr nanosleep 2 ,
.Xr sleep 3
.Sh STANDARDS
The
.Fn usleep
function conforms to
.St -xpg4.2 .
.Sh HISTORY
The
.Fn usleep

View File

@ -1,4 +1,4 @@
/* $NetBSD: usleep.c,v 1.15 1997/08/19 04:34:15 mikel Exp $ */
/* $NetBSD: usleep.c,v 1.16 1997/11/24 19:56:32 kleink Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -38,10 +38,11 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: usleep.c,v 1.15 1997/08/19 04:34:15 mikel Exp $");
__RCSID("$NetBSD: usleep.c,v 1.16 1997/11/24 19:56:32 kleink Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <errno.h>
#include <time.h>
#include <unistd.h>
@ -49,14 +50,21 @@ __RCSID("$NetBSD: usleep.c,v 1.15 1997/08/19 04:34:15 mikel Exp $");
__weak_alias(usleep,_usleep);
#endif
void
int
usleep(useconds)
unsigned int useconds;
useconds_t useconds;
{
struct timespec ts;
ts.tv_sec = useconds / 1000000;
ts.tv_nsec = (useconds % 1000000) * 1000;
if (useconds >= 1000000) {
errno = EINVAL;
return (-1);
}
ts.tv_sec = 0;
ts.tv_nsec = useconds * 1000;
nanosleep(&ts, NULL);
return (0);
}