2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)usleep.c 1.17 03/06/15 Copyright 1995-2003 J. Schilling */
15 * Copyright (c) 1995-2003 J. Schilling
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2
20 * as published by the Free Software Foundation.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License along with
28 * this program; see the file COPYING. If not, write to the Free Software
29 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #define usleep __nothing_ /* prototype in unistd.h may be different */
40 # ifdef HAVE_SYS_POLL_H
41 # include <sys/poll.h>
44 #ifdef HAVE_SYS_SYSTEMINFO_H
45 #include <sys/systeminfo.h>
51 EXPORT int usleep __PR((int usec));
56 * Don't use the usleep() from libc on SCO's OPENSERVER.
57 * It will kill our processes with SIGALRM.
58 * SCO has a usleep() prototype in unistd.h, for this reason we
59 * #define usleep to __nothing__ before including unistd.h
66 * Apollo sys5.3 usleep is broken. Define a version based on time_$wait.
68 #include <apollo/base.h>
69 #include <apollo/time.h>
73 #if !defined(HAVE_USLEEP)
81 * Need to check apollo before HAVE_SELECT, because Apollo has select,
82 * but it's time wait feature is also broken :-(
86 * XXX Do these vars need to be static on Domain/OS ???
88 static time_$clock_t DomainDelay;
89 static status_$t DomainStatus;
92 * DomainDelay is a 48 bit value that defines how many 4uS periods to
93 * delay. Since the input value range is 32 bits, the upper 16 bits of
94 * DomainDelay must be zero. So we just divide the input value by 4 to
95 * determine how many "ticks" to wait
97 DomainDelay.c2.high16 = 0;
98 DomainDelay.c2.low32 = usec / 4;
99 time_$wait(time_$relative, DomainDelay, &DomainStatus);
102 #if defined(HAVE_SELECT) && !defined(HAVE_USLEEP)
106 tv.tv_sec = usec / 1000000;
107 tv.tv_usec = usec % 1000000;
108 select(0, 0, 0, 0, &tv);
111 #if defined(HAVE_POLL) && !defined(HAVE_USLEEP)
114 if (poll(0, 0, usec/1000) < 0)
115 comerr("poll delay failed.\n");
119 #if defined(HAVE_NANOSLEEP) && !defined(HAVE_USLEEP)
124 ts.tv_sec = usec / 1000000;
125 ts.tv_nsec = (usec % 1000000) * 1000;
131 #if !defined(HAVE_USLEEP)
134 sleep((usec+500000)/1000000);