1 /* Provide a replacement for the POSIX nanosleep function.
2 Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* written by Jim Meyering */
22 /* Undefine nanosleep here so any prototype is not redefined to be a
23 prototype for rpl_nanosleep. (they'd conflict e.g., on alpha-dec-osf3.2) */
27 #include <sys/types.h>
39 /* Some systems (MSDOS) don't have SIGCONT.
40 Using SIGTERM here turns the signal-handling code below
41 into a no-op on such systems. */
43 # define SIGCONT SIGTERM
62 my_usleep (const struct timespec
*ts_delay
)
64 struct timeval tv_delay
;
65 tv_delay
.tv_sec
= ts_delay
->tv_sec
;
66 tv_delay
.tv_usec
= ts_delay
->tv_nsec
/ 1000;
67 select (0, (void *) 0, (void *) 0, (void *) 0, &tv_delay
);
73 rpl_nanosleep (const struct timespec
*requested_delay
,
74 struct timespec
*remaining_delay
)
77 struct sigaction oldact
, newact
;
82 /* set up sig handler */
86 newact
.sa_handler
= sighandler
;
87 sigemptyset (&newact
.sa_mask
);
90 sigaction (SIGCONT
, NULL
, &oldact
);
91 if (oldact
.sa_handler
!= SIG_IGN
)
92 sigaction (SIGCONT
, &newact
, NULL
);
94 if (signal (SIGCONT
, SIG_IGN
) != SIG_IGN
)
95 signal (SIGCONT
, sighandler
);
100 my_usleep (requested_delay
);
104 /* Calculate time remaining. */
105 /* FIXME: the code in sleep doesn't use this, so there's no
106 rush to implement it. */
111 /* FIXME: Restore sig handler? */