usleep.c revision 200150
1236769Sobrien/*
2236769Sobrien * Copyright (c) 1989, 1993
3236769Sobrien *	The Regents of the University of California.  All rights reserved.
4236769Sobrien *
5236769Sobrien * Redistribution and use in source and binary forms, with or without
6236769Sobrien * modification, are permitted provided that the following conditions
7236769Sobrien * are met:
8236769Sobrien * 1. Redistributions of source code must retain the above copyright
9236769Sobrien *    notice, this list of conditions and the following disclaimer.
10236769Sobrien * 2. Redistributions in binary form must reproduce the above copyright
11236769Sobrien *    notice, this list of conditions and the following disclaimer in the
12236769Sobrien *    documentation and/or other materials provided with the distribution.
13236769Sobrien * 4. Neither the name of the University nor the names of its contributors
14236769Sobrien *    may be used to endorse or promote products derived from this software
15236769Sobrien *    without specific prior written permission.
16236769Sobrien *
17236769Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18236769Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19236769Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20236769Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21236769Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22236769Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23236769Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24236769Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25236769Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26236769Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27236769Sobrien * SUCH DAMAGE.
28236769Sobrien */
29236769Sobrien
30236769Sobrien#if defined(LIBC_SCCS) && !defined(lint)
31236769Sobrienstatic char sccsid[] = "@(#)usleep.c	8.1 (Berkeley) 6/4/93";
32236769Sobrien#endif /* LIBC_SCCS and not lint */
33236769Sobrien#include <sys/cdefs.h>
34236769Sobrien__FBSDID("$FreeBSD: head/lib/libc/gen/usleep.c 200150 2009-12-05 19:31:38Z ed $");
35236769Sobrien
36236769Sobrien#include "namespace.h"
37236769Sobrien#include <time.h>
38236769Sobrien#include <unistd.h>
39236769Sobrien#include "un-namespace.h"
40236769Sobrien
41236769Sobrienint
42236769Sobrien__usleep(useconds_t useconds)
43236769Sobrien{
44236769Sobrien	struct timespec time_to_sleep;
45236769Sobrien
46236769Sobrien	time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
47236769Sobrien	time_to_sleep.tv_sec = useconds / 1000000;
48236769Sobrien	return (_nanosleep(&time_to_sleep, NULL));
49236769Sobrien}
50236769Sobrien
51236769Sobrien__weak_reference(__usleep, usleep);
52236769Sobrien__weak_reference(__usleep, _usleep);
53236769Sobrien