usleep.c revision 30646
1145510Sdarrenr/* 2145510Sdarrenr * Copyright (c) 1989, 1993 3145510Sdarrenr * The Regents of the University of California. All rights reserved. 4145510Sdarrenr * 5145510Sdarrenr * Redistribution and use in source and binary forms, with or without 6145510Sdarrenr * modification, are permitted provided that the following conditions 7145510Sdarrenr * are met: 8145510Sdarrenr * 1. Redistributions of source code must retain the above copyright 9145510Sdarrenr * notice, this list of conditions and the following disclaimer. 10145510Sdarrenr * 2. Redistributions in binary form must reproduce the above copyright 11145510Sdarrenr * notice, this list of conditions and the following disclaimer in the 12145510Sdarrenr * documentation and/or other materials provided with the distribution. 13145510Sdarrenr * 3. All advertising materials mentioning features or use of this software 14145510Sdarrenr * must display the following acknowledgement: 15145510Sdarrenr * This product includes software developed by the University of 16145510Sdarrenr * California, Berkeley and its contributors. 17145510Sdarrenr * 4. Neither the name of the University nor the names of its contributors 18145510Sdarrenr * may be used to endorse or promote products derived from this software 19145510Sdarrenr * without specific prior written permission. 20145510Sdarrenr * 21145510Sdarrenr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22145510Sdarrenr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23145510Sdarrenr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24145510Sdarrenr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25145510Sdarrenr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26145510Sdarrenr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27145510Sdarrenr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28145510Sdarrenr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29145510Sdarrenr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30145510Sdarrenr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31145510Sdarrenr * SUCH DAMAGE. 32145510Sdarrenr */ 33145510Sdarrenr 34145510Sdarrenr#if defined(LIBC_SCCS) && !defined(lint) 35145510Sdarrenr#if 0 36145510Sdarrenrstatic char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93"; 37#endif 38static char rcsid[] = 39 "$Id: usleep.c,v 1.19 1997/10/17 09:40:08 ache Exp $"; 40#endif /* LIBC_SCCS and not lint */ 41 42#include <errno.h> 43#include <time.h> 44#include <unistd.h> 45 46int 47usleep(useconds) 48 unsigned int useconds; 49{ 50 struct timespec time_to_sleep; 51 52 if (useconds >= 1000000) { 53 errno = EINVAL; 54 return -1; 55 } 56 if (useconds) { 57 time_to_sleep.tv_nsec = useconds * 1000; 58 time_to_sleep.tv_sec = 0; 59 return nanosleep(&time_to_sleep, NULL); 60 } 61 return 0; 62} 63