Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/nanosleep.c @ 6275:fd0ccce602e4
Sync from coreutils.
* .cppi-disable: Add regcomp.c, regex_internal.c, regex_internal.h,
stat-time.h.
* argmatch.h: Include verify.h
(ARGMATCH_VERIFY): Use verify rather than rolling our own.
(ARGMATCH_ASSERT): Remove; unused.
* canonicalize.c: Assume STDC_HEADERS.
* exclude.c: Include "strcase.h".
* regex_internal.h [!defined _LIBC]: Likewise.
* getusershell.c: Include stdio--.h rather than stdio.h
and stdio-safer.h.
(getusershell): Call fopen, not fopen_safer.
* save-cwd.c: Include fcntl--.h rather than fcntl.h.
Do not include unistd-safer.h.
(save_cwd): Don't call fd_safer; no longer needed
now that we include fcntl--.h.
* modules/argmatch (Depends-on): Add verify.
* modules/getloadavg (Depends-on): Depend on fcntl-safer, not
unistd-safer.
* modules/save-cwd (Depends-on): Likewise.
* backupfile.m4, calloc.m4, chown.m4, cloexec.m4, dup2.m4:
* fileblocks.m4, free.m4, ftruncate.m4, getcwd.m4, getpagesize.m4:
* getugroups.m4, group-member.m4, idcache.m4, link-follow.m4:
* mkstemp.m4, mktime.m4, mountlist.m4, nanosleep.m4, pathmax.m4:
* physmem.m4, posixver.m4, putenv.m4, safe-read.m4, same.m4:
* save-cwd.m4, stdio-safer.m4, unistd-safer.m4, unlinkdir.m4:
* userspec.m4, xgetcwd.m4, xreadlink.m4:
Don't bother checking for string.h, stdlib.h, unistd.h.
* fts.m4 (gl_FUNC_FTS_CORE): Don't require
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK; that's now the lstat
module's job.
* jm-macros.m4 (gl_MACROS): Likewise.
* prereq.m4 (gl_PREREQ): Add gl_FUNC_LSTAT.
* backupfile.c: Use ARGMATCH_VERIFY, just in case.
* posixtm.c (posixtime) [lint]: Initialize *all* of tm0, not just
the .tm_year member, since otherwise gcc-4.0 would now warn about
tm_zone, tm_gmtoff, tm_isdst, tm_yday, tm_wday.
* quotearg.c (quotearg_n_options): Change code to be suboptimal, in
order to avoid an unsuppressible warning from gcc on 64-bit systems.
* lstat.m4 (gl_FUNC_LSTAT):
Use AC_LIBSOURCES to require lstat.c and lstat.h.
Remove obsolete comment.
* xreadlink.m4: Use AC_LIBSOURCES and AC_LIBOBJ.
* xstrtod.m4: Likewise.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 23 Sep 2005 04:15:13 +0000 |
parents | 96c32553b4c6 |
children | 9dc5bb3f3359 |
rev | line source |
---|---|
2052 | 1 /* Provide a replacement for the POSIX nanosleep function. |
5813 | 2 Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. |
2052 | 3 |
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) | |
7 any later version. | |
8 | |
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. | |
13 | |
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, | |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5813
diff
changeset
|
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
2052 | 17 |
18 /* written by Jim Meyering */ | |
19 | |
6259
96c32553b4c6
Use a consistent style for including <config.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
20 #ifdef HAVE_CONFIG_H |
96c32553b4c6
Use a consistent style for including <config.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
21 # include <config.h> |
96c32553b4c6
Use a consistent style for including <config.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
22 #endif |
2270 | 23 |
24 /* Undefine nanosleep here so any prototype is not redefined to be a | |
25 prototype for rpl_nanosleep. (they'd conflict e.g., on alpha-dec-osf3.2) */ | |
26 #undef nanosleep | |
27 | |
5159 | 28 #include <stdbool.h> |
2053 | 29 #include <stdio.h> |
2052 | 30 #include <sys/types.h> |
2053 | 31 #include <signal.h> |
2052 | 32 |
2057 | 33 #include <errno.h> |
34 | |
6275 | 35 #include <unistd.h> |
2056 | 36 |
5813 | 37 #include "timespec.h" |
38 | |
2687
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
39 /* Some systems (MSDOS) don't have SIGCONT. |
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
40 Using SIGTERM here turns the signal-handling code below |
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
41 into a no-op on such systems. */ |
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
42 #ifndef SIGCONT |
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
43 # define SIGCONT SIGTERM |
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
44 #endif |
34703e371994
(SIGCONT): Define if not already defined.
Jim Meyering <jim@meyering.net>
parents:
2341
diff
changeset
|
45 |
5813 | 46 #if ! HAVE_SIGINTERRUPT |
47 # define siginterrupt(sig, flag) /* empty */ | |
48 #endif | |
2052 | 49 |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
50 static sig_atomic_t volatile suspended; |
2052 | 51 |
2053 | 52 /* Handle SIGCONT. */ |
53 | |
54 static void | |
55 sighandler (int sig) | |
56 { | |
57 suspended = 1; | |
58 } | |
59 | |
2058 | 60 /* FIXME: comment */ |
2052 | 61 |
62 static void | |
2056 | 63 my_usleep (const struct timespec *ts_delay) |
2052 | 64 { |
65 struct timeval tv_delay; | |
66 tv_delay.tv_sec = ts_delay->tv_sec; | |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
67 tv_delay.tv_usec = (ts_delay->tv_nsec + 999) / 1000; |
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
68 if (tv_delay.tv_usec == 1000000) |
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
69 { |
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
70 tv_delay.tv_sec++; |
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
71 tv_delay.tv_usec = 0; |
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
72 } |
5813 | 73 select (0, NULL, NULL, NULL, &tv_delay); |
2052 | 74 } |
75 | |
2058 | 76 /* FIXME: comment */ |
77 | |
2052 | 78 int |
2270 | 79 rpl_nanosleep (const struct timespec *requested_delay, |
2341 | 80 struct timespec *remaining_delay) |
2052 | 81 { |
5159 | 82 static bool initialized; |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
83 |
2058 | 84 /* set up sig handler */ |
5060
4e59cddb690f
nanosleep merge from coreutils
Paul Eggert <eggert@cs.ucla.edu>
parents:
3767
diff
changeset
|
85 if (! initialized) |
2058 | 86 { |
2151 | 87 #ifdef SA_NOCLDSTOP |
5813 | 88 struct sigaction oldact, newact; |
2058 | 89 newact.sa_handler = sighandler; |
90 sigemptyset (&newact.sa_mask); | |
91 newact.sa_flags = 0; | |
2053 | 92 |
2058 | 93 sigaction (SIGCONT, NULL, &oldact); |
94 if (oldact.sa_handler != SIG_IGN) | |
95 sigaction (SIGCONT, &newact, NULL); | |
2053 | 96 #else |
2058 | 97 if (signal (SIGCONT, SIG_IGN) != SIG_IGN) |
5813 | 98 { |
99 signal (SIGCONT, sighandler); | |
100 siginterrupt (SIGCONT, 1); | |
101 } | |
2053 | 102 #endif |
5159 | 103 initialized = true; |
2058 | 104 } |
2052 | 105 |
5813 | 106 suspended = 0; |
107 | |
2056 | 108 my_usleep (requested_delay); |
2052 | 109 |
2056 | 110 if (suspended) |
2052 | 111 { |
112 /* Calculate time remaining. */ | |
113 /* FIXME: the code in sleep doesn't use this, so there's no | |
114 rush to implement it. */ | |
2058 | 115 |
116 errno = EINTR; | |
2052 | 117 } |
118 | |
119 /* FIXME: Restore sig handler? */ | |
120 | |
2056 | 121 return suspended; |
2052 | 122 } |