usleep.c revision 165903
1193323Sed/*
2193323Sed * Copyright (c) 1989, 1993
3193323Sed *	The Regents of the University of California.  All rights reserved.
4193323Sed *
5193323Sed * Redistribution and use in source and binary forms, with or without
6193323Sed * modification, are permitted provided that the following conditions
7193323Sed * are met:
8193323Sed * 1. Redistributions of source code must retain the above copyright
9193323Sed *    notice, this list of conditions and the following disclaimer.
10193323Sed * 2. Redistributions in binary form must reproduce the above copyright
11193323Sed *    notice, this list of conditions and the following disclaimer in the
12193323Sed *    documentation and/or other materials provided with the distribution.
13193323Sed * 4. Neither the name of the University nor the names of its contributors
14193323Sed *    may be used to endorse or promote products derived from this software
15212904Sdim *    without specific prior written permission.
16249423Sdim *
17249423Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18249423Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19249423Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20249423Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21193323Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22193323Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23224145Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24243830Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25224145Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26224145Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27224145Sdim * SUCH DAMAGE.
28218893Sdim */
29193323Sed
30218893Sdim#if defined(LIBC_SCCS) && !defined(lint)
31218893Sdimstatic char sccsid[] = "@(#)usleep.c	8.1 (Berkeley) 6/4/93";
32218893Sdim#endif /* LIBC_SCCS and not lint */
33212904Sdim#include <sys/cdefs.h>
34212904Sdim__FBSDID("$FreeBSD: head/lib/libc/gen/usleep.c 165903 2007-01-09 00:28:16Z imp $");
35224145Sdim
36218893Sdim#include "namespace.h"
37224145Sdim#include <time.h>
38224145Sdim#include <unistd.h>
39224145Sdim#include "un-namespace.h"
40224145Sdim
41224145Sdimint
42224145Sdim__usleep(useconds)
43193323Sed	useconds_t useconds;
44224145Sdim{
45224145Sdim	struct timespec time_to_sleep;
46224145Sdim
47224145Sdim	time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
48224145Sdim	time_to_sleep.tv_sec = useconds / 1000000;
49224145Sdim	return (_nanosleep(&time_to_sleep, NULL));
50224145Sdim}
51224145Sdim
52224145Sdim__weak_reference(__usleep, usleep);
53202878Srdivacky__weak_reference(__usleep, _usleep);
54218893Sdim