2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: sleep.c /main/3 1995/11/01 16:29:36 rswiston $ */
24 /***************************************************************
26 * AT&T - PROPRIETARY *
28 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF *
29 * AT&T BELL LABORATORIES *
30 * AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN *
31 * ACCORDANCE WITH APPLICABLE AGREEMENTS *
33 * Copyright (c) 1995 AT&T Corp. *
34 * Unpublished & Not for Publication *
35 * All Rights Reserved *
37 * The copyright notice above does not evidence any *
38 * actual or intended publication of such source code *
40 * This software was created by the *
41 * Advanced Software Technology Department *
42 * AT&T Bell Laboratories *
44 * For further information contact *
45 * {research,attmail}!dgk *
47 ***************************************************************/
49 /* : : generated by proto : : */
51 #if !defined(__PROTO__)
52 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
53 #if defined(__cplusplus)
54 #define __MANGLE__ "C"
59 #define __PROTO__(x) x
61 #define __PARAM__(n,o) n
62 #if !defined(__STDC__) && !defined(__cplusplus)
63 #if !defined(c_plusplus)
74 #define __PROTO__(x) ()
75 #define __OTORP__(x) x
76 #define __PARAM__(n,o) o
84 #if defined(__cplusplus) || defined(c_plusplus)
85 #define __VARARG__ ...
89 #if defined(__STDARG__)
90 #define __VA_START__(p,a) va_start(p,a)
92 #define __VA_START__(p,a) va_start(p)
99 #include "FEATURE/time"
100 #include "FEATURE/poll"
102 # define sleep _ast_sleep
103 #endif /* _NEXT_SOURCE */
104 #ifdef _lib_poll_notimer
106 #endif /* _lib_poll_notimer */
108 int b_sleep __PARAM__((register int argc,char *argv[],__V_ *extra), (argc, argv, extra)) __OTORP__(register int argc;char *argv[];__V_ *extra;){
113 while((argc = optget(argv,sh_optsleep))) switch(argc)
119 error(ERROR_usage(2), opt_arg);
123 if(error_info.errors || !(cp= *argv) || !(strmatch(cp,e_numeric)))
124 error(ERROR_usage(2),optusage((char*)0));
125 if((d=atof(cp)) > 1.0)
129 tloc += (time_t)(d+.5);
137 if(tloc==0 || errno!=EINTR || sh.lastsig)
140 if(tloc < (now=time(NIL(time_t*))))
142 d = (double)(tloc-now);
143 if(sh.sigflag[SIGALRM]&SH_SIGTRAP)
150 static void completed __PARAM__((__V_ * handle), (handle)) __OTORP__(__V_ * handle;){
155 unsigned sleep __PARAM__((unsigned sec), (sec)) __OTORP__(unsigned sec;){
156 pid_t newpid, curpid=getpid();
160 tp = (__V_*)kshtimeradd(1000*sec, 0, completed, (__V_*)0);
164 if(sh.sigflag[SIGALRM]&SH_SIGTRAP)
166 if((newpid=getpid()) != curpid)
172 while(!expired && sh.lastsig==0);
180 * delay execution for time <t>
183 void sh_delay __PARAM__((double t), (t)) __OTORP__(double t;){
184 register int n = (int)t;
197 # if defined(_lib_select) && defined(_mem_tv_usec_timeval)
198 struct timeval timeloc;
202 timeloc.tv_usec = 1000000*(t-(double)n);
203 select(0,(fd_set*)0,(fd_set*)0,(fd_set*)0,&timeloc);
206 /* for 9th edition machines */
215 select(0,(fd_set*)0,(fd_set*)0,n);
224 clock_t begin = times(&tt);
229 while((times(&tt)-begin) < n);
233 #endif /* _lib_poll */