usleep.c revision 30443
1266423Sjfv/*
2266423Sjfv * Copyright (c) 1989, 1993
3279033Sjfv *	The Regents of the University of California.  All rights reserved.
4266423Sjfv *
5266423Sjfv * Redistribution and use in source and binary forms, with or without
6266423Sjfv * modification, are permitted provided that the following conditions
7266423Sjfv * are met:
8266423Sjfv * 1. Redistributions of source code must retain the above copyright
9266423Sjfv *    notice, this list of conditions and the following disclaimer.
10266423Sjfv * 2. Redistributions in binary form must reproduce the above copyright
11266423Sjfv *    notice, this list of conditions and the following disclaimer in the
12266423Sjfv *    documentation and/or other materials provided with the distribution.
13266423Sjfv * 3. All advertising materials mentioning features or use of this software
14266423Sjfv *    must display the following acknowledgement:
15266423Sjfv *	This product includes software developed by the University of
16266423Sjfv *	California, Berkeley and its contributors.
17266423Sjfv * 4. Neither the name of the University nor the names of its contributors
18266423Sjfv *    may be used to endorse or promote products derived from this software
19266423Sjfv *    without specific prior written permission.
20266423Sjfv *
21266423Sjfv * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22266423Sjfv * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23266423Sjfv * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24266423Sjfv * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25266423Sjfv * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26266423Sjfv * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27266423Sjfv * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28266423Sjfv * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29266423Sjfv * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30266423Sjfv * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31266423Sjfv * SUCH DAMAGE.
32266423Sjfv */
33266423Sjfv
34266423Sjfv#if defined(LIBC_SCCS) && !defined(lint)
35266423Sjfvstatic char sccsid[] = "@(#)usleep.c	8.1 (Berkeley) 6/4/93";
36266423Sjfv#endif /* LIBC_SCCS and not lint */
37266423Sjfv
38266423Sjfv#include <errno.h>
39266423Sjfv#include <sys/time.h>
40266423Sjfv#include <signal.h>
41266423Sjfv#include <unistd.h>
42266423Sjfv
43266423Sjfvvoid
44270346Sjfvusleep(useconds)
45299549Serj	unsigned int useconds;
46266423Sjfv{
47266423Sjfv	struct timespec time_to_sleep;
48266423Sjfv
49266423Sjfv	if (useconds) {
50266423Sjfv		time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
51266423Sjfv		time_to_sleep.tv_sec = useconds / 1000000;
52266423Sjfv		(void)nanosleep(&time_to_sleep, NULL);
53266423Sjfv	}
54266423Sjfv}
55266423Sjfv