usleep.c revision 30649
155714Skris/* 255714Skris * Copyright (c) 1989, 1993 355714Skris * The Regents of the University of California. All rights reserved. 455714Skris * 555714Skris * Redistribution and use in source and binary forms, with or without 655714Skris * modification, are permitted provided that the following conditions 755714Skris * are met: 8296465Sdelphij * 1. Redistributions of source code must retain the above copyright 955714Skris * notice, this list of conditions and the following disclaimer. 1055714Skris * 2. Redistributions in binary form must reproduce the above copyright 1155714Skris * notice, this list of conditions and the following disclaimer in the 1255714Skris * documentation and/or other materials provided with the distribution. 1355714Skris * 3. All advertising materials mentioning features or use of this software 1455714Skris * must display the following acknowledgement: 15296465Sdelphij * This product includes software developed by the University of 1655714Skris * California, Berkeley and its contributors. 1755714Skris * 4. Neither the name of the University nor the names of its contributors 1855714Skris * may be used to endorse or promote products derived from this software 1955714Skris * without specific prior written permission. 2055714Skris * 2155714Skris * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22296465Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3155714Skris * SUCH DAMAGE. 3255714Skris */ 3355714Skris 3455714Skris#if defined(LIBC_SCCS) && !defined(lint) 3555714Skris#if 0 3655714Skrisstatic char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93"; 37296465Sdelphij#endif 3855714Skrisstatic char rcsid[] = 3955714Skris "$Id: usleep.c,v 1.20 1997/10/22 10:55:49 ache Exp $"; 40296465Sdelphij#endif /* LIBC_SCCS and not lint */ 4155714Skris 4255714Skris#include <time.h> 4355714Skris#include <unistd.h> 4455714Skris 4555714Skrisint 4655714Skrisusleep(useconds) 4755714Skris unsigned int useconds; 4855714Skris{ 4955714Skris struct timespec time_to_sleep; 5055714Skris 5155714Skris if (useconds) { 52296465Sdelphij time_to_sleep.tv_nsec = (useconds % 1000000) * 1000; 5355714Skris time_to_sleep.tv_sec = useconds / 1000000; 5455714Skris return nanosleep(&time_to_sleep, NULL); 5555714Skris } 5655714Skris return 0; 5755714Skris} 5855714Skris