diff options
| author | Joakim Verona | 2011-07-15 04:39:29 +0200 |
|---|---|---|
| committer | Joakim Verona | 2011-07-15 04:39:29 +0200 |
| commit | 4f616a2e7ed1db28da98df90266e9751a8ae9ee1 (patch) | |
| tree | 74a9dcbe13e945e712ae04a4a94c2202ca720591 /lib | |
| parent | ff2be00005c3aeda6e11d7ed264ce86f02b60958 (diff) | |
| parent | ec2bc542a4d0127425625e8cb458684bd825675a (diff) | |
| download | emacs-4f616a2e7ed1db28da98df90266e9751a8ae9ee1.tar.gz emacs-4f616a2e7ed1db28da98df90266e9751a8ae9ee1.zip | |
merge from upstream
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/getopt.c | 11 | ||||
| -rw-r--r-- | lib/gnulib.mk | 81 | ||||
| -rw-r--r-- | lib/pthread_sigmask.c | 29 | ||||
| -rw-r--r-- | lib/signal.in.h | 428 | ||||
| -rw-r--r-- | lib/sigprocmask.c | 329 | ||||
| -rw-r--r-- | lib/stdint.in.h | 96 | ||||
| -rw-r--r-- | lib/strtoll.c | 33 | ||||
| -rw-r--r-- | lib/unistd.in.h | 141 |
8 files changed, 1032 insertions, 116 deletions
diff --git a/lib/getopt.c b/lib/getopt.c index 2af8352ee9c..7c9f7040612 100644 --- a/lib/getopt.c +++ b/lib/getopt.c | |||
| @@ -829,7 +829,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 829 | return '?'; | 829 | return '?'; |
| 830 | } | 830 | } |
| 831 | /* Convenience. Treat POSIX -W foo same as long option --foo */ | 831 | /* Convenience. Treat POSIX -W foo same as long option --foo */ |
| 832 | if (temp[0] == 'W' && temp[1] == ';' && longopts) | 832 | if (temp[0] == 'W' && temp[1] == ';') |
| 833 | { | 833 | { |
| 834 | char *nameend; | 834 | char *nameend; |
| 835 | const struct option *p; | 835 | const struct option *p; |
| @@ -839,6 +839,9 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 839 | int indfound = 0; | 839 | int indfound = 0; |
| 840 | int option_index; | 840 | int option_index; |
| 841 | 841 | ||
| 842 | if (longopts == NULL) | ||
| 843 | goto no_longs; | ||
| 844 | |||
| 842 | /* This is an option that requires an argument. */ | 845 | /* This is an option that requires an argument. */ |
| 843 | if (*d->__nextchar != '\0') | 846 | if (*d->__nextchar != '\0') |
| 844 | { | 847 | { |
| @@ -1046,8 +1049,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 1046 | } | 1049 | } |
| 1047 | return pfound->val; | 1050 | return pfound->val; |
| 1048 | } | 1051 | } |
| 1049 | d->__nextchar = NULL; | 1052 | |
| 1050 | return 'W'; /* Let the application handle it. */ | 1053 | no_longs: |
| 1054 | d->__nextchar = NULL; | ||
| 1055 | return 'W'; /* Let the application handle it. */ | ||
| 1051 | } | 1056 | } |
| 1052 | if (temp[1] == ':') | 1057 | if (temp[1] == ':') |
| 1053 | { | 1058 | { |
diff --git a/lib/gnulib.mk b/lib/gnulib.mk index 18abe4536fa..4341a5d184d 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | # the same distribution terms as the rest of that program. | 9 | # the same distribution terms as the rest of that program. |
| 10 | # | 10 | # |
| 11 | # Generated by gnulib-tool. | 11 | # Generated by gnulib-tool. |
| 12 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dup2 filemode getloadavg getopt-gnu ignore-value intprops lstat mktime readlink socklen stdarg stdio strftime strtoumax symlink sys_stat | 12 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dup2 filemode getloadavg getopt-gnu ignore-value intprops lstat mktime pthread_sigmask readlink socklen stdarg stdio strftime strtoimax strtoumax symlink sys_stat |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | MOSTLYCLEANFILES += core *.stackdump | 15 | MOSTLYCLEANFILES += core *.stackdump |
| @@ -294,6 +294,15 @@ EXTRA_libgnu_a_SOURCES += mktime.c | |||
| 294 | 294 | ||
| 295 | ## end gnulib module mktime | 295 | ## end gnulib module mktime |
| 296 | 296 | ||
| 297 | ## begin gnulib module pthread_sigmask | ||
| 298 | |||
| 299 | |||
| 300 | EXTRA_DIST += pthread_sigmask.c | ||
| 301 | |||
| 302 | EXTRA_libgnu_a_SOURCES += pthread_sigmask.c | ||
| 303 | |||
| 304 | ## end gnulib module pthread_sigmask | ||
| 305 | |||
| 297 | ## begin gnulib module readlink | 306 | ## begin gnulib module readlink |
| 298 | 307 | ||
| 299 | 308 | ||
| @@ -303,6 +312,56 @@ EXTRA_libgnu_a_SOURCES += readlink.c | |||
| 303 | 312 | ||
| 304 | ## end gnulib module readlink | 313 | ## end gnulib module readlink |
| 305 | 314 | ||
| 315 | ## begin gnulib module signal | ||
| 316 | |||
| 317 | BUILT_SOURCES += signal.h | ||
| 318 | |||
| 319 | # We need the following in order to create <signal.h> when the system | ||
| 320 | # doesn't have a complete one. | ||
| 321 | signal.h: signal.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | ||
| 322 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 323 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ | ||
| 324 | sed -e 's|@''GUARD_PREFIX''@|GL|g' \ | ||
| 325 | -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ | ||
| 326 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ | ||
| 327 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ | ||
| 328 | -e 's|@''NEXT_SIGNAL_H''@|$(NEXT_SIGNAL_H)|g' \ | ||
| 329 | -e 's|@''GNULIB_PTHREAD_SIGMASK''@|$(GNULIB_PTHREAD_SIGMASK)|g' \ | ||
| 330 | -e 's/@''GNULIB_SIGNAL_H_SIGPIPE''@/$(GNULIB_SIGNAL_H_SIGPIPE)/g' \ | ||
| 331 | -e 's/@''GNULIB_SIGPROCMASK''@/$(GNULIB_SIGPROCMASK)/g' \ | ||
| 332 | -e 's/@''GNULIB_SIGACTION''@/$(GNULIB_SIGACTION)/g' \ | ||
| 333 | -e 's|@''HAVE_POSIX_SIGNALBLOCKING''@|$(HAVE_POSIX_SIGNALBLOCKING)|g' \ | ||
| 334 | -e 's|@''HAVE_PTHREAD_SIGMASK''@|$(HAVE_PTHREAD_SIGMASK)|g' \ | ||
| 335 | -e 's|@''HAVE_SIGSET_T''@|$(HAVE_SIGSET_T)|g' \ | ||
| 336 | -e 's|@''HAVE_SIGINFO_T''@|$(HAVE_SIGINFO_T)|g' \ | ||
| 337 | -e 's|@''HAVE_SIGACTION''@|$(HAVE_SIGACTION)|g' \ | ||
| 338 | -e 's|@''HAVE_STRUCT_SIGACTION_SA_SIGACTION''@|$(HAVE_STRUCT_SIGACTION_SA_SIGACTION)|g' \ | ||
| 339 | -e 's|@''HAVE_TYPE_VOLATILE_SIG_ATOMIC_T''@|$(HAVE_TYPE_VOLATILE_SIG_ATOMIC_T)|g' \ | ||
| 340 | -e 's|@''HAVE_SIGHANDLER_T''@|$(HAVE_SIGHANDLER_T)|g' \ | ||
| 341 | -e 's|@''REPLACE_PTHREAD_SIGMASK''@|$(REPLACE_PTHREAD_SIGMASK)|g' \ | ||
| 342 | -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ | ||
| 343 | -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ | ||
| 344 | -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ | ||
| 345 | < $(srcdir)/signal.in.h; \ | ||
| 346 | } > $@-t && \ | ||
| 347 | mv $@-t $@ | ||
| 348 | MOSTLYCLEANFILES += signal.h signal.h-t | ||
| 349 | |||
| 350 | EXTRA_DIST += signal.in.h | ||
| 351 | |||
| 352 | ## end gnulib module signal | ||
| 353 | |||
| 354 | ## begin gnulib module sigprocmask | ||
| 355 | |||
| 356 | if gl_GNULIB_ENABLED_sigprocmask | ||
| 357 | |||
| 358 | endif | ||
| 359 | EXTRA_DIST += sigprocmask.c | ||
| 360 | |||
| 361 | EXTRA_libgnu_a_SOURCES += sigprocmask.c | ||
| 362 | |||
| 363 | ## end gnulib module sigprocmask | ||
| 364 | |||
| 306 | ## begin gnulib module stat | 365 | ## begin gnulib module stat |
| 307 | 366 | ||
| 308 | if gl_GNULIB_ENABLED_stat | 367 | if gl_GNULIB_ENABLED_stat |
| @@ -667,6 +726,26 @@ EXTRA_DIST += strftime.h | |||
| 667 | 726 | ||
| 668 | ## end gnulib module strftime | 727 | ## end gnulib module strftime |
| 669 | 728 | ||
| 729 | ## begin gnulib module strtoimax | ||
| 730 | |||
| 731 | |||
| 732 | EXTRA_DIST += strtoimax.c | ||
| 733 | |||
| 734 | EXTRA_libgnu_a_SOURCES += strtoimax.c | ||
| 735 | |||
| 736 | ## end gnulib module strtoimax | ||
| 737 | |||
| 738 | ## begin gnulib module strtoll | ||
| 739 | |||
| 740 | if gl_GNULIB_ENABLED_strtoll | ||
| 741 | |||
| 742 | endif | ||
| 743 | EXTRA_DIST += strtol.c strtoll.c | ||
| 744 | |||
| 745 | EXTRA_libgnu_a_SOURCES += strtol.c strtoll.c | ||
| 746 | |||
| 747 | ## end gnulib module strtoll | ||
| 748 | |||
| 670 | ## begin gnulib module strtoull | 749 | ## begin gnulib module strtoull |
| 671 | 750 | ||
| 672 | if gl_GNULIB_ENABLED_strtoull | 751 | if gl_GNULIB_ENABLED_strtoull |
diff --git a/lib/pthread_sigmask.c b/lib/pthread_sigmask.c new file mode 100644 index 00000000000..1f460f13c48 --- /dev/null +++ b/lib/pthread_sigmask.c | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | /* POSIX compatible signal blocking for threads. | ||
| 2 | Copyright (C) 2011 Free Software Foundation, Inc. | ||
| 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 3 of the License, or | ||
| 7 | (at your option) 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, see <http://www.gnu.org/licenses/>. */ | ||
| 16 | |||
| 17 | #include <config.h> | ||
| 18 | |||
| 19 | /* Specification. */ | ||
| 20 | #include <signal.h> | ||
| 21 | |||
| 22 | #include <errno.h> | ||
| 23 | |||
| 24 | int | ||
| 25 | pthread_sigmask (int how, const sigset_t *new_mask, sigset_t *old_mask) | ||
| 26 | { | ||
| 27 | int ret = sigprocmask (how, new_mask, old_mask); | ||
| 28 | return (ret < 0 ? errno : 0); | ||
| 29 | } | ||
diff --git a/lib/signal.in.h b/lib/signal.in.h new file mode 100644 index 00000000000..93787f753fa --- /dev/null +++ b/lib/signal.in.h | |||
| @@ -0,0 +1,428 @@ | |||
| 1 | /* A GNU-like <signal.h>. | ||
| 2 | |||
| 3 | Copyright (C) 2006-2011 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This program is free software: you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation; either version 3 of the License, or | ||
| 8 | (at your option) any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 17 | |||
| 18 | #if __GNUC__ >= 3 | ||
| 19 | @PRAGMA_SYSTEM_HEADER@ | ||
| 20 | #endif | ||
| 21 | @PRAGMA_COLUMNS@ | ||
| 22 | |||
| 23 | #if defined __need_sig_atomic_t || defined __need_sigset_t || defined _GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined __SIZEOF_PTHREAD_MUTEX_T) | ||
| 24 | /* Special invocation convention: | ||
| 25 | - Inside glibc header files. | ||
| 26 | - On glibc systems we have a sequence of nested includes | ||
| 27 | <signal.h> -> <ucontext.h> -> <signal.h>. | ||
| 28 | In this situation, the functions are not yet declared, therefore we cannot | ||
| 29 | provide the C++ aliases. | ||
| 30 | - On glibc systems with GCC 4.3 we have a sequence of nested includes | ||
| 31 | <csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>. | ||
| 32 | In this situation, some of the functions are not yet declared, therefore | ||
| 33 | we cannot provide the C++ aliases. */ | ||
| 34 | |||
| 35 | # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@ | ||
| 36 | |||
| 37 | #else | ||
| 38 | /* Normal invocation convention. */ | ||
| 39 | |||
| 40 | #ifndef _@GUARD_PREFIX@_SIGNAL_H | ||
| 41 | |||
| 42 | #define _GL_ALREADY_INCLUDING_SIGNAL_H | ||
| 43 | |||
| 44 | /* Define pid_t, uid_t. | ||
| 45 | Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>. | ||
| 46 | On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes | ||
| 47 | us; so include <sys/types.h> now, before the second inclusion guard. */ | ||
| 48 | #include <sys/types.h> | ||
| 49 | |||
| 50 | /* The include_next requires a split double-inclusion guard. */ | ||
| 51 | #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@ | ||
| 52 | |||
| 53 | #undef _GL_ALREADY_INCLUDING_SIGNAL_H | ||
| 54 | |||
| 55 | #ifndef _@GUARD_PREFIX@_SIGNAL_H | ||
| 56 | #define _@GUARD_PREFIX@_SIGNAL_H | ||
| 57 | |||
| 58 | /* MacOS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6 declare | ||
| 59 | pthread_sigmask in <pthread.h>, not in <signal.h>. | ||
| 60 | But avoid namespace pollution on glibc systems.*/ | ||
| 61 | #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \ | ||
| 62 | && ((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ || defined __sun) \ | ||
| 63 | && ! defined __GLIBC__ | ||
| 64 | # include <pthread.h> | ||
| 65 | #endif | ||
| 66 | |||
| 67 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ | ||
| 68 | |||
| 69 | /* The definition of _GL_ARG_NONNULL is copied here. */ | ||
| 70 | |||
| 71 | /* The definition of _GL_WARN_ON_USE is copied here. */ | ||
| 72 | |||
| 73 | /* On AIX, sig_atomic_t already includes volatile. C99 requires that | ||
| 74 | 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not. | ||
| 75 | Hence, redefine this to a non-volatile type as needed. */ | ||
| 76 | #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@ | ||
| 77 | # if !GNULIB_defined_sig_atomic_t | ||
| 78 | typedef int rpl_sig_atomic_t; | ||
| 79 | # undef sig_atomic_t | ||
| 80 | # define sig_atomic_t rpl_sig_atomic_t | ||
| 81 | # define GNULIB_defined_sig_atomic_t 1 | ||
| 82 | # endif | ||
| 83 | #endif | ||
| 84 | |||
| 85 | /* A set or mask of signals. */ | ||
| 86 | #if !@HAVE_SIGSET_T@ | ||
| 87 | # if !GNULIB_defined_sigset_t | ||
| 88 | typedef unsigned int sigset_t; | ||
| 89 | # define GNULIB_defined_sigset_t 1 | ||
| 90 | # endif | ||
| 91 | #endif | ||
| 92 | |||
| 93 | /* Define sighandler_t, the type of signal handlers. A GNU extension. */ | ||
| 94 | #if !@HAVE_SIGHANDLER_T@ | ||
| 95 | # ifdef __cplusplus | ||
| 96 | extern "C" { | ||
| 97 | # endif | ||
| 98 | # if !GNULIB_defined_sighandler_t | ||
| 99 | typedef void (*sighandler_t) (int); | ||
| 100 | # define GNULIB_defined_sighandler_t 1 | ||
| 101 | # endif | ||
| 102 | # ifdef __cplusplus | ||
| 103 | } | ||
| 104 | # endif | ||
| 105 | #endif | ||
| 106 | |||
| 107 | |||
| 108 | #if @GNULIB_SIGNAL_H_SIGPIPE@ | ||
| 109 | # ifndef SIGPIPE | ||
| 110 | /* Define SIGPIPE to a value that does not overlap with other signals. */ | ||
| 111 | # define SIGPIPE 13 | ||
| 112 | # define GNULIB_defined_SIGPIPE 1 | ||
| 113 | /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask', | ||
| 114 | 'write', 'stdio'. */ | ||
| 115 | # endif | ||
| 116 | #endif | ||
| 117 | |||
| 118 | |||
| 119 | /* Maximum signal number + 1. */ | ||
| 120 | #ifndef NSIG | ||
| 121 | # if defined __TANDEM | ||
| 122 | # define NSIG 32 | ||
| 123 | # endif | ||
| 124 | #endif | ||
| 125 | |||
| 126 | |||
| 127 | #if @GNULIB_PTHREAD_SIGMASK@ | ||
| 128 | # if @REPLACE_PTHREAD_SIGMASK@ | ||
| 129 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 130 | # undef pthread_sigmask | ||
| 131 | # define pthread_sigmask rpl_pthread_sigmask | ||
| 132 | # endif | ||
| 133 | _GL_FUNCDECL_RPL (pthread_sigmask, int, | ||
| 134 | (int how, const sigset_t *new_mask, sigset_t *old_mask)); | ||
| 135 | _GL_CXXALIAS_RPL (pthread_sigmask, int, | ||
| 136 | (int how, const sigset_t *new_mask, sigset_t *old_mask)); | ||
| 137 | # else | ||
| 138 | # if !@HAVE_PTHREAD_SIGMASK@ | ||
| 139 | _GL_FUNCDECL_SYS (pthread_sigmask, int, | ||
| 140 | (int how, const sigset_t *new_mask, sigset_t *old_mask)); | ||
| 141 | # endif | ||
| 142 | _GL_CXXALIAS_SYS (pthread_sigmask, int, | ||
| 143 | (int how, const sigset_t *new_mask, sigset_t *old_mask)); | ||
| 144 | # endif | ||
| 145 | _GL_CXXALIASWARN (pthread_sigmask); | ||
| 146 | #elif defined GNULIB_POSIXCHECK | ||
| 147 | # undef pthread_sigmask | ||
| 148 | # if HAVE_RAW_DECL_PTHREAD_SIGMASK | ||
| 149 | _GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - " | ||
| 150 | "use gnulib module pthread_sigmask for portability"); | ||
| 151 | # endif | ||
| 152 | #endif | ||
| 153 | |||
| 154 | |||
| 155 | #if @GNULIB_SIGPROCMASK@ | ||
| 156 | # if !@HAVE_POSIX_SIGNALBLOCKING@ | ||
| 157 | |||
| 158 | /* Maximum signal number + 1. */ | ||
| 159 | # ifndef NSIG | ||
| 160 | # define NSIG 32 | ||
| 161 | # endif | ||
| 162 | |||
| 163 | /* This code supports only 32 signals. */ | ||
| 164 | # if !GNULIB_defined_verify_NSIG_constraint | ||
| 165 | typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1]; | ||
| 166 | # define GNULIB_defined_verify_NSIG_constraint 1 | ||
| 167 | # endif | ||
| 168 | |||
| 169 | # endif | ||
| 170 | |||
| 171 | /* Test whether a given signal is contained in a signal set. */ | ||
| 172 | # if @HAVE_POSIX_SIGNALBLOCKING@ | ||
| 173 | /* This function is defined as a macro on MacOS X. */ | ||
| 174 | # if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 175 | # undef sigismember | ||
| 176 | # endif | ||
| 177 | # else | ||
| 178 | _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig) | ||
| 179 | _GL_ARG_NONNULL ((1))); | ||
| 180 | # endif | ||
| 181 | _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig)); | ||
| 182 | _GL_CXXALIASWARN (sigismember); | ||
| 183 | |||
| 184 | /* Initialize a signal set to the empty set. */ | ||
| 185 | # if @HAVE_POSIX_SIGNALBLOCKING@ | ||
| 186 | /* This function is defined as a macro on MacOS X. */ | ||
| 187 | # if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 188 | # undef sigemptyset | ||
| 189 | # endif | ||
| 190 | # else | ||
| 191 | _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1))); | ||
| 192 | # endif | ||
| 193 | _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set)); | ||
| 194 | _GL_CXXALIASWARN (sigemptyset); | ||
| 195 | |||
| 196 | /* Add a signal to a signal set. */ | ||
| 197 | # if @HAVE_POSIX_SIGNALBLOCKING@ | ||
| 198 | /* This function is defined as a macro on MacOS X. */ | ||
| 199 | # if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 200 | # undef sigaddset | ||
| 201 | # endif | ||
| 202 | # else | ||
| 203 | _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig) | ||
| 204 | _GL_ARG_NONNULL ((1))); | ||
| 205 | # endif | ||
| 206 | _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig)); | ||
| 207 | _GL_CXXALIASWARN (sigaddset); | ||
| 208 | |||
| 209 | /* Remove a signal from a signal set. */ | ||
| 210 | # if @HAVE_POSIX_SIGNALBLOCKING@ | ||
| 211 | /* This function is defined as a macro on MacOS X. */ | ||
| 212 | # if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 213 | # undef sigdelset | ||
| 214 | # endif | ||
| 215 | # else | ||
| 216 | _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig) | ||
| 217 | _GL_ARG_NONNULL ((1))); | ||
| 218 | # endif | ||
| 219 | _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig)); | ||
| 220 | _GL_CXXALIASWARN (sigdelset); | ||
| 221 | |||
| 222 | /* Fill a signal set with all possible signals. */ | ||
| 223 | # if @HAVE_POSIX_SIGNALBLOCKING@ | ||
| 224 | /* This function is defined as a macro on MacOS X. */ | ||
| 225 | # if defined __cplusplus && defined GNULIB_NAMESPACE | ||
| 226 | # undef sigfillset | ||
| 227 | # endif | ||
| 228 | # else | ||
| 229 | _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1))); | ||
| 230 | # endif | ||
| 231 | _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set)); | ||
| 232 | _GL_CXXALIASWARN (sigfillset); | ||
| 233 | |||
| 234 | /* Return the set of those blocked signals that are pending. */ | ||
| 235 | # if !@HAVE_POSIX_SIGNALBLOCKING@ | ||
| 236 | _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1))); | ||
| 237 | # endif | ||
| 238 | _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set)); | ||
| 239 | _GL_CXXALIASWARN (sigpending); | ||
| 240 | |||
| 241 | /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET. | ||
| 242 | Then, if SET is not NULL, affect the current set of blocked signals by | ||
| 243 | combining it with *SET as indicated in OPERATION. | ||
| 244 | In this implementation, you are not allowed to change a signal handler | ||
| 245 | while the signal is blocked. */ | ||
| 246 | # if !@HAVE_POSIX_SIGNALBLOCKING@ | ||
| 247 | # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */ | ||
| 248 | # define SIG_SETMASK 1 /* blocked_set = *set; */ | ||
| 249 | # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */ | ||
| 250 | _GL_FUNCDECL_SYS (sigprocmask, int, | ||
| 251 | (int operation, const sigset_t *set, sigset_t *old_set)); | ||
| 252 | # endif | ||
| 253 | _GL_CXXALIAS_SYS (sigprocmask, int, | ||
| 254 | (int operation, const sigset_t *set, sigset_t *old_set)); | ||
| 255 | _GL_CXXALIASWARN (sigprocmask); | ||
| 256 | |||
| 257 | /* Install the handler FUNC for signal SIG, and return the previous | ||
| 258 | handler. */ | ||
| 259 | # ifdef __cplusplus | ||
| 260 | extern "C" { | ||
| 261 | # endif | ||
| 262 | # if !GNULIB_defined_function_taking_int_returning_void_t | ||
| 263 | typedef void (*_gl_function_taking_int_returning_void_t) (int); | ||
| 264 | # define GNULIB_defined_function_taking_int_returning_void_t 1 | ||
| 265 | # endif | ||
| 266 | # ifdef __cplusplus | ||
| 267 | } | ||
| 268 | # endif | ||
| 269 | # if !@HAVE_POSIX_SIGNALBLOCKING@ | ||
| 270 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 271 | # define signal rpl_signal | ||
| 272 | # endif | ||
| 273 | _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t, | ||
| 274 | (int sig, _gl_function_taking_int_returning_void_t func)); | ||
| 275 | _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t, | ||
| 276 | (int sig, _gl_function_taking_int_returning_void_t func)); | ||
| 277 | # else | ||
| 278 | _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t, | ||
| 279 | (int sig, _gl_function_taking_int_returning_void_t func)); | ||
| 280 | # endif | ||
| 281 | _GL_CXXALIASWARN (signal); | ||
| 282 | |||
| 283 | /* Raise signal SIG. */ | ||
| 284 | # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE | ||
| 285 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 286 | # undef raise | ||
| 287 | # define raise rpl_raise | ||
| 288 | # endif | ||
| 289 | _GL_FUNCDECL_RPL (raise, int, (int sig)); | ||
| 290 | _GL_CXXALIAS_RPL (raise, int, (int sig)); | ||
| 291 | # else | ||
| 292 | _GL_CXXALIAS_SYS (raise, int, (int sig)); | ||
| 293 | # endif | ||
| 294 | _GL_CXXALIASWARN (raise); | ||
| 295 | |||
| 296 | #elif defined GNULIB_POSIXCHECK | ||
| 297 | # undef sigaddset | ||
| 298 | # if HAVE_RAW_DECL_SIGADDSET | ||
| 299 | _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - " | ||
| 300 | "use the gnulib module sigprocmask for portability"); | ||
| 301 | # endif | ||
| 302 | # undef sigdelset | ||
| 303 | # if HAVE_RAW_DECL_SIGDELSET | ||
| 304 | _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - " | ||
| 305 | "use the gnulib module sigprocmask for portability"); | ||
| 306 | # endif | ||
| 307 | # undef sigemptyset | ||
| 308 | # if HAVE_RAW_DECL_SIGEMPTYSET | ||
| 309 | _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - " | ||
| 310 | "use the gnulib module sigprocmask for portability"); | ||
| 311 | # endif | ||
| 312 | # undef sigfillset | ||
| 313 | # if HAVE_RAW_DECL_SIGFILLSET | ||
| 314 | _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - " | ||
| 315 | "use the gnulib module sigprocmask for portability"); | ||
| 316 | # endif | ||
| 317 | # undef sigismember | ||
| 318 | # if HAVE_RAW_DECL_SIGISMEMBER | ||
| 319 | _GL_WARN_ON_USE (sigismember, "sigismember is unportable - " | ||
| 320 | "use the gnulib module sigprocmask for portability"); | ||
| 321 | # endif | ||
| 322 | # undef sigpending | ||
| 323 | # if HAVE_RAW_DECL_SIGPENDING | ||
| 324 | _GL_WARN_ON_USE (sigpending, "sigpending is unportable - " | ||
| 325 | "use the gnulib module sigprocmask for portability"); | ||
| 326 | # endif | ||
| 327 | # undef sigprocmask | ||
| 328 | # if HAVE_RAW_DECL_SIGPROCMASK | ||
| 329 | _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - " | ||
| 330 | "use the gnulib module sigprocmask for portability"); | ||
| 331 | # endif | ||
| 332 | #endif /* @GNULIB_SIGPROCMASK@ */ | ||
| 333 | |||
| 334 | |||
| 335 | #if @GNULIB_SIGACTION@ | ||
| 336 | # if !@HAVE_SIGACTION@ | ||
| 337 | |||
| 338 | # if !@HAVE_SIGINFO_T@ | ||
| 339 | |||
| 340 | # if !GNULIB_defined_siginfo_types | ||
| 341 | |||
| 342 | /* Present to allow compilation, but unsupported by gnulib. */ | ||
| 343 | union sigval | ||
| 344 | { | ||
| 345 | int sival_int; | ||
| 346 | void *sival_ptr; | ||
| 347 | }; | ||
| 348 | |||
| 349 | /* Present to allow compilation, but unsupported by gnulib. */ | ||
| 350 | struct siginfo_t | ||
| 351 | { | ||
| 352 | int si_signo; | ||
| 353 | int si_code; | ||
| 354 | int si_errno; | ||
| 355 | pid_t si_pid; | ||
| 356 | uid_t si_uid; | ||
| 357 | void *si_addr; | ||
| 358 | int si_status; | ||
| 359 | long si_band; | ||
| 360 | union sigval si_value; | ||
| 361 | }; | ||
| 362 | typedef struct siginfo_t siginfo_t; | ||
| 363 | |||
| 364 | # define GNULIB_defined_siginfo_types 1 | ||
| 365 | # endif | ||
| 366 | |||
| 367 | # endif /* !@HAVE_SIGINFO_T@ */ | ||
| 368 | |||
| 369 | /* We assume that platforms which lack the sigaction() function also lack | ||
| 370 | the 'struct sigaction' type, and vice versa. */ | ||
| 371 | |||
| 372 | # if !GNULIB_defined_struct_sigaction | ||
| 373 | |||
| 374 | struct sigaction | ||
| 375 | { | ||
| 376 | union | ||
| 377 | { | ||
| 378 | void (*_sa_handler) (int); | ||
| 379 | /* Present to allow compilation, but unsupported by gnulib. POSIX | ||
| 380 | says that implementations may, but not must, make sa_sigaction | ||
| 381 | overlap with sa_handler, but we know of no implementation where | ||
| 382 | they do not overlap. */ | ||
| 383 | void (*_sa_sigaction) (int, siginfo_t *, void *); | ||
| 384 | } _sa_func; | ||
| 385 | sigset_t sa_mask; | ||
| 386 | /* Not all POSIX flags are supported. */ | ||
| 387 | int sa_flags; | ||
| 388 | }; | ||
| 389 | # define sa_handler _sa_func._sa_handler | ||
| 390 | # define sa_sigaction _sa_func._sa_sigaction | ||
| 391 | /* Unsupported flags are not present. */ | ||
| 392 | # define SA_RESETHAND 1 | ||
| 393 | # define SA_NODEFER 2 | ||
| 394 | # define SA_RESTART 4 | ||
| 395 | |||
| 396 | # define GNULIB_defined_struct_sigaction 1 | ||
| 397 | # endif | ||
| 398 | |||
| 399 | _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict, | ||
| 400 | struct sigaction *restrict)); | ||
| 401 | |||
| 402 | # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ | ||
| 403 | |||
| 404 | # define sa_sigaction sa_handler | ||
| 405 | |||
| 406 | # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */ | ||
| 407 | |||
| 408 | _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict, | ||
| 409 | struct sigaction *restrict)); | ||
| 410 | _GL_CXXALIASWARN (sigaction); | ||
| 411 | |||
| 412 | #elif defined GNULIB_POSIXCHECK | ||
| 413 | # undef sigaction | ||
| 414 | # if HAVE_RAW_DECL_SIGACTION | ||
| 415 | _GL_WARN_ON_USE (sigaction, "sigaction is unportable - " | ||
| 416 | "use the gnulib module sigaction for portability"); | ||
| 417 | # endif | ||
| 418 | #endif | ||
| 419 | |||
| 420 | /* Some systems don't have SA_NODEFER. */ | ||
| 421 | #ifndef SA_NODEFER | ||
| 422 | # define SA_NODEFER 0 | ||
| 423 | #endif | ||
| 424 | |||
| 425 | |||
| 426 | #endif /* _@GUARD_PREFIX@_SIGNAL_H */ | ||
| 427 | #endif /* _@GUARD_PREFIX@_SIGNAL_H */ | ||
| 428 | #endif | ||
diff --git a/lib/sigprocmask.c b/lib/sigprocmask.c new file mode 100644 index 00000000000..6780a37b14f --- /dev/null +++ b/lib/sigprocmask.c | |||
| @@ -0,0 +1,329 @@ | |||
| 1 | /* POSIX compatible signal blocking. | ||
| 2 | Copyright (C) 2006-2011 Free Software Foundation, Inc. | ||
| 3 | Written by Bruno Haible <bruno@clisp.org>, 2006. | ||
| 4 | |||
| 5 | This program is free software: you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation; either version 3 of the License, or | ||
| 8 | (at your option) any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 17 | |||
| 18 | #include <config.h> | ||
| 19 | |||
| 20 | /* Specification. */ | ||
| 21 | #include <signal.h> | ||
| 22 | |||
| 23 | #include <errno.h> | ||
| 24 | #include <stdint.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | |||
| 27 | /* We assume that a platform without POSIX signal blocking functions | ||
| 28 | also does not have the POSIX sigaction() function, only the | ||
| 29 | signal() function. We also assume signal() has SysV semantics, | ||
| 30 | where any handler is uninstalled prior to being invoked. This is | ||
| 31 | true for Woe32 platforms. */ | ||
| 32 | |||
| 33 | /* We use raw signal(), but also provide a wrapper rpl_signal() so | ||
| 34 | that applications can query or change a blocked signal. */ | ||
| 35 | #undef signal | ||
| 36 | |||
| 37 | /* Provide invalid signal numbers as fallbacks if the uncatchable | ||
| 38 | signals are not defined. */ | ||
| 39 | #ifndef SIGKILL | ||
| 40 | # define SIGKILL (-1) | ||
| 41 | #endif | ||
| 42 | #ifndef SIGSTOP | ||
| 43 | # define SIGSTOP (-1) | ||
| 44 | #endif | ||
| 45 | |||
| 46 | /* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias | ||
| 47 | for the signal SIGABRT. Only one signal handler is stored for both | ||
| 48 | SIGABRT and SIGABRT_COMPAT. SIGABRT_COMPAT is not a signal of its own. */ | ||
| 49 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 50 | # undef SIGABRT_COMPAT | ||
| 51 | # define SIGABRT_COMPAT 6 | ||
| 52 | #endif | ||
| 53 | #ifdef SIGABRT_COMPAT | ||
| 54 | # define SIGABRT_COMPAT_MASK (1U << SIGABRT_COMPAT) | ||
| 55 | #else | ||
| 56 | # define SIGABRT_COMPAT_MASK 0 | ||
| 57 | #endif | ||
| 58 | |||
| 59 | typedef void (*handler_t) (int); | ||
| 60 | |||
| 61 | /* Handling of gnulib defined signals. */ | ||
| 62 | |||
| 63 | #if GNULIB_defined_SIGPIPE | ||
| 64 | static handler_t SIGPIPE_handler = SIG_DFL; | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #if GNULIB_defined_SIGPIPE | ||
| 68 | static handler_t | ||
| 69 | ext_signal (int sig, handler_t handler) | ||
| 70 | { | ||
| 71 | switch (sig) | ||
| 72 | { | ||
| 73 | case SIGPIPE: | ||
| 74 | { | ||
| 75 | handler_t old_handler = SIGPIPE_handler; | ||
| 76 | SIGPIPE_handler = handler; | ||
| 77 | return old_handler; | ||
| 78 | } | ||
| 79 | default: /* System defined signal */ | ||
| 80 | return signal (sig, handler); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | # define signal ext_signal | ||
| 84 | #endif | ||
| 85 | |||
| 86 | int | ||
| 87 | sigismember (const sigset_t *set, int sig) | ||
| 88 | { | ||
| 89 | if (sig >= 0 && sig < NSIG) | ||
| 90 | { | ||
| 91 | #ifdef SIGABRT_COMPAT | ||
| 92 | if (sig == SIGABRT_COMPAT) | ||
| 93 | sig = SIGABRT; | ||
| 94 | #endif | ||
| 95 | |||
| 96 | return (*set >> sig) & 1; | ||
| 97 | } | ||
| 98 | else | ||
| 99 | return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | int | ||
| 103 | sigemptyset (sigset_t *set) | ||
| 104 | { | ||
| 105 | *set = 0; | ||
| 106 | return 0; | ||
| 107 | } | ||
| 108 | |||
| 109 | int | ||
| 110 | sigaddset (sigset_t *set, int sig) | ||
| 111 | { | ||
| 112 | if (sig >= 0 && sig < NSIG) | ||
| 113 | { | ||
| 114 | #ifdef SIGABRT_COMPAT | ||
| 115 | if (sig == SIGABRT_COMPAT) | ||
| 116 | sig = SIGABRT; | ||
| 117 | #endif | ||
| 118 | |||
| 119 | *set |= 1U << sig; | ||
| 120 | return 0; | ||
| 121 | } | ||
| 122 | else | ||
| 123 | { | ||
| 124 | errno = EINVAL; | ||
| 125 | return -1; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | int | ||
| 130 | sigdelset (sigset_t *set, int sig) | ||
| 131 | { | ||
| 132 | if (sig >= 0 && sig < NSIG) | ||
| 133 | { | ||
| 134 | #ifdef SIGABRT_COMPAT | ||
| 135 | if (sig == SIGABRT_COMPAT) | ||
| 136 | sig = SIGABRT; | ||
| 137 | #endif | ||
| 138 | |||
| 139 | *set &= ~(1U << sig); | ||
| 140 | return 0; | ||
| 141 | } | ||
| 142 | else | ||
| 143 | { | ||
| 144 | errno = EINVAL; | ||
| 145 | return -1; | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | |||
| 150 | int | ||
| 151 | sigfillset (sigset_t *set) | ||
| 152 | { | ||
| 153 | *set = ((2U << (NSIG - 1)) - 1) & ~ SIGABRT_COMPAT_MASK; | ||
| 154 | return 0; | ||
| 155 | } | ||
| 156 | |||
| 157 | /* Set of currently blocked signals. */ | ||
| 158 | static volatile sigset_t blocked_set /* = 0 */; | ||
| 159 | |||
| 160 | /* Set of currently blocked and pending signals. */ | ||
| 161 | static volatile sig_atomic_t pending_array[NSIG] /* = { 0 } */; | ||
| 162 | |||
| 163 | /* Signal handler that is installed for blocked signals. */ | ||
| 164 | static void | ||
| 165 | blocked_handler (int sig) | ||
| 166 | { | ||
| 167 | /* Reinstall the handler, in case the signal occurs multiple times | ||
| 168 | while blocked. There is an inherent race where an asynchronous | ||
| 169 | signal in between when the kernel uninstalled the handler and | ||
| 170 | when we reinstall it will trigger the default handler; oh | ||
| 171 | well. */ | ||
| 172 | signal (sig, blocked_handler); | ||
| 173 | if (sig >= 0 && sig < NSIG) | ||
| 174 | pending_array[sig] = 1; | ||
| 175 | } | ||
| 176 | |||
| 177 | int | ||
| 178 | sigpending (sigset_t *set) | ||
| 179 | { | ||
| 180 | sigset_t pending = 0; | ||
| 181 | int sig; | ||
| 182 | |||
| 183 | for (sig = 0; sig < NSIG; sig++) | ||
| 184 | if (pending_array[sig]) | ||
| 185 | pending |= 1U << sig; | ||
| 186 | *set = pending; | ||
| 187 | return 0; | ||
| 188 | } | ||
| 189 | |||
| 190 | /* The previous signal handlers. | ||
| 191 | Only the array elements corresponding to blocked signals are relevant. */ | ||
| 192 | static volatile handler_t old_handlers[NSIG]; | ||
| 193 | |||
| 194 | int | ||
| 195 | sigprocmask (int operation, const sigset_t *set, sigset_t *old_set) | ||
| 196 | { | ||
| 197 | if (old_set != NULL) | ||
| 198 | *old_set = blocked_set; | ||
| 199 | |||
| 200 | if (set != NULL) | ||
| 201 | { | ||
| 202 | sigset_t new_blocked_set; | ||
| 203 | sigset_t to_unblock; | ||
| 204 | sigset_t to_block; | ||
| 205 | |||
| 206 | switch (operation) | ||
| 207 | { | ||
| 208 | case SIG_BLOCK: | ||
| 209 | new_blocked_set = blocked_set | *set; | ||
| 210 | break; | ||
| 211 | case SIG_SETMASK: | ||
| 212 | new_blocked_set = *set; | ||
| 213 | break; | ||
| 214 | case SIG_UNBLOCK: | ||
| 215 | new_blocked_set = blocked_set & ~*set; | ||
| 216 | break; | ||
| 217 | default: | ||
| 218 | errno = EINVAL; | ||
| 219 | return -1; | ||
| 220 | } | ||
| 221 | to_unblock = blocked_set & ~new_blocked_set; | ||
| 222 | to_block = new_blocked_set & ~blocked_set; | ||
| 223 | |||
| 224 | if (to_block != 0) | ||
| 225 | { | ||
| 226 | int sig; | ||
| 227 | |||
| 228 | for (sig = 0; sig < NSIG; sig++) | ||
| 229 | if ((to_block >> sig) & 1) | ||
| 230 | { | ||
| 231 | pending_array[sig] = 0; | ||
| 232 | if ((old_handlers[sig] = signal (sig, blocked_handler)) != SIG_ERR) | ||
| 233 | blocked_set |= 1U << sig; | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | if (to_unblock != 0) | ||
| 238 | { | ||
| 239 | sig_atomic_t received[NSIG]; | ||
| 240 | int sig; | ||
| 241 | |||
| 242 | for (sig = 0; sig < NSIG; sig++) | ||
| 243 | if ((to_unblock >> sig) & 1) | ||
| 244 | { | ||
| 245 | if (signal (sig, old_handlers[sig]) != blocked_handler) | ||
| 246 | /* The application changed a signal handler while the signal | ||
| 247 | was blocked, bypassing our rpl_signal replacement. | ||
| 248 | We don't support this. */ | ||
| 249 | abort (); | ||
| 250 | received[sig] = pending_array[sig]; | ||
| 251 | blocked_set &= ~(1U << sig); | ||
| 252 | pending_array[sig] = 0; | ||
| 253 | } | ||
| 254 | else | ||
| 255 | received[sig] = 0; | ||
| 256 | |||
| 257 | for (sig = 0; sig < NSIG; sig++) | ||
| 258 | if (received[sig]) | ||
| 259 | raise (sig); | ||
| 260 | } | ||
| 261 | } | ||
| 262 | return 0; | ||
| 263 | } | ||
| 264 | |||
| 265 | /* Install the handler FUNC for signal SIG, and return the previous | ||
| 266 | handler. */ | ||
| 267 | handler_t | ||
| 268 | rpl_signal (int sig, handler_t handler) | ||
| 269 | { | ||
| 270 | /* We must provide a wrapper, so that a user can query what handler | ||
| 271 | they installed even if that signal is currently blocked. */ | ||
| 272 | if (sig >= 0 && sig < NSIG && sig != SIGKILL && sig != SIGSTOP | ||
| 273 | && handler != SIG_ERR) | ||
| 274 | { | ||
| 275 | #ifdef SIGABRT_COMPAT | ||
| 276 | if (sig == SIGABRT_COMPAT) | ||
| 277 | sig = SIGABRT; | ||
| 278 | #endif | ||
| 279 | |||
| 280 | if (blocked_set & (1U << sig)) | ||
| 281 | { | ||
| 282 | /* POSIX states that sigprocmask and signal are both | ||
| 283 | async-signal-safe. This is not true of our | ||
| 284 | implementation - there is a slight data race where an | ||
| 285 | asynchronous interrupt on signal A can occur after we | ||
| 286 | install blocked_handler but before we have updated | ||
| 287 | old_handlers for signal B, such that handler A can see | ||
| 288 | stale information if it calls signal(B). Oh well - | ||
| 289 | signal handlers really shouldn't try to manipulate the | ||
| 290 | installed handlers of unrelated signals. */ | ||
| 291 | handler_t result = old_handlers[sig]; | ||
| 292 | old_handlers[sig] = handler; | ||
| 293 | return result; | ||
| 294 | } | ||
| 295 | else | ||
| 296 | return signal (sig, handler); | ||
| 297 | } | ||
| 298 | else | ||
| 299 | { | ||
| 300 | errno = EINVAL; | ||
| 301 | return SIG_ERR; | ||
| 302 | } | ||
| 303 | } | ||
| 304 | |||
| 305 | #if GNULIB_defined_SIGPIPE | ||
| 306 | /* Raise the signal SIG. */ | ||
| 307 | int | ||
| 308 | rpl_raise (int sig) | ||
| 309 | # undef raise | ||
| 310 | { | ||
| 311 | switch (sig) | ||
| 312 | { | ||
| 313 | case SIGPIPE: | ||
| 314 | if (blocked_set & (1U << sig)) | ||
| 315 | pending_array[sig] = 1; | ||
| 316 | else | ||
| 317 | { | ||
| 318 | handler_t handler = SIGPIPE_handler; | ||
| 319 | if (handler == SIG_DFL) | ||
| 320 | exit (128 + SIGPIPE); | ||
| 321 | else if (handler != SIG_IGN) | ||
| 322 | (*handler) (sig); | ||
| 323 | } | ||
| 324 | return 0; | ||
| 325 | default: /* System defined signal */ | ||
| 326 | return raise (sig); | ||
| 327 | } | ||
| 328 | } | ||
| 329 | #endif | ||
diff --git a/lib/stdint.in.h b/lib/stdint.in.h index 09ac138b851..b6d08c754ae 100644 --- a/lib/stdint.in.h +++ b/lib/stdint.in.h | |||
| @@ -270,26 +270,36 @@ typedef unsigned long int gl_uintptr_t; | |||
| 270 | /* Note: These types are compiler dependent. It may be unwise to use them in | 270 | /* Note: These types are compiler dependent. It may be unwise to use them in |
| 271 | public header files. */ | 271 | public header files. */ |
| 272 | 272 | ||
| 273 | #undef intmax_t | 273 | /* If the system defines INTMAX_MAX, assume that intmax_t works, and |
| 274 | #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 | 274 | similarly for UINTMAX_MAX and uintmax_t. This avoids problems with |
| 275 | assuming one type where another is used by the system. */ | ||
| 276 | |||
| 277 | #ifndef INTMAX_MAX | ||
| 278 | # undef INTMAX_C | ||
| 279 | # undef intmax_t | ||
| 280 | # if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 | ||
| 275 | typedef long long int gl_intmax_t; | 281 | typedef long long int gl_intmax_t; |
| 276 | # define intmax_t gl_intmax_t | 282 | # define intmax_t gl_intmax_t |
| 277 | #elif defined GL_INT64_T | 283 | # elif defined GL_INT64_T |
| 278 | # define intmax_t int64_t | 284 | # define intmax_t int64_t |
| 279 | #else | 285 | # else |
| 280 | typedef long int gl_intmax_t; | 286 | typedef long int gl_intmax_t; |
| 281 | # define intmax_t gl_intmax_t | 287 | # define intmax_t gl_intmax_t |
| 288 | # endif | ||
| 282 | #endif | 289 | #endif |
| 283 | 290 | ||
| 284 | #undef uintmax_t | 291 | #ifndef UINTMAX_MAX |
| 285 | #if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 | 292 | # undef UINTMAX_C |
| 293 | # undef uintmax_t | ||
| 294 | # if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 | ||
| 286 | typedef unsigned long long int gl_uintmax_t; | 295 | typedef unsigned long long int gl_uintmax_t; |
| 287 | # define uintmax_t gl_uintmax_t | 296 | # define uintmax_t gl_uintmax_t |
| 288 | #elif defined GL_UINT64_T | 297 | # elif defined GL_UINT64_T |
| 289 | # define uintmax_t uint64_t | 298 | # define uintmax_t uint64_t |
| 290 | #else | 299 | # else |
| 291 | typedef unsigned long int gl_uintmax_t; | 300 | typedef unsigned long int gl_uintmax_t; |
| 292 | # define uintmax_t gl_uintmax_t | 301 | # define uintmax_t gl_uintmax_t |
| 302 | # endif | ||
| 293 | #endif | 303 | #endif |
| 294 | 304 | ||
| 295 | /* Verify that intmax_t and uintmax_t have the same size. Too much code | 305 | /* Verify that intmax_t and uintmax_t have the same size. Too much code |
| @@ -431,21 +441,23 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t) | |||
| 431 | 441 | ||
| 432 | /* 7.18.2.5. Limits of greatest-width integer types */ | 442 | /* 7.18.2.5. Limits of greatest-width integer types */ |
| 433 | 443 | ||
| 434 | #undef INTMAX_MIN | 444 | #ifndef INTMAX_MAX |
| 435 | #undef INTMAX_MAX | 445 | # undef INTMAX_MIN |
| 436 | #ifdef INT64_MAX | 446 | # ifdef INT64_MAX |
| 437 | # define INTMAX_MIN INT64_MIN | 447 | # define INTMAX_MIN INT64_MIN |
| 438 | # define INTMAX_MAX INT64_MAX | 448 | # define INTMAX_MAX INT64_MAX |
| 439 | #else | 449 | # else |
| 440 | # define INTMAX_MIN INT32_MIN | 450 | # define INTMAX_MIN INT32_MIN |
| 441 | # define INTMAX_MAX INT32_MAX | 451 | # define INTMAX_MAX INT32_MAX |
| 452 | # endif | ||
| 442 | #endif | 453 | #endif |
| 443 | 454 | ||
| 444 | #undef UINTMAX_MAX | 455 | #ifndef UINTMAX_MAX |
| 445 | #ifdef UINT64_MAX | 456 | # ifdef UINT64_MAX |
| 446 | # define UINTMAX_MAX UINT64_MAX | 457 | # define UINTMAX_MAX UINT64_MAX |
| 447 | #else | 458 | # else |
| 448 | # define UINTMAX_MAX UINT32_MAX | 459 | # define UINTMAX_MAX UINT32_MAX |
| 460 | # endif | ||
| 449 | #endif | 461 | #endif |
| 450 | 462 | ||
| 451 | /* 7.18.3. Limits of other integer types */ | 463 | /* 7.18.3. Limits of other integer types */ |
| @@ -568,22 +580,24 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t) | |||
| 568 | 580 | ||
| 569 | /* 7.18.4.2. Macros for greatest-width integer constants */ | 581 | /* 7.18.4.2. Macros for greatest-width integer constants */ |
| 570 | 582 | ||
| 571 | #undef INTMAX_C | 583 | #ifndef INTMAX_C |
| 572 | #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 | 584 | # if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 |
| 573 | # define INTMAX_C(x) x##LL | 585 | # define INTMAX_C(x) x##LL |
| 574 | #elif defined GL_INT64_T | 586 | # elif defined GL_INT64_T |
| 575 | # define INTMAX_C(x) INT64_C(x) | 587 | # define INTMAX_C(x) INT64_C(x) |
| 576 | #else | 588 | # else |
| 577 | # define INTMAX_C(x) x##L | 589 | # define INTMAX_C(x) x##L |
| 590 | # endif | ||
| 578 | #endif | 591 | #endif |
| 579 | 592 | ||
| 580 | #undef UINTMAX_C | 593 | #ifndef UINTMAX_C |
| 581 | #if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 | 594 | # if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 |
| 582 | # define UINTMAX_C(x) x##ULL | 595 | # define UINTMAX_C(x) x##ULL |
| 583 | #elif defined GL_UINT64_T | 596 | # elif defined GL_UINT64_T |
| 584 | # define UINTMAX_C(x) UINT64_C(x) | 597 | # define UINTMAX_C(x) UINT64_C(x) |
| 585 | #else | 598 | # else |
| 586 | # define UINTMAX_C(x) x##UL | 599 | # define UINTMAX_C(x) x##UL |
| 600 | # endif | ||
| 587 | #endif | 601 | #endif |
| 588 | 602 | ||
| 589 | #endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */ | 603 | #endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */ |
diff --git a/lib/strtoll.c b/lib/strtoll.c new file mode 100644 index 00000000000..75afa4d9bc9 --- /dev/null +++ b/lib/strtoll.c | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | /* Function to parse a `long long int' from text. | ||
| 2 | Copyright (C) 1995-1997, 1999, 2001, 2009-2011 Free Software Foundation, | ||
| 3 | Inc. | ||
| 4 | This file is part of the GNU C Library. | ||
| 5 | |||
| 6 | This program is free software: you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or | ||
| 9 | (at your option) any later version. | ||
| 10 | |||
| 11 | This program is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #define QUAD 1 | ||
| 20 | |||
| 21 | #include <strtol.c> | ||
| 22 | |||
| 23 | #ifdef _LIBC | ||
| 24 | # ifdef SHARED | ||
| 25 | # include <shlib-compat.h> | ||
| 26 | |||
| 27 | # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2) | ||
| 28 | compat_symbol (libc, __strtoll_internal, __strtoq_internal, GLIBC_2_0); | ||
| 29 | # endif | ||
| 30 | |||
| 31 | # endif | ||
| 32 | weak_alias (strtoll, strtoq) | ||
| 33 | #endif | ||
diff --git a/lib/unistd.in.h b/lib/unistd.in.h index fdf0fca54e9..769ecf0d43f 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h | |||
| @@ -117,78 +117,77 @@ | |||
| 117 | /* The definition of _GL_WARN_ON_USE is copied here. */ | 117 | /* The definition of _GL_WARN_ON_USE is copied here. */ |
| 118 | 118 | ||
| 119 | 119 | ||
| 120 | #if @GNULIB_GETHOSTNAME@ | 120 | /* Hide some function declarations from <winsock2.h>. */ |
| 121 | /* Get all possible declarations of gethostname(). */ | 121 | |
| 122 | # if @UNISTD_H_HAVE_WINSOCK2_H@ | 122 | #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ |
| 123 | # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H | 123 | # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H |
| 124 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | 124 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 125 | # undef socket | 125 | # undef socket |
| 126 | # define socket socket_used_without_including_sys_socket_h | 126 | # define socket socket_used_without_including_sys_socket_h |
| 127 | # undef connect | 127 | # undef connect |
| 128 | # define connect connect_used_without_including_sys_socket_h | 128 | # define connect connect_used_without_including_sys_socket_h |
| 129 | # undef accept | 129 | # undef accept |
| 130 | # define accept accept_used_without_including_sys_socket_h | 130 | # define accept accept_used_without_including_sys_socket_h |
| 131 | # undef bind | 131 | # undef bind |
| 132 | # define bind bind_used_without_including_sys_socket_h | 132 | # define bind bind_used_without_including_sys_socket_h |
| 133 | # undef getpeername | 133 | # undef getpeername |
| 134 | # define getpeername getpeername_used_without_including_sys_socket_h | 134 | # define getpeername getpeername_used_without_including_sys_socket_h |
| 135 | # undef getsockname | 135 | # undef getsockname |
| 136 | # define getsockname getsockname_used_without_including_sys_socket_h | 136 | # define getsockname getsockname_used_without_including_sys_socket_h |
| 137 | # undef getsockopt | 137 | # undef getsockopt |
| 138 | # define getsockopt getsockopt_used_without_including_sys_socket_h | 138 | # define getsockopt getsockopt_used_without_including_sys_socket_h |
| 139 | # undef listen | 139 | # undef listen |
| 140 | # define listen listen_used_without_including_sys_socket_h | 140 | # define listen listen_used_without_including_sys_socket_h |
| 141 | # undef recv | 141 | # undef recv |
| 142 | # define recv recv_used_without_including_sys_socket_h | 142 | # define recv recv_used_without_including_sys_socket_h |
| 143 | # undef send | 143 | # undef send |
| 144 | # define send send_used_without_including_sys_socket_h | 144 | # define send send_used_without_including_sys_socket_h |
| 145 | # undef recvfrom | 145 | # undef recvfrom |
| 146 | # define recvfrom recvfrom_used_without_including_sys_socket_h | 146 | # define recvfrom recvfrom_used_without_including_sys_socket_h |
| 147 | # undef sendto | 147 | # undef sendto |
| 148 | # define sendto sendto_used_without_including_sys_socket_h | 148 | # define sendto sendto_used_without_including_sys_socket_h |
| 149 | # undef setsockopt | 149 | # undef setsockopt |
| 150 | # define setsockopt setsockopt_used_without_including_sys_socket_h | 150 | # define setsockopt setsockopt_used_without_including_sys_socket_h |
| 151 | # undef shutdown | 151 | # undef shutdown |
| 152 | # define shutdown shutdown_used_without_including_sys_socket_h | 152 | # define shutdown shutdown_used_without_including_sys_socket_h |
| 153 | # else | 153 | # else |
| 154 | _GL_WARN_ON_USE (socket, | 154 | _GL_WARN_ON_USE (socket, |
| 155 | "socket() used without including <sys/socket.h>"); | 155 | "socket() used without including <sys/socket.h>"); |
| 156 | _GL_WARN_ON_USE (connect, | 156 | _GL_WARN_ON_USE (connect, |
| 157 | "connect() used without including <sys/socket.h>"); | 157 | "connect() used without including <sys/socket.h>"); |
| 158 | _GL_WARN_ON_USE (accept, | 158 | _GL_WARN_ON_USE (accept, |
| 159 | "accept() used without including <sys/socket.h>"); | 159 | "accept() used without including <sys/socket.h>"); |
| 160 | _GL_WARN_ON_USE (bind, | 160 | _GL_WARN_ON_USE (bind, |
| 161 | "bind() used without including <sys/socket.h>"); | 161 | "bind() used without including <sys/socket.h>"); |
| 162 | _GL_WARN_ON_USE (getpeername, | 162 | _GL_WARN_ON_USE (getpeername, |
| 163 | "getpeername() used without including <sys/socket.h>"); | 163 | "getpeername() used without including <sys/socket.h>"); |
| 164 | _GL_WARN_ON_USE (getsockname, | 164 | _GL_WARN_ON_USE (getsockname, |
| 165 | "getsockname() used without including <sys/socket.h>"); | 165 | "getsockname() used without including <sys/socket.h>"); |
| 166 | _GL_WARN_ON_USE (getsockopt, | 166 | _GL_WARN_ON_USE (getsockopt, |
| 167 | "getsockopt() used without including <sys/socket.h>"); | 167 | "getsockopt() used without including <sys/socket.h>"); |
| 168 | _GL_WARN_ON_USE (listen, | 168 | _GL_WARN_ON_USE (listen, |
| 169 | "listen() used without including <sys/socket.h>"); | 169 | "listen() used without including <sys/socket.h>"); |
| 170 | _GL_WARN_ON_USE (recv, | 170 | _GL_WARN_ON_USE (recv, |
| 171 | "recv() used without including <sys/socket.h>"); | 171 | "recv() used without including <sys/socket.h>"); |
| 172 | _GL_WARN_ON_USE (send, | 172 | _GL_WARN_ON_USE (send, |
| 173 | "send() used without including <sys/socket.h>"); | 173 | "send() used without including <sys/socket.h>"); |
| 174 | _GL_WARN_ON_USE (recvfrom, | 174 | _GL_WARN_ON_USE (recvfrom, |
| 175 | "recvfrom() used without including <sys/socket.h>"); | 175 | "recvfrom() used without including <sys/socket.h>"); |
| 176 | _GL_WARN_ON_USE (sendto, | 176 | _GL_WARN_ON_USE (sendto, |
| 177 | "sendto() used without including <sys/socket.h>"); | 177 | "sendto() used without including <sys/socket.h>"); |
| 178 | _GL_WARN_ON_USE (setsockopt, | 178 | _GL_WARN_ON_USE (setsockopt, |
| 179 | "setsockopt() used without including <sys/socket.h>"); | 179 | "setsockopt() used without including <sys/socket.h>"); |
| 180 | _GL_WARN_ON_USE (shutdown, | 180 | _GL_WARN_ON_USE (shutdown, |
| 181 | "shutdown() used without including <sys/socket.h>"); | 181 | "shutdown() used without including <sys/socket.h>"); |
| 182 | # endif | ||
| 183 | # endif | 182 | # endif |
| 184 | # if !defined _@GUARD_PREFIX@_SYS_SELECT_H | 183 | # endif |
| 185 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | 184 | # if !defined _@GUARD_PREFIX@_SYS_SELECT_H |
| 186 | # undef select | 185 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 187 | # define select select_used_without_including_sys_select_h | 186 | # undef select |
| 188 | # else | 187 | # define select select_used_without_including_sys_select_h |
| 189 | _GL_WARN_ON_USE (select, | 188 | # else |
| 190 | "select() used without including <sys/select.h>"); | 189 | _GL_WARN_ON_USE (select, |
| 191 | # endif | 190 | "select() used without including <sys/select.h>"); |
| 192 | # endif | 191 | # endif |
| 193 | # endif | 192 | # endif |
| 194 | #endif | 193 | #endif |