diff options
| author | Bill Wohler | 2014-02-23 18:04:35 -0800 |
|---|---|---|
| committer | Bill Wohler | 2014-02-23 18:04:35 -0800 |
| commit | 3e93bafb95608467e438ba7f725fd1f020669f8c (patch) | |
| tree | f2f90109f283e06a18caea3cb2a2623abcfb3a92 /lib | |
| parent | 791c0d7634e44bb92ca85af605be84ff2ae08963 (diff) | |
| parent | e918e27fdf331e89268fc2c9d7cf838d3ecf7aa7 (diff) | |
| download | emacs-3e93bafb95608467e438ba7f725fd1f020669f8c.tar.gz emacs-3e93bafb95608467e438ba7f725fd1f020669f8c.zip | |
Merge from trunk; up to 2014-02-23T23:41:17Z!lekktu@gmail.com.
Diffstat (limited to 'lib')
127 files changed, 5203 insertions, 389 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index a341609e895..f76d0d3928d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
| @@ -1,12 +1,18 @@ | |||
| 1 | BUILT_SOURCES = | 1 | BUILT_SOURCES = |
| 2 | CLEANFILES = | ||
| 2 | EXTRA_DIST = | 3 | EXTRA_DIST = |
| 3 | MOSTLYCLEANDIRS = | 4 | MOSTLYCLEANDIRS = |
| 4 | MOSTLYCLEANFILES = | 5 | MOSTLYCLEANFILES = |
| 5 | noinst_LIBRARIES = | 6 | noinst_LIBRARIES = |
| 7 | SUFFIXES = | ||
| 6 | 8 | ||
| 7 | AM_CFLAGS = $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS) | 9 | AM_CFLAGS = $(PROFILING_CFLAGS) $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS) |
| 8 | DEFAULT_INCLUDES = -I. -I$(top_srcdir)/lib -I../src -I$(top_srcdir)/src | 10 | DEFAULT_INCLUDES = -I. -I$(top_srcdir)/lib -I../src -I$(top_srcdir)/src |
| 9 | 11 | ||
| 12 | if BUILDING_FOR_WINDOWSNT | ||
| 13 | include ../nt/gnulib.mk | ||
| 14 | else | ||
| 10 | include gnulib.mk | 15 | include gnulib.mk |
| 11 | 16 | ||
| 12 | libgnu_a_SOURCES += openat-die.c save-cwd.c | 17 | libgnu_a_SOURCES += openat-die.c save-cwd.c |
| 18 | endif | ||
diff --git a/lib/acl-errno-valid.c b/lib/acl-errno-valid.c new file mode 100644 index 00000000000..3287382ea99 --- /dev/null +++ b/lib/acl-errno-valid.c | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* Test whether ACLs are well supported on this system. | ||
| 2 | |||
| 3 | Copyright 2013-2014 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 | Written by Paul Eggert. */ | ||
| 19 | |||
| 20 | #include <config.h> | ||
| 21 | |||
| 22 | #include <acl.h> | ||
| 23 | |||
| 24 | #include <errno.h> | ||
| 25 | |||
| 26 | /* Return true if errno value ERRNUM indicates that ACLs are well | ||
| 27 | supported on this system. ERRNUM should be an errno value obtained | ||
| 28 | after an ACL-related system call fails. */ | ||
| 29 | bool | ||
| 30 | acl_errno_valid (int errnum) | ||
| 31 | { | ||
| 32 | /* Recognize some common errors such as from an NFS mount that does | ||
| 33 | not support ACLs, even when local drives do. */ | ||
| 34 | switch (errnum) | ||
| 35 | { | ||
| 36 | case EBUSY: return false; | ||
| 37 | case EINVAL: return false; | ||
| 38 | #if defined __APPLE__ && defined __MACH__ | ||
| 39 | case ENOENT: return false; | ||
| 40 | #endif | ||
| 41 | case ENOSYS: return false; | ||
| 42 | |||
| 43 | #if defined ENOTSUP && ENOTSUP != EOPNOTSUPP | ||
| 44 | # if ENOTSUP != ENOSYS /* Needed for the MS-Windows port of GNU Emacs. */ | ||
| 45 | case ENOTSUP: return false; | ||
| 46 | # endif | ||
| 47 | #endif | ||
| 48 | |||
| 49 | case EOPNOTSUPP: return false; | ||
| 50 | default: return true; | ||
| 51 | } | ||
| 52 | } | ||
diff --git a/lib/acl-internal.h b/lib/acl-internal.h new file mode 100644 index 00000000000..fdffe648490 --- /dev/null +++ b/lib/acl-internal.h | |||
| @@ -0,0 +1,253 @@ | |||
| 1 | /* Internal implementation of access control lists. | ||
| 2 | |||
| 3 | Copyright (C) 2002-2003, 2005-2014 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 | Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible. */ | ||
| 19 | |||
| 20 | #include "acl.h" | ||
| 21 | |||
| 22 | #include <stdbool.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | |||
| 25 | /* All systems define the ACL related API in <sys/acl.h>. */ | ||
| 26 | #if HAVE_SYS_ACL_H | ||
| 27 | # include <sys/acl.h> | ||
| 28 | #endif | ||
| 29 | #if defined HAVE_FACL && ! defined GETACLCNT && defined ACL_CNT | ||
| 30 | # define GETACLCNT ACL_CNT | ||
| 31 | #endif | ||
| 32 | |||
| 33 | /* On Linux, additional ACL related API is available in <acl/libacl.h>. */ | ||
| 34 | #ifdef HAVE_ACL_LIBACL_H | ||
| 35 | # include <acl/libacl.h> | ||
| 36 | #endif | ||
| 37 | |||
| 38 | /* On HP-UX >= 11.11, additional ACL API is available in <aclv.h>. */ | ||
| 39 | #if HAVE_ACLV_H | ||
| 40 | # include <sys/types.h> | ||
| 41 | # include <aclv.h> | ||
| 42 | /* HP-UX 11.11 lacks these declarations. */ | ||
| 43 | extern int acl (char *, int, int, struct acl *); | ||
| 44 | extern int aclsort (int, int, struct acl *); | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #include <errno.h> | ||
| 48 | |||
| 49 | #include <limits.h> | ||
| 50 | #ifndef MIN | ||
| 51 | # define MIN(a,b) ((a) < (b) ? (a) : (b)) | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #ifndef SIZE_MAX | ||
| 55 | # define SIZE_MAX ((size_t) -1) | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #ifndef HAVE_FCHMOD | ||
| 59 | # define HAVE_FCHMOD false | ||
| 60 | # define fchmod(fd, mode) (-1) | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 64 | #error "Please include config.h first." | ||
| 65 | #endif | ||
| 66 | _GL_INLINE_HEADER_BEGIN | ||
| 67 | #ifndef ACL_INTERNAL_INLINE | ||
| 68 | # define ACL_INTERNAL_INLINE _GL_INLINE | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #if USE_ACL | ||
| 72 | |||
| 73 | # if HAVE_ACL_GET_FILE | ||
| 74 | /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ | ||
| 75 | /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ | ||
| 76 | |||
| 77 | # ifndef MIN_ACL_ENTRIES | ||
| 78 | # define MIN_ACL_ENTRIES 4 | ||
| 79 | # endif | ||
| 80 | |||
| 81 | /* POSIX 1003.1e (draft 17) */ | ||
| 82 | # ifdef HAVE_ACL_GET_FD | ||
| 83 | /* Most platforms have a 1-argument acl_get_fd, only OSF/1 has a 2-argument | ||
| 84 | macro(!). */ | ||
| 85 | # if HAVE_ACL_FREE_TEXT /* OSF/1 */ | ||
| 86 | ACL_INTERNAL_INLINE acl_t | ||
| 87 | rpl_acl_get_fd (int fd) | ||
| 88 | { | ||
| 89 | return acl_get_fd (fd, ACL_TYPE_ACCESS); | ||
| 90 | } | ||
| 91 | # undef acl_get_fd | ||
| 92 | # define acl_get_fd rpl_acl_get_fd | ||
| 93 | # endif | ||
| 94 | # else | ||
| 95 | # define HAVE_ACL_GET_FD false | ||
| 96 | # undef acl_get_fd | ||
| 97 | # define acl_get_fd(fd) (NULL) | ||
| 98 | # endif | ||
| 99 | |||
| 100 | /* POSIX 1003.1e (draft 17) */ | ||
| 101 | # ifdef HAVE_ACL_SET_FD | ||
| 102 | /* Most platforms have a 2-argument acl_set_fd, only OSF/1 has a 3-argument | ||
| 103 | macro(!). */ | ||
| 104 | # if HAVE_ACL_FREE_TEXT /* OSF/1 */ | ||
| 105 | ACL_INTERNAL_INLINE int | ||
| 106 | rpl_acl_set_fd (int fd, acl_t acl) | ||
| 107 | { | ||
| 108 | return acl_set_fd (fd, ACL_TYPE_ACCESS, acl); | ||
| 109 | } | ||
| 110 | # undef acl_set_fd | ||
| 111 | # define acl_set_fd rpl_acl_set_fd | ||
| 112 | # endif | ||
| 113 | # else | ||
| 114 | # define HAVE_ACL_SET_FD false | ||
| 115 | # undef acl_set_fd | ||
| 116 | # define acl_set_fd(fd, acl) (-1) | ||
| 117 | # endif | ||
| 118 | |||
| 119 | /* POSIX 1003.1e (draft 13) */ | ||
| 120 | # if ! HAVE_ACL_FREE_TEXT | ||
| 121 | # define acl_free_text(buf) acl_free (buf) | ||
| 122 | # endif | ||
| 123 | |||
| 124 | /* Linux-specific */ | ||
| 125 | # ifndef HAVE_ACL_EXTENDED_FILE | ||
| 126 | # define HAVE_ACL_EXTENDED_FILE false | ||
| 127 | # define acl_extended_file(name) (-1) | ||
| 128 | # endif | ||
| 129 | |||
| 130 | /* Linux-specific */ | ||
| 131 | # ifndef HAVE_ACL_FROM_MODE | ||
| 132 | # define HAVE_ACL_FROM_MODE false | ||
| 133 | # define acl_from_mode(mode) (NULL) | ||
| 134 | # endif | ||
| 135 | |||
| 136 | /* Set to 1 if a file's mode is implicit by the ACL. | ||
| 137 | Set to 0 if a file's mode is stored independently from the ACL. */ | ||
| 138 | # if (HAVE_ACL_COPY_EXT_NATIVE && HAVE_ACL_CREATE_ENTRY_NP) || defined __sgi /* Mac OS X, IRIX */ | ||
| 139 | # define MODE_INSIDE_ACL 0 | ||
| 140 | # else | ||
| 141 | # define MODE_INSIDE_ACL 1 | ||
| 142 | # endif | ||
| 143 | |||
| 144 | /* Return the number of entries in ACL. | ||
| 145 | Return -1 and set errno upon failure to determine it. */ | ||
| 146 | /* Define a replacement for acl_entries if needed. (Only Linux has it.) */ | ||
| 147 | # if !HAVE_ACL_ENTRIES | ||
| 148 | # define acl_entries rpl_acl_entries | ||
| 149 | extern int acl_entries (acl_t); | ||
| 150 | # endif | ||
| 151 | |||
| 152 | # if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */ | ||
| 153 | /* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED. | ||
| 154 | Return 1 if the given ACL is non-trivial. | ||
| 155 | Return 0 if it is trivial. */ | ||
| 156 | extern int acl_extended_nontrivial (acl_t); | ||
| 157 | # else | ||
| 158 | /* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS. | ||
| 159 | Return 1 if the given ACL is non-trivial. | ||
| 160 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. | ||
| 161 | Return -1 and set errno upon failure to determine it. */ | ||
| 162 | extern int acl_access_nontrivial (acl_t); | ||
| 163 | # endif | ||
| 164 | |||
| 165 | # elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ | ||
| 166 | |||
| 167 | /* Set to 1 if a file's mode is implicit by the ACL. | ||
| 168 | Set to 0 if a file's mode is stored independently from the ACL. */ | ||
| 169 | # if defined __CYGWIN__ /* Cygwin */ | ||
| 170 | # define MODE_INSIDE_ACL 0 | ||
| 171 | # else /* Solaris */ | ||
| 172 | # define MODE_INSIDE_ACL 1 | ||
| 173 | # endif | ||
| 174 | |||
| 175 | /* Return 1 if the given ACL is non-trivial. | ||
| 176 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 177 | extern int acl_nontrivial (int count, aclent_t *entries); | ||
| 178 | |||
| 179 | # ifdef ACE_GETACL /* Solaris 10 */ | ||
| 180 | |||
| 181 | /* Test an ACL retrieved with ACE_GETACL. | ||
| 182 | Return 1 if the given ACL, consisting of COUNT entries, is non-trivial. | ||
| 183 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 184 | extern int acl_ace_nontrivial (int count, ace_t *entries); | ||
| 185 | |||
| 186 | /* Definitions for when the built executable is executed on Solaris 10 | ||
| 187 | (newer version) or Solaris 11. */ | ||
| 188 | /* For a_type. */ | ||
| 189 | # define OLD_ALLOW 0 | ||
| 190 | # define OLD_DENY 1 | ||
| 191 | # define NEW_ACE_ACCESS_ALLOWED_ACE_TYPE 0 /* replaces ALLOW */ | ||
| 192 | # define NEW_ACE_ACCESS_DENIED_ACE_TYPE 1 /* replaces DENY */ | ||
| 193 | /* For a_flags. */ | ||
| 194 | # define OLD_ACE_OWNER 0x0100 | ||
| 195 | # define OLD_ACE_GROUP 0x0200 | ||
| 196 | # define OLD_ACE_OTHER 0x0400 | ||
| 197 | # define NEW_ACE_OWNER 0x1000 | ||
| 198 | # define NEW_ACE_GROUP 0x2000 | ||
| 199 | # define NEW_ACE_IDENTIFIER_GROUP 0x0040 | ||
| 200 | # define NEW_ACE_EVERYONE 0x4000 | ||
| 201 | /* For a_access_mask. */ | ||
| 202 | # define NEW_ACE_READ_DATA 0x001 /* corresponds to 'r' */ | ||
| 203 | # define NEW_ACE_WRITE_DATA 0x002 /* corresponds to 'w' */ | ||
| 204 | # define NEW_ACE_APPEND_DATA 0x004 | ||
| 205 | # define NEW_ACE_READ_NAMED_ATTRS 0x008 | ||
| 206 | # define NEW_ACE_WRITE_NAMED_ATTRS 0x010 | ||
| 207 | # define NEW_ACE_EXECUTE 0x020 | ||
| 208 | # define NEW_ACE_DELETE_CHILD 0x040 | ||
| 209 | # define NEW_ACE_READ_ATTRIBUTES 0x080 | ||
| 210 | # define NEW_ACE_WRITE_ATTRIBUTES 0x100 | ||
| 211 | # define NEW_ACE_DELETE 0x10000 | ||
| 212 | # define NEW_ACE_READ_ACL 0x20000 | ||
| 213 | # define NEW_ACE_WRITE_ACL 0x40000 | ||
| 214 | # define NEW_ACE_WRITE_OWNER 0x80000 | ||
| 215 | # define NEW_ACE_SYNCHRONIZE 0x100000 | ||
| 216 | |||
| 217 | # endif | ||
| 218 | |||
| 219 | # elif HAVE_GETACL /* HP-UX */ | ||
| 220 | |||
| 221 | /* Return 1 if the given ACL is non-trivial. | ||
| 222 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 223 | extern int acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb); | ||
| 224 | |||
| 225 | # if HAVE_ACLV_H /* HP-UX >= 11.11 */ | ||
| 226 | |||
| 227 | /* Return 1 if the given ACL is non-trivial. | ||
| 228 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 229 | extern int aclv_nontrivial (int count, struct acl *entries); | ||
| 230 | |||
| 231 | # endif | ||
| 232 | |||
| 233 | # elif HAVE_ACLX_GET && 0 /* AIX */ | ||
| 234 | |||
| 235 | /* TODO */ | ||
| 236 | |||
| 237 | # elif HAVE_STATACL /* older AIX */ | ||
| 238 | |||
| 239 | /* Return 1 if the given ACL is non-trivial. | ||
| 240 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 241 | extern int acl_nontrivial (struct acl *a); | ||
| 242 | |||
| 243 | # elif HAVE_ACLSORT /* NonStop Kernel */ | ||
| 244 | |||
| 245 | /* Return 1 if the given ACL is non-trivial. | ||
| 246 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 247 | extern int acl_nontrivial (int count, struct acl *entries); | ||
| 248 | |||
| 249 | # endif | ||
| 250 | |||
| 251 | #endif | ||
| 252 | |||
| 253 | _GL_INLINE_HEADER_END | ||
diff --git a/lib/acl.h b/lib/acl.h new file mode 100644 index 00000000000..d024f74ba67 --- /dev/null +++ b/lib/acl.h | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | /* acl.c - access control lists | ||
| 2 | |||
| 3 | Copyright (C) 2002, 2008-2014 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 | Written by Paul Eggert. */ | ||
| 19 | |||
| 20 | #include <stdbool.h> | ||
| 21 | #include <sys/types.h> | ||
| 22 | #include <sys/stat.h> | ||
| 23 | |||
| 24 | bool acl_errno_valid (int) _GL_ATTRIBUTE_CONST; | ||
| 25 | int file_has_acl (char const *, struct stat const *); | ||
| 26 | int qset_acl (char const *, int, mode_t); | ||
| 27 | int set_acl (char const *, int, mode_t); | ||
| 28 | int qcopy_acl (char const *, int, char const *, int, mode_t); | ||
| 29 | int copy_acl (char const *, int, char const *, int, mode_t); | ||
| 30 | int chmod_or_fchmod (char const *, int, mode_t); | ||
diff --git a/lib/acl_entries.c b/lib/acl_entries.c new file mode 100644 index 00000000000..39d6b28fe8a --- /dev/null +++ b/lib/acl_entries.c | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | /* Return the number of entries in an ACL. | ||
| 2 | |||
| 3 | Copyright (C) 2002-2003, 2005-2014 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 | Written by Paul Eggert and Andreas Gruenbacher. */ | ||
| 19 | |||
| 20 | #include <config.h> | ||
| 21 | |||
| 22 | #include "acl-internal.h" | ||
| 23 | |||
| 24 | /* This file assumes POSIX-draft like ACLs | ||
| 25 | (Linux, FreeBSD, Mac OS X, IRIX, Tru64). */ | ||
| 26 | |||
| 27 | /* Return the number of entries in ACL. | ||
| 28 | Return -1 and set errno upon failure to determine it. */ | ||
| 29 | |||
| 30 | int | ||
| 31 | acl_entries (acl_t acl) | ||
| 32 | { | ||
| 33 | int count = 0; | ||
| 34 | |||
| 35 | if (acl != NULL) | ||
| 36 | { | ||
| 37 | #if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, Mac OS X */ | ||
| 38 | # if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */ | ||
| 39 | /* acl_get_entry returns 0 when it successfully fetches an entry, | ||
| 40 | and -1/EINVAL at the end. */ | ||
| 41 | acl_entry_t ace; | ||
| 42 | int got_one; | ||
| 43 | |||
| 44 | for (got_one = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace); | ||
| 45 | got_one >= 0; | ||
| 46 | got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace)) | ||
| 47 | count++; | ||
| 48 | # else /* Linux, FreeBSD */ | ||
| 49 | /* acl_get_entry returns 1 when it successfully fetches an entry, | ||
| 50 | and 0 at the end. */ | ||
| 51 | acl_entry_t ace; | ||
| 52 | int got_one; | ||
| 53 | |||
| 54 | for (got_one = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace); | ||
| 55 | got_one > 0; | ||
| 56 | got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace)) | ||
| 57 | count++; | ||
| 58 | if (got_one < 0) | ||
| 59 | return -1; | ||
| 60 | # endif | ||
| 61 | #else /* IRIX, Tru64 */ | ||
| 62 | # if HAVE_ACL_TO_SHORT_TEXT /* IRIX */ | ||
| 63 | /* Don't use acl_get_entry: it is undocumented. */ | ||
| 64 | count = acl->acl_cnt; | ||
| 65 | # endif | ||
| 66 | # if HAVE_ACL_FREE_TEXT /* Tru64 */ | ||
| 67 | /* Don't use acl_get_entry: it takes only one argument and does not | ||
| 68 | work. */ | ||
| 69 | count = acl->acl_num; | ||
| 70 | # endif | ||
| 71 | #endif | ||
| 72 | } | ||
| 73 | |||
| 74 | return count; | ||
| 75 | } | ||
diff --git a/lib/alloca.in.h b/lib/alloca.in.h index 72d28ee3066..5de9aaabc49 100644 --- a/lib/alloca.in.h +++ b/lib/alloca.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Memory allocation on the stack. | 1 | /* Memory allocation on the stack. |
| 2 | 2 | ||
| 3 | Copyright (C) 1995, 1999, 2001-2004, 2006-2013 Free Software Foundation, | 3 | Copyright (C) 1995, 1999, 2001-2004, 2006-2014 Free Software Foundation, |
| 4 | Inc. | 4 | Inc. |
| 5 | 5 | ||
| 6 | This program is free software; you can redistribute it and/or modify it | 6 | This program is free software; you can redistribute it and/or modify it |
diff --git a/lib/allocator.h b/lib/allocator.h index b71fbbbb53c..0904b32154b 100644 --- a/lib/allocator.h +++ b/lib/allocator.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Memory allocators such as malloc+free. | 1 | /* Memory allocators such as malloc+free. |
| 2 | 2 | ||
| 3 | Copyright (C) 2011-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/at-func.c b/lib/at-func.c index 03c56788b08..c8ee073d110 100644 --- a/lib/at-func.c +++ b/lib/at-func.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Define at-style functions like fstatat, unlinkat, fchownat, etc. | 1 | /* Define at-style functions like fstatat, unlinkat, fchownat, etc. |
| 2 | Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2006, 2009-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/binary-io.c b/lib/binary-io.c new file mode 100644 index 00000000000..8bbdb44d121 --- /dev/null +++ b/lib/binary-io.c | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | #include <config.h> | ||
| 2 | #define BINARY_IO_INLINE _GL_EXTERN_INLINE | ||
| 3 | #include "binary-io.h" | ||
diff --git a/lib/binary-io.h b/lib/binary-io.h new file mode 100644 index 00000000000..7928f8c10cc --- /dev/null +++ b/lib/binary-io.h | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | /* Binary mode I/O. | ||
| 2 | Copyright (C) 2001, 2003, 2005, 2008-2014 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 | #ifndef _BINARY_H | ||
| 18 | #define _BINARY_H | ||
| 19 | |||
| 20 | /* For systems that distinguish between text and binary I/O. | ||
| 21 | O_BINARY is guaranteed by the gnulib <fcntl.h>. */ | ||
| 22 | #include <fcntl.h> | ||
| 23 | |||
| 24 | /* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...', | ||
| 25 | so we include it here first. */ | ||
| 26 | #include <stdio.h> | ||
| 27 | |||
| 28 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 29 | #error "Please include config.h first." | ||
| 30 | #endif | ||
| 31 | _GL_INLINE_HEADER_BEGIN | ||
| 32 | #ifndef BINARY_IO_INLINE | ||
| 33 | # define BINARY_IO_INLINE _GL_INLINE | ||
| 34 | #endif | ||
| 35 | |||
| 36 | /* set_binary_mode (fd, mode) | ||
| 37 | sets the binary/text I/O mode of file descriptor fd to the given mode | ||
| 38 | (must be O_BINARY or O_TEXT) and returns the previous mode. */ | ||
| 39 | #if O_BINARY | ||
| 40 | # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ | ||
| 41 | # include <io.h> /* declares setmode() */ | ||
| 42 | # define set_binary_mode setmode | ||
| 43 | # else | ||
| 44 | # define set_binary_mode _setmode | ||
| 45 | # undef fileno | ||
| 46 | # define fileno _fileno | ||
| 47 | # endif | ||
| 48 | #else | ||
| 49 | /* On reasonable systems, binary I/O is the only choice. */ | ||
| 50 | /* Use a function rather than a macro, to avoid gcc warnings | ||
| 51 | "warning: statement with no effect". */ | ||
| 52 | BINARY_IO_INLINE int | ||
| 53 | set_binary_mode (int fd, int mode) | ||
| 54 | { | ||
| 55 | (void) fd; | ||
| 56 | (void) mode; | ||
| 57 | return O_BINARY; | ||
| 58 | } | ||
| 59 | #endif | ||
| 60 | |||
| 61 | /* SET_BINARY (fd); | ||
| 62 | changes the file descriptor fd to perform binary I/O. */ | ||
| 63 | #ifdef __DJGPP__ | ||
| 64 | # include <unistd.h> /* declares isatty() */ | ||
| 65 | /* Avoid putting stdin/stdout in binary mode if it is connected to | ||
| 66 | the console, because that would make it impossible for the user | ||
| 67 | to interrupt the program through Ctrl-C or Ctrl-Break. */ | ||
| 68 | # define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0)) | ||
| 69 | #else | ||
| 70 | # define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY)) | ||
| 71 | #endif | ||
| 72 | |||
| 73 | _GL_INLINE_HEADER_END | ||
| 74 | |||
| 75 | #endif /* _BINARY_H */ | ||
diff --git a/lib/byteswap.in.h b/lib/byteswap.in.h new file mode 100644 index 00000000000..5d1592a5574 --- /dev/null +++ b/lib/byteswap.in.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /* byteswap.h - Byte swapping | ||
| 2 | Copyright (C) 2005, 2007, 2009-2014 Free Software Foundation, Inc. | ||
| 3 | Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005. | ||
| 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 | #ifndef _GL_BYTESWAP_H | ||
| 19 | #define _GL_BYTESWAP_H | ||
| 20 | |||
| 21 | /* Given an unsigned 16-bit argument X, return the value corresponding to | ||
| 22 | X with reversed byte order. */ | ||
| 23 | #define bswap_16(x) ((((x) & 0x00FF) << 8) | \ | ||
| 24 | (((x) & 0xFF00) >> 8)) | ||
| 25 | |||
| 26 | /* Given an unsigned 32-bit argument X, return the value corresponding to | ||
| 27 | X with reversed byte order. */ | ||
| 28 | #define bswap_32(x) ((((x) & 0x000000FF) << 24) | \ | ||
| 29 | (((x) & 0x0000FF00) << 8) | \ | ||
| 30 | (((x) & 0x00FF0000) >> 8) | \ | ||
| 31 | (((x) & 0xFF000000) >> 24)) | ||
| 32 | |||
| 33 | /* Given an unsigned 64-bit argument X, return the value corresponding to | ||
| 34 | X with reversed byte order. */ | ||
| 35 | #define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \ | ||
| 36 | (((x) & 0x000000000000FF00ULL) << 40) | \ | ||
| 37 | (((x) & 0x0000000000FF0000ULL) << 24) | \ | ||
| 38 | (((x) & 0x00000000FF000000ULL) << 8) | \ | ||
| 39 | (((x) & 0x000000FF00000000ULL) >> 8) | \ | ||
| 40 | (((x) & 0x0000FF0000000000ULL) >> 24) | \ | ||
| 41 | (((x) & 0x00FF000000000000ULL) >> 40) | \ | ||
| 42 | (((x) & 0xFF00000000000000ULL) >> 56)) | ||
| 43 | |||
| 44 | #endif /* _GL_BYTESWAP_H */ | ||
diff --git a/lib/c-ctype.c b/lib/c-ctype.c index 752d2e32aed..48c64783787 100644 --- a/lib/c-ctype.c +++ b/lib/c-ctype.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Character handling in C locale. | 1 | /* Character handling in C locale. |
| 2 | 2 | ||
| 3 | Copyright 2000-2003, 2006, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright 2000-2003, 2006, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/c-ctype.h b/lib/c-ctype.h index 3a66440ae9e..b465277619c 100644 --- a/lib/c-ctype.h +++ b/lib/c-ctype.h | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | <ctype.h> functions' behaviour depends on the current locale set via | 5 | <ctype.h> functions' behaviour depends on the current locale set via |
| 6 | setlocale. | 6 | setlocale. |
| 7 | 7 | ||
| 8 | Copyright (C) 2000-2003, 2006, 2008-2013 Free Software Foundation, Inc. | 8 | Copyright (C) 2000-2003, 2006, 2008-2014 Free Software Foundation, Inc. |
| 9 | 9 | ||
| 10 | This program is free software; you can redistribute it and/or modify | 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by | 11 | it under the terms of the GNU General Public License as published by |
| @@ -136,7 +136,8 @@ extern int c_tolower (int c) _GL_ATTRIBUTE_CONST; | |||
| 136 | extern int c_toupper (int c) _GL_ATTRIBUTE_CONST; | 136 | extern int c_toupper (int c) _GL_ATTRIBUTE_CONST; |
| 137 | 137 | ||
| 138 | 138 | ||
| 139 | #if defined __GNUC__ && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ && !defined NO_C_CTYPE_MACROS | 139 | #if (defined __GNUC__ && !defined __STRICT_ANSI__ && defined __OPTIMIZE__ \ |
| 140 | && !defined __OPTIMIZE_SIZE__ && !defined NO_C_CTYPE_MACROS) | ||
| 140 | 141 | ||
| 141 | /* ASCII optimizations. */ | 142 | /* ASCII optimizations. */ |
| 142 | 143 | ||
diff --git a/lib/c-strcase.h b/lib/c-strcase.h index 49e1bb03dd0..8e660441d08 100644 --- a/lib/c-strcase.h +++ b/lib/c-strcase.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Case-insensitive string comparison functions in C locale. | 1 | /* Case-insensitive string comparison functions in C locale. |
| 2 | Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2013 Free Software | 2 | Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2014 Free Software |
| 3 | Foundation, Inc. | 3 | Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
diff --git a/lib/c-strcasecmp.c b/lib/c-strcasecmp.c index ef85f0e67db..b9b26a4ce83 100644 --- a/lib/c-strcasecmp.c +++ b/lib/c-strcasecmp.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* c-strcasecmp.c -- case insensitive string comparator in C locale | 1 | /* c-strcasecmp.c -- case insensitive string comparator in C locale |
| 2 | Copyright (C) 1998-1999, 2005-2006, 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 1998-1999, 2005-2006, 2009-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/c-strncasecmp.c b/lib/c-strncasecmp.c index 04404b00cd4..972eb800795 100644 --- a/lib/c-strncasecmp.c +++ b/lib/c-strncasecmp.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* c-strncasecmp.c -- case insensitive string comparator in C locale | 1 | /* c-strncasecmp.c -- case insensitive string comparator in C locale |
| 2 | Copyright (C) 1998-1999, 2005-2006, 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 1998-1999, 2005-2006, 2009-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c index e2c19d1c1f1..b36fea28302 100644 --- a/lib/careadlinkat.c +++ b/lib/careadlinkat.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Read symbolic links into a buffer without size limitation, relative to fd. | 1 | /* Read symbolic links into a buffer without size limitation, relative to fd. |
| 2 | 2 | ||
| 3 | Copyright (C) 2001, 2003-2004, 2007, 2009-2013 Free Software Foundation, | 3 | Copyright (C) 2001, 2003-2004, 2007, 2009-2014 Free Software Foundation, |
| 4 | Inc. | 4 | Inc. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify |
diff --git a/lib/careadlinkat.h b/lib/careadlinkat.h index 46f88ae288a..704f8159b88 100644 --- a/lib/careadlinkat.h +++ b/lib/careadlinkat.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Read symbolic links into a buffer without size limitation, relative to fd. | 1 | /* Read symbolic links into a buffer without size limitation, relative to fd. |
| 2 | 2 | ||
| 3 | Copyright (C) 2011-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/close-stream.c b/lib/close-stream.c index d6a869287e3..87921d42938 100644 --- a/lib/close-stream.c +++ b/lib/close-stream.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Close a stream, with nicer error checking than fclose's. | 1 | /* Close a stream, with nicer error checking than fclose's. |
| 2 | 2 | ||
| 3 | Copyright (C) 1998-2002, 2004, 2006-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 1998-2002, 2004, 2006-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/count-one-bits.c b/lib/count-one-bits.c new file mode 100644 index 00000000000..66341d77cda --- /dev/null +++ b/lib/count-one-bits.c | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | #include <config.h> | ||
| 2 | #define COUNT_ONE_BITS_INLINE _GL_EXTERN_INLINE | ||
| 3 | #include "count-one-bits.h" | ||
| 4 | |||
| 5 | #if 1500 <= _MSC_VER && (defined _M_IX86 || defined _M_X64) | ||
| 6 | int popcount_support = -1; | ||
| 7 | #endif | ||
diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h new file mode 100644 index 00000000000..97b0f8a3f4b --- /dev/null +++ b/lib/count-one-bits.h | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | /* count-one-bits.h -- counts the number of 1-bits in a word. | ||
| 2 | Copyright (C) 2007-2014 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 | /* Written by Ben Pfaff. */ | ||
| 18 | |||
| 19 | #ifndef COUNT_ONE_BITS_H | ||
| 20 | #define COUNT_ONE_BITS_H 1 | ||
| 21 | |||
| 22 | #include <limits.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | |||
| 25 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 26 | #error "Please include config.h first." | ||
| 27 | #endif | ||
| 28 | _GL_INLINE_HEADER_BEGIN | ||
| 29 | #ifndef COUNT_ONE_BITS_INLINE | ||
| 30 | # define COUNT_ONE_BITS_INLINE _GL_INLINE | ||
| 31 | #endif | ||
| 32 | |||
| 33 | /* Expand to code that computes the number of 1-bits of the local | ||
| 34 | variable 'x' of type TYPE (an unsigned integer type) and return it | ||
| 35 | from the current function. */ | ||
| 36 | #define COUNT_ONE_BITS_GENERIC(TYPE) \ | ||
| 37 | do \ | ||
| 38 | { \ | ||
| 39 | int count = 0; \ | ||
| 40 | int bits; \ | ||
| 41 | for (bits = 0; bits < sizeof (TYPE) * CHAR_BIT; bits += 32) \ | ||
| 42 | { \ | ||
| 43 | count += count_one_bits_32 (x); \ | ||
| 44 | x = x >> 31 >> 1; \ | ||
| 45 | } \ | ||
| 46 | return count; \ | ||
| 47 | } \ | ||
| 48 | while (0) | ||
| 49 | |||
| 50 | /* Assuming the GCC builtin is BUILTIN and the MSC builtin is MSC_BUILTIN, | ||
| 51 | expand to code that computes the number of 1-bits of the local | ||
| 52 | variable 'x' of type TYPE (an unsigned integer type) and return it | ||
| 53 | from the current function. */ | ||
| 54 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) | ||
| 55 | # define COUNT_ONE_BITS(BUILTIN, MSC_BUILTIN, TYPE) return BUILTIN (x) | ||
| 56 | #else | ||
| 57 | |||
| 58 | /* Compute and return the number of 1-bits set in the least | ||
| 59 | significant 32 bits of X. */ | ||
| 60 | COUNT_ONE_BITS_INLINE int | ||
| 61 | count_one_bits_32 (unsigned int x) | ||
| 62 | { | ||
| 63 | x = ((x & 0xaaaaaaaaU) >> 1) + (x & 0x55555555U); | ||
| 64 | x = ((x & 0xccccccccU) >> 2) + (x & 0x33333333U); | ||
| 65 | x = (x >> 16) + (x & 0xffff); | ||
| 66 | x = ((x & 0xf0f0) >> 4) + (x & 0x0f0f); | ||
| 67 | return (x >> 8) + (x & 0x00ff); | ||
| 68 | } | ||
| 69 | |||
| 70 | # if 1500 <= _MSC_VER && (defined _M_IX86 || defined _M_X64) | ||
| 71 | |||
| 72 | /* While gcc falls back to its own generic code if the machine | ||
| 73 | on which it's running doesn't support popcount, with Microsoft's | ||
| 74 | compiler we need to detect and fallback ourselves. */ | ||
| 75 | # pragma intrinsic __cpuid | ||
| 76 | # pragma intrinsic __popcnt | ||
| 77 | # pragma intrinsic __popcnt64 | ||
| 78 | |||
| 79 | /* Return nonzero if popcount is supported. */ | ||
| 80 | |||
| 81 | /* 1 if supported, 0 if not supported, -1 if unknown. */ | ||
| 82 | extern int popcount_support; | ||
| 83 | |||
| 84 | COUNT_ONE_BITS_INLINE int | ||
| 85 | popcount_supported (void) | ||
| 86 | { | ||
| 87 | if (popcount_support < 0) | ||
| 88 | { | ||
| 89 | int cpu_info[4]; | ||
| 90 | __cpuid (cpu_info, 1); | ||
| 91 | popcount_support = (cpu_info[2] >> 23) & 1; /* See MSDN. */ | ||
| 92 | } | ||
| 93 | return popcount_support; | ||
| 94 | } | ||
| 95 | |||
| 96 | # define COUNT_ONE_BITS(BUILTIN, MSC_BUILTIN, TYPE) \ | ||
| 97 | do \ | ||
| 98 | { \ | ||
| 99 | if (popcount_supported ()) \ | ||
| 100 | return MSC_BUILTIN (x); \ | ||
| 101 | else \ | ||
| 102 | COUNT_ONE_BITS_GENERIC (TYPE); \ | ||
| 103 | } \ | ||
| 104 | while (0) | ||
| 105 | # else | ||
| 106 | # define COUNT_ONE_BITS(BUILTIN, MSC_BUILTIN, TYPE) \ | ||
| 107 | COUNT_ONE_BITS_GENERIC (TYPE) | ||
| 108 | # endif | ||
| 109 | #endif | ||
| 110 | |||
| 111 | /* Compute and return the number of 1-bits set in X. */ | ||
| 112 | COUNT_ONE_BITS_INLINE int | ||
| 113 | count_one_bits (unsigned int x) | ||
| 114 | { | ||
| 115 | COUNT_ONE_BITS (__builtin_popcount, __popcnt, unsigned int); | ||
| 116 | } | ||
| 117 | |||
| 118 | /* Compute and return the number of 1-bits set in X. */ | ||
| 119 | COUNT_ONE_BITS_INLINE int | ||
| 120 | count_one_bits_l (unsigned long int x) | ||
| 121 | { | ||
| 122 | COUNT_ONE_BITS (__builtin_popcountl, __popcnt, unsigned long int); | ||
| 123 | } | ||
| 124 | |||
| 125 | #if HAVE_UNSIGNED_LONG_LONG_INT | ||
| 126 | /* Compute and return the number of 1-bits set in X. */ | ||
| 127 | COUNT_ONE_BITS_INLINE int | ||
| 128 | count_one_bits_ll (unsigned long long int x) | ||
| 129 | { | ||
| 130 | COUNT_ONE_BITS (__builtin_popcountll, __popcnt64, unsigned long long int); | ||
| 131 | } | ||
| 132 | #endif | ||
| 133 | |||
| 134 | _GL_INLINE_HEADER_END | ||
| 135 | |||
| 136 | #endif /* COUNT_ONE_BITS_H */ | ||
diff --git a/lib/count-trailing-zeros.c b/lib/count-trailing-zeros.c new file mode 100644 index 00000000000..f3da8867428 --- /dev/null +++ b/lib/count-trailing-zeros.c | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | #include <config.h> | ||
| 2 | #define COUNT_TRAILING_ZEROS_INLINE _GL_EXTERN_INLINE | ||
| 3 | #include "count-trailing-zeros.h" | ||
diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h new file mode 100644 index 00000000000..8b65301eefb --- /dev/null +++ b/lib/count-trailing-zeros.h | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /* count-trailing-zeros.h -- counts the number of trailing 0 bits in a word. | ||
| 2 | Copyright 2013-2014 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 | /* Written by Paul Eggert. */ | ||
| 18 | |||
| 19 | #ifndef COUNT_TRAILING_ZEROS_H | ||
| 20 | #define COUNT_TRAILING_ZEROS_H 1 | ||
| 21 | |||
| 22 | #include <limits.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | |||
| 25 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 26 | #error "Please include config.h first." | ||
| 27 | #endif | ||
| 28 | _GL_INLINE_HEADER_BEGIN | ||
| 29 | #ifndef COUNT_TRAILING_ZEROS_INLINE | ||
| 30 | # define COUNT_TRAILING_ZEROS_INLINE _GL_INLINE | ||
| 31 | #endif | ||
| 32 | |||
| 33 | /* Assuming the GCC builtin is BUILTIN and the MSC builtin is MSC_BUILTIN, | ||
| 34 | expand to code that computes the number of trailing zeros of the local | ||
| 35 | variable 'x' of type TYPE (an unsigned integer type) and return it | ||
| 36 | from the current function. */ | ||
| 37 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) | ||
| 38 | # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ | ||
| 39 | return x ? BUILTIN (x) : CHAR_BIT * sizeof x; | ||
| 40 | #elif _MSC_VER | ||
| 41 | # pragma intrinsic _BitScanForward | ||
| 42 | # pragma intrinsic _BitScanForward64 | ||
| 43 | # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ | ||
| 44 | do \ | ||
| 45 | { \ | ||
| 46 | unsigned long result; \ | ||
| 47 | return MSC_BUILTIN (&result, x) ? result : CHAR_BIT * sizeof x; \ | ||
| 48 | } \ | ||
| 49 | while (0) | ||
| 50 | #else | ||
| 51 | # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ | ||
| 52 | do \ | ||
| 53 | { \ | ||
| 54 | int count = 0; \ | ||
| 55 | if (! x) \ | ||
| 56 | return CHAR_BIT * sizeof x; \ | ||
| 57 | for (count = 0; \ | ||
| 58 | (count < CHAR_BIT * sizeof x - 32 \ | ||
| 59 | && ! (x & 0xffffffffU)); \ | ||
| 60 | count += 32) \ | ||
| 61 | x = x >> 31 >> 1; \ | ||
| 62 | return count + count_trailing_zeros_32 (x); \ | ||
| 63 | } \ | ||
| 64 | while (0) | ||
| 65 | |||
| 66 | /* Compute and return the number of trailing zeros in the least | ||
| 67 | significant 32 bits of X. One of these bits must be nonzero. */ | ||
| 68 | COUNT_TRAILING_ZEROS_INLINE int | ||
| 69 | count_trailing_zeros_32 (unsigned int x) | ||
| 70 | { | ||
| 71 | /* http://graphics.stanford.edu/~seander/bithacks.html */ | ||
| 72 | static const char de_Bruijn_lookup[32] = { | ||
| 73 | 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, | ||
| 74 | 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 | ||
| 75 | }; | ||
| 76 | return de_Bruijn_lookup[(((x & -x) * 0x077cb531U) & 0xffffffffU) >> 27]; | ||
| 77 | } | ||
| 78 | #endif | ||
| 79 | |||
| 80 | /* Compute and return the number of trailing zeros in X. */ | ||
| 81 | COUNT_TRAILING_ZEROS_INLINE int | ||
| 82 | count_trailing_zeros (unsigned int x) | ||
| 83 | { | ||
| 84 | COUNT_TRAILING_ZEROS (__builtin_ctz, _BitScanForward, unsigned int); | ||
| 85 | } | ||
| 86 | |||
| 87 | /* Compute and return the number of trailing zeros in X. */ | ||
| 88 | COUNT_TRAILING_ZEROS_INLINE int | ||
| 89 | count_trailing_zeros_l (unsigned long int x) | ||
| 90 | { | ||
| 91 | COUNT_TRAILING_ZEROS (__builtin_ctzl, _BitScanForward, unsigned long int); | ||
| 92 | } | ||
| 93 | |||
| 94 | #if HAVE_UNSIGNED_LONG_LONG_INT | ||
| 95 | /* Compute and return the number of trailing zeros in X. */ | ||
| 96 | COUNT_TRAILING_ZEROS_INLINE int | ||
| 97 | count_trailing_zeros_ll (unsigned long long int x) | ||
| 98 | { | ||
| 99 | COUNT_TRAILING_ZEROS (__builtin_ctzll, _BitScanForward64, | ||
| 100 | unsigned long long int); | ||
| 101 | } | ||
| 102 | #endif | ||
| 103 | |||
| 104 | _GL_INLINE_HEADER_END | ||
| 105 | |||
| 106 | #endif | ||
diff --git a/lib/dirent.in.h b/lib/dirent.in.h index fad3797b8ba..4822d6b2c40 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* A GNU-like <dirent.h>. | 1 | /* A GNU-like <dirent.h>. |
| 2 | Copyright (C) 2006-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2006-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/dosname.h b/lib/dosname.h index ba63ce4bd37..b92adfac2ec 100644 --- a/lib/dosname.h +++ b/lib/dosname.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* File names on MS-DOS/Windows systems. | 1 | /* File names on MS-DOS/Windows systems. |
| 2 | 2 | ||
| 3 | Copyright (C) 2000-2001, 2004-2006, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2000-2001, 2004-2006, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/dtotimespec.c b/lib/dtotimespec.c index ecce2e5bcc5..57a0cee2611 100644 --- a/lib/dtotimespec.c +++ b/lib/dtotimespec.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Convert double to timespec. | 1 | /* Convert double to timespec. |
| 2 | 2 | ||
| 3 | Copyright (C) 2011-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -29,41 +29,31 @@ | |||
| 29 | struct timespec | 29 | struct timespec |
| 30 | dtotimespec (double sec) | 30 | dtotimespec (double sec) |
| 31 | { | 31 | { |
| 32 | enum { BILLION = 1000 * 1000 * 1000 }; | ||
| 33 | double min_representable = TYPE_MINIMUM (time_t); | 32 | double min_representable = TYPE_MINIMUM (time_t); |
| 34 | double max_representable = | 33 | double max_representable = |
| 35 | ((TYPE_MAXIMUM (time_t) * (double) BILLION + (BILLION - 1)) | 34 | ((TYPE_MAXIMUM (time_t) * (double) TIMESPEC_RESOLUTION |
| 36 | / BILLION); | 35 | + (TIMESPEC_RESOLUTION - 1)) |
| 37 | struct timespec r; | 36 | / TIMESPEC_RESOLUTION); |
| 38 | 37 | ||
| 39 | if (! (min_representable < sec)) | 38 | if (! (min_representable < sec)) |
| 40 | { | 39 | return make_timespec (TYPE_MINIMUM (time_t), 0); |
| 41 | r.tv_sec = TYPE_MINIMUM (time_t); | ||
| 42 | r.tv_nsec = 0; | ||
| 43 | } | ||
| 44 | else if (! (sec < max_representable)) | 40 | else if (! (sec < max_representable)) |
| 45 | { | 41 | return make_timespec (TYPE_MAXIMUM (time_t), TIMESPEC_RESOLUTION - 1); |
| 46 | r.tv_sec = TYPE_MAXIMUM (time_t); | ||
| 47 | r.tv_nsec = BILLION - 1; | ||
| 48 | } | ||
| 49 | else | 42 | else |
| 50 | { | 43 | { |
| 51 | time_t s = sec; | 44 | time_t s = sec; |
| 52 | double frac = BILLION * (sec - s); | 45 | double frac = TIMESPEC_RESOLUTION * (sec - s); |
| 53 | long ns = frac; | 46 | long ns = frac; |
| 54 | ns += ns < frac; | 47 | ns += ns < frac; |
| 55 | s += ns / BILLION; | 48 | s += ns / TIMESPEC_RESOLUTION; |
| 56 | ns %= BILLION; | 49 | ns %= TIMESPEC_RESOLUTION; |
| 57 | 50 | ||
| 58 | if (ns < 0) | 51 | if (ns < 0) |
| 59 | { | 52 | { |
| 60 | s--; | 53 | s--; |
| 61 | ns += BILLION; | 54 | ns += TIMESPEC_RESOLUTION; |
| 62 | } | 55 | } |
| 63 | 56 | ||
| 64 | r.tv_sec = s; | 57 | return make_timespec (s, ns); |
| 65 | r.tv_nsec = ns; | ||
| 66 | } | 58 | } |
| 67 | |||
| 68 | return r; | ||
| 69 | } | 59 | } |
diff --git a/lib/dup2.c b/lib/dup2.c index 9219eb38238..7de68054990 100644 --- a/lib/dup2.c +++ b/lib/dup2.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Duplicate an open file descriptor to a specified file descriptor. | 1 | /* Duplicate an open file descriptor to a specified file descriptor. |
| 2 | 2 | ||
| 3 | Copyright (C) 1999, 2004-2007, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 1999, 2004-2007, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -96,7 +96,11 @@ rpl_dup2 (int fd, int desired_fd) | |||
| 96 | /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF. | 96 | /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF. |
| 97 | On Cygwin 1.5.x, dup2 (1, 1) returns 0. | 97 | On Cygwin 1.5.x, dup2 (1, 1) returns 0. |
| 98 | On Cygwin 1.7.17, dup2 (1, -1) dumps core. | 98 | On Cygwin 1.7.17, dup2 (1, -1) dumps core. |
| 99 | On Cygwin 1.7.25, dup2 (1, 256) can dump core. | ||
| 99 | On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */ | 100 | On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */ |
| 101 | # if HAVE_SETDTABLESIZE | ||
| 102 | setdtablesize (desired_fd + 1); | ||
| 103 | # endif | ||
| 100 | if (desired_fd < 0) | 104 | if (desired_fd < 0) |
| 101 | fd = desired_fd; | 105 | fd = desired_fd; |
| 102 | if (fd == desired_fd) | 106 | if (fd == desired_fd) |
diff --git a/lib/errno.in.h b/lib/errno.in.h new file mode 100644 index 00000000000..832afc8f853 --- /dev/null +++ b/lib/errno.in.h | |||
| @@ -0,0 +1,279 @@ | |||
| 1 | /* A POSIX-like <errno.h>. | ||
| 2 | |||
| 3 | Copyright (C) 2008-2014 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, or (at your option) | ||
| 8 | 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 | #ifndef _@GUARD_PREFIX@_ERRNO_H | ||
| 19 | |||
| 20 | #if __GNUC__ >= 3 | ||
| 21 | @PRAGMA_SYSTEM_HEADER@ | ||
| 22 | #endif | ||
| 23 | @PRAGMA_COLUMNS@ | ||
| 24 | |||
| 25 | /* The include_next requires a split double-inclusion guard. */ | ||
| 26 | #@INCLUDE_NEXT@ @NEXT_ERRNO_H@ | ||
| 27 | |||
| 28 | #ifndef _@GUARD_PREFIX@_ERRNO_H | ||
| 29 | #define _@GUARD_PREFIX@_ERRNO_H | ||
| 30 | |||
| 31 | |||
| 32 | /* On native Windows platforms, many macros are not defined. */ | ||
| 33 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 34 | |||
| 35 | /* These are the same values as defined by MSVC 10, for interoperability. */ | ||
| 36 | |||
| 37 | # ifndef ENOMSG | ||
| 38 | # define ENOMSG 122 | ||
| 39 | # define GNULIB_defined_ENOMSG 1 | ||
| 40 | # endif | ||
| 41 | |||
| 42 | # ifndef EIDRM | ||
| 43 | # define EIDRM 111 | ||
| 44 | # define GNULIB_defined_EIDRM 1 | ||
| 45 | # endif | ||
| 46 | |||
| 47 | # ifndef ENOLINK | ||
| 48 | # define ENOLINK 121 | ||
| 49 | # define GNULIB_defined_ENOLINK 1 | ||
| 50 | # endif | ||
| 51 | |||
| 52 | # ifndef EPROTO | ||
| 53 | # define EPROTO 134 | ||
| 54 | # define GNULIB_defined_EPROTO 1 | ||
| 55 | # endif | ||
| 56 | |||
| 57 | # ifndef EBADMSG | ||
| 58 | # define EBADMSG 104 | ||
| 59 | # define GNULIB_defined_EBADMSG 1 | ||
| 60 | # endif | ||
| 61 | |||
| 62 | # ifndef EOVERFLOW | ||
| 63 | # define EOVERFLOW 132 | ||
| 64 | # define GNULIB_defined_EOVERFLOW 1 | ||
| 65 | # endif | ||
| 66 | |||
| 67 | # ifndef ENOTSUP | ||
| 68 | # define ENOTSUP 129 | ||
| 69 | # define GNULIB_defined_ENOTSUP 1 | ||
| 70 | # endif | ||
| 71 | |||
| 72 | # ifndef ENETRESET | ||
| 73 | # define ENETRESET 117 | ||
| 74 | # define GNULIB_defined_ENETRESET 1 | ||
| 75 | # endif | ||
| 76 | |||
| 77 | # ifndef ECONNABORTED | ||
| 78 | # define ECONNABORTED 106 | ||
| 79 | # define GNULIB_defined_ECONNABORTED 1 | ||
| 80 | # endif | ||
| 81 | |||
| 82 | # ifndef ECANCELED | ||
| 83 | # define ECANCELED 105 | ||
| 84 | # define GNULIB_defined_ECANCELED 1 | ||
| 85 | # endif | ||
| 86 | |||
| 87 | # ifndef EOWNERDEAD | ||
| 88 | # define EOWNERDEAD 133 | ||
| 89 | # define GNULIB_defined_EOWNERDEAD 1 | ||
| 90 | # endif | ||
| 91 | |||
| 92 | # ifndef ENOTRECOVERABLE | ||
| 93 | # define ENOTRECOVERABLE 127 | ||
| 94 | # define GNULIB_defined_ENOTRECOVERABLE 1 | ||
| 95 | # endif | ||
| 96 | |||
| 97 | # ifndef EINPROGRESS | ||
| 98 | # define EINPROGRESS 112 | ||
| 99 | # define EALREADY 103 | ||
| 100 | # define ENOTSOCK 128 | ||
| 101 | # define EDESTADDRREQ 109 | ||
| 102 | # define EMSGSIZE 115 | ||
| 103 | # define EPROTOTYPE 136 | ||
| 104 | # define ENOPROTOOPT 123 | ||
| 105 | # define EPROTONOSUPPORT 135 | ||
| 106 | # define EOPNOTSUPP 130 | ||
| 107 | # define EAFNOSUPPORT 102 | ||
| 108 | # define EADDRINUSE 100 | ||
| 109 | # define EADDRNOTAVAIL 101 | ||
| 110 | # define ENETDOWN 116 | ||
| 111 | # define ENETUNREACH 118 | ||
| 112 | # define ECONNRESET 108 | ||
| 113 | # define ENOBUFS 119 | ||
| 114 | # define EISCONN 113 | ||
| 115 | # define ENOTCONN 126 | ||
| 116 | # define ETIMEDOUT 138 | ||
| 117 | # define ECONNREFUSED 107 | ||
| 118 | # define ELOOP 114 | ||
| 119 | # define EHOSTUNREACH 110 | ||
| 120 | # define EWOULDBLOCK 140 | ||
| 121 | # define GNULIB_defined_ESOCK 1 | ||
| 122 | # endif | ||
| 123 | |||
| 124 | # ifndef ETXTBSY | ||
| 125 | # define ETXTBSY 139 | ||
| 126 | # define ENODATA 120 /* not required by POSIX */ | ||
| 127 | # define ENOSR 124 /* not required by POSIX */ | ||
| 128 | # define ENOSTR 125 /* not required by POSIX */ | ||
| 129 | # define ETIME 137 /* not required by POSIX */ | ||
| 130 | # define EOTHER 131 /* not required by POSIX */ | ||
| 131 | # define GNULIB_defined_ESTREAMS 1 | ||
| 132 | # endif | ||
| 133 | |||
| 134 | /* These are intentionally the same values as the WSA* error numbers, defined | ||
| 135 | in <winsock2.h>. */ | ||
| 136 | # define ESOCKTNOSUPPORT 10044 /* not required by POSIX */ | ||
| 137 | # define EPFNOSUPPORT 10046 /* not required by POSIX */ | ||
| 138 | # define ESHUTDOWN 10058 /* not required by POSIX */ | ||
| 139 | # define ETOOMANYREFS 10059 /* not required by POSIX */ | ||
| 140 | # define EHOSTDOWN 10064 /* not required by POSIX */ | ||
| 141 | # define EPROCLIM 10067 /* not required by POSIX */ | ||
| 142 | # define EUSERS 10068 /* not required by POSIX */ | ||
| 143 | # define EDQUOT 10069 | ||
| 144 | # define ESTALE 10070 | ||
| 145 | # define EREMOTE 10071 /* not required by POSIX */ | ||
| 146 | # define GNULIB_defined_EWINSOCK 1 | ||
| 147 | |||
| 148 | # endif | ||
| 149 | |||
| 150 | |||
| 151 | /* On OSF/1 5.1, when _XOPEN_SOURCE_EXTENDED is not defined, the macros | ||
| 152 | EMULTIHOP, ENOLINK, EOVERFLOW are not defined. */ | ||
| 153 | # if @EMULTIHOP_HIDDEN@ | ||
| 154 | # define EMULTIHOP @EMULTIHOP_VALUE@ | ||
| 155 | # define GNULIB_defined_EMULTIHOP 1 | ||
| 156 | # endif | ||
| 157 | # if @ENOLINK_HIDDEN@ | ||
| 158 | # define ENOLINK @ENOLINK_VALUE@ | ||
| 159 | # define GNULIB_defined_ENOLINK 1 | ||
| 160 | # endif | ||
| 161 | # if @EOVERFLOW_HIDDEN@ | ||
| 162 | # define EOVERFLOW @EOVERFLOW_VALUE@ | ||
| 163 | # define GNULIB_defined_EOVERFLOW 1 | ||
| 164 | # endif | ||
| 165 | |||
| 166 | |||
| 167 | /* On OpenBSD 4.0 and on native Windows, the macros ENOMSG, EIDRM, ENOLINK, | ||
| 168 | EPROTO, EMULTIHOP, EBADMSG, EOVERFLOW, ENOTSUP, ECANCELED are not defined. | ||
| 169 | Likewise, on NonStop Kernel, EDQUOT is not defined. | ||
| 170 | Define them here. Values >= 2000 seem safe to use: Solaris ESTALE = 151, | ||
| 171 | HP-UX EWOULDBLOCK = 246, IRIX EDQUOT = 1133. | ||
| 172 | |||
| 173 | Note: When one of these systems defines some of these macros some day, | ||
| 174 | binaries will have to be recompiled so that they recognizes the new | ||
| 175 | errno values from the system. */ | ||
| 176 | |||
| 177 | # ifndef ENOMSG | ||
| 178 | # define ENOMSG 2000 | ||
| 179 | # define GNULIB_defined_ENOMSG 1 | ||
| 180 | # endif | ||
| 181 | |||
| 182 | # ifndef EIDRM | ||
| 183 | # define EIDRM 2001 | ||
| 184 | # define GNULIB_defined_EIDRM 1 | ||
| 185 | # endif | ||
| 186 | |||
| 187 | # ifndef ENOLINK | ||
| 188 | # define ENOLINK 2002 | ||
| 189 | # define GNULIB_defined_ENOLINK 1 | ||
| 190 | # endif | ||
| 191 | |||
| 192 | # ifndef EPROTO | ||
| 193 | # define EPROTO 2003 | ||
| 194 | # define GNULIB_defined_EPROTO 1 | ||
| 195 | # endif | ||
| 196 | |||
| 197 | # ifndef EMULTIHOP | ||
| 198 | # define EMULTIHOP 2004 | ||
| 199 | # define GNULIB_defined_EMULTIHOP 1 | ||
| 200 | # endif | ||
| 201 | |||
| 202 | # ifndef EBADMSG | ||
| 203 | # define EBADMSG 2005 | ||
| 204 | # define GNULIB_defined_EBADMSG 1 | ||
| 205 | # endif | ||
| 206 | |||
| 207 | # ifndef EOVERFLOW | ||
| 208 | # define EOVERFLOW 2006 | ||
| 209 | # define GNULIB_defined_EOVERFLOW 1 | ||
| 210 | # endif | ||
| 211 | |||
| 212 | # ifndef ENOTSUP | ||
| 213 | # define ENOTSUP 2007 | ||
| 214 | # define GNULIB_defined_ENOTSUP 1 | ||
| 215 | # endif | ||
| 216 | |||
| 217 | # ifndef ENETRESET | ||
| 218 | # define ENETRESET 2011 | ||
| 219 | # define GNULIB_defined_ENETRESET 1 | ||
| 220 | # endif | ||
| 221 | |||
| 222 | # ifndef ECONNABORTED | ||
| 223 | # define ECONNABORTED 2012 | ||
| 224 | # define GNULIB_defined_ECONNABORTED 1 | ||
| 225 | # endif | ||
| 226 | |||
| 227 | # ifndef ESTALE | ||
| 228 | # define ESTALE 2009 | ||
| 229 | # define GNULIB_defined_ESTALE 1 | ||
| 230 | # endif | ||
| 231 | |||
| 232 | # ifndef EDQUOT | ||
| 233 | # define EDQUOT 2010 | ||
| 234 | # define GNULIB_defined_EDQUOT 1 | ||
| 235 | # endif | ||
| 236 | |||
| 237 | # ifndef ECANCELED | ||
| 238 | # define ECANCELED 2008 | ||
| 239 | # define GNULIB_defined_ECANCELED 1 | ||
| 240 | # endif | ||
| 241 | |||
| 242 | /* On many platforms, the macros EOWNERDEAD and ENOTRECOVERABLE are not | ||
| 243 | defined. */ | ||
| 244 | |||
| 245 | # ifndef EOWNERDEAD | ||
| 246 | # if defined __sun | ||
| 247 | /* Use the same values as defined for Solaris >= 8, for | ||
| 248 | interoperability. */ | ||
| 249 | # define EOWNERDEAD 58 | ||
| 250 | # define ENOTRECOVERABLE 59 | ||
| 251 | # elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 252 | /* We have a conflict here: pthreads-win32 defines these values | ||
| 253 | differently than MSVC 10. It's hairy to decide which one to use. */ | ||
| 254 | # if defined __MINGW32__ && !defined USE_WINDOWS_THREADS | ||
| 255 | /* Use the same values as defined by pthreads-win32, for | ||
| 256 | interoperability. */ | ||
| 257 | # define EOWNERDEAD 43 | ||
| 258 | # define ENOTRECOVERABLE 44 | ||
| 259 | # else | ||
| 260 | /* Use the same values as defined by MSVC 10, for | ||
| 261 | interoperability. */ | ||
| 262 | # define EOWNERDEAD 133 | ||
| 263 | # define ENOTRECOVERABLE 127 | ||
| 264 | # endif | ||
| 265 | # else | ||
| 266 | # define EOWNERDEAD 2013 | ||
| 267 | # define ENOTRECOVERABLE 2014 | ||
| 268 | # endif | ||
| 269 | # define GNULIB_defined_EOWNERDEAD 1 | ||
| 270 | # define GNULIB_defined_ENOTRECOVERABLE 1 | ||
| 271 | # endif | ||
| 272 | |||
| 273 | # ifndef EILSEQ | ||
| 274 | # define EILSEQ 2015 | ||
| 275 | # define GNULIB_defined_EILSEQ 1 | ||
| 276 | # endif | ||
| 277 | |||
| 278 | #endif /* _@GUARD_PREFIX@_ERRNO_H */ | ||
| 279 | #endif /* _@GUARD_PREFIX@_ERRNO_H */ | ||
diff --git a/lib/euidaccess.c b/lib/euidaccess.c index f73438e6f47..363e6fe2d70 100644 --- a/lib/euidaccess.c +++ b/lib/euidaccess.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* euidaccess -- check if effective user id can access file | 1 | /* euidaccess -- check if effective user id can access file |
| 2 | 2 | ||
| 3 | Copyright (C) 1990-1991, 1995, 1998, 2000, 2003-2006, 2008-2013 Free | 3 | Copyright (C) 1990-1991, 1995, 1998, 2000, 2003-2006, 2008-2014 Free |
| 4 | Software Foundation, Inc. | 4 | Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | This file is part of the GNU C Library. | 6 | This file is part of the GNU C Library. |
diff --git a/lib/execinfo.in.h b/lib/execinfo.in.h index 6cfc8d56d2d..5d10aecd807 100644 --- a/lib/execinfo.in.h +++ b/lib/execinfo.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Information about executables. | 1 | /* Information about executables. |
| 2 | 2 | ||
| 3 | Copyright (C) 2012-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2012-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -20,6 +20,9 @@ | |||
| 20 | #ifndef _GL_EXECINFO_H | 20 | #ifndef _GL_EXECINFO_H |
| 21 | #define _GL_EXECINFO_H | 21 | #define _GL_EXECINFO_H |
| 22 | 22 | ||
| 23 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 24 | #error "Please include config.h first." | ||
| 25 | #endif | ||
| 23 | _GL_INLINE_HEADER_BEGIN | 26 | _GL_INLINE_HEADER_BEGIN |
| 24 | #ifndef _GL_EXECINFO_INLINE | 27 | #ifndef _GL_EXECINFO_INLINE |
| 25 | # define _GL_EXECINFO_INLINE _GL_INLINE | 28 | # define _GL_EXECINFO_INLINE _GL_INLINE |
diff --git a/lib/faccessat.c b/lib/faccessat.c index f3c3f6736d2..44a38ae6598 100644 --- a/lib/faccessat.c +++ b/lib/faccessat.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Check the access rights of a file relative to an open directory. | 1 | /* Check the access rights of a file relative to an open directory. |
| 2 | Copyright (C) 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2009-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/fcntl.c b/lib/fcntl.c new file mode 100644 index 00000000000..54f748606b7 --- /dev/null +++ b/lib/fcntl.c | |||
| @@ -0,0 +1,311 @@ | |||
| 1 | /* Provide file descriptor control. | ||
| 2 | |||
| 3 | Copyright (C) 2009-2014 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 | /* Written by Eric Blake <ebb9@byu.net>. */ | ||
| 19 | |||
| 20 | #include <config.h> | ||
| 21 | |||
| 22 | /* Specification. */ | ||
| 23 | #include <fcntl.h> | ||
| 24 | |||
| 25 | #include <errno.h> | ||
| 26 | #include <limits.h> | ||
| 27 | #include <stdarg.h> | ||
| 28 | #include <unistd.h> | ||
| 29 | |||
| 30 | #if !HAVE_FCNTL | ||
| 31 | # define rpl_fcntl fcntl | ||
| 32 | #endif | ||
| 33 | #undef fcntl | ||
| 34 | |||
| 35 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 36 | /* Get declarations of the native Windows API functions. */ | ||
| 37 | # define WIN32_LEAN_AND_MEAN | ||
| 38 | # include <windows.h> | ||
| 39 | |||
| 40 | /* Get _get_osfhandle. */ | ||
| 41 | # include "msvc-nothrow.h" | ||
| 42 | |||
| 43 | /* Upper bound on getdtablesize(). See lib/getdtablesize.c. */ | ||
| 44 | # define OPEN_MAX_MAX 0x10000 | ||
| 45 | |||
| 46 | /* Duplicate OLDFD into the first available slot of at least NEWFD, | ||
| 47 | which must be positive, with FLAGS determining whether the duplicate | ||
| 48 | will be inheritable. */ | ||
| 49 | static int | ||
| 50 | dupfd (int oldfd, int newfd, int flags) | ||
| 51 | { | ||
| 52 | /* Mingw has no way to create an arbitrary fd. Iterate until all | ||
| 53 | file descriptors less than newfd are filled up. */ | ||
| 54 | HANDLE curr_process = GetCurrentProcess (); | ||
| 55 | HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd); | ||
| 56 | unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT]; | ||
| 57 | unsigned int fds_to_close_bound = 0; | ||
| 58 | int result; | ||
| 59 | BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE; | ||
| 60 | int mode; | ||
| 61 | |||
| 62 | if (newfd < 0 || getdtablesize () <= newfd) | ||
| 63 | { | ||
| 64 | errno = EINVAL; | ||
| 65 | return -1; | ||
| 66 | } | ||
| 67 | if (old_handle == INVALID_HANDLE_VALUE | ||
| 68 | || (mode = setmode (oldfd, O_BINARY)) == -1) | ||
| 69 | { | ||
| 70 | /* oldfd is not open, or is an unassigned standard file | ||
| 71 | descriptor. */ | ||
| 72 | errno = EBADF; | ||
| 73 | return -1; | ||
| 74 | } | ||
| 75 | setmode (oldfd, mode); | ||
| 76 | flags |= mode; | ||
| 77 | |||
| 78 | for (;;) | ||
| 79 | { | ||
| 80 | HANDLE new_handle; | ||
| 81 | int duplicated_fd; | ||
| 82 | unsigned int index; | ||
| 83 | |||
| 84 | if (!DuplicateHandle (curr_process, /* SourceProcessHandle */ | ||
| 85 | old_handle, /* SourceHandle */ | ||
| 86 | curr_process, /* TargetProcessHandle */ | ||
| 87 | (PHANDLE) &new_handle, /* TargetHandle */ | ||
| 88 | (DWORD) 0, /* DesiredAccess */ | ||
| 89 | inherit, /* InheritHandle */ | ||
| 90 | DUPLICATE_SAME_ACCESS)) /* Options */ | ||
| 91 | { | ||
| 92 | /* TODO: Translate GetLastError () into errno. */ | ||
| 93 | errno = EMFILE; | ||
| 94 | result = -1; | ||
| 95 | break; | ||
| 96 | } | ||
| 97 | duplicated_fd = _open_osfhandle ((intptr_t) new_handle, flags); | ||
| 98 | if (duplicated_fd < 0) | ||
| 99 | { | ||
| 100 | CloseHandle (new_handle); | ||
| 101 | errno = EMFILE; | ||
| 102 | result = -1; | ||
| 103 | break; | ||
| 104 | } | ||
| 105 | if (newfd <= duplicated_fd) | ||
| 106 | { | ||
| 107 | result = duplicated_fd; | ||
| 108 | break; | ||
| 109 | } | ||
| 110 | |||
| 111 | /* Set the bit duplicated_fd in fds_to_close[]. */ | ||
| 112 | index = (unsigned int) duplicated_fd / CHAR_BIT; | ||
| 113 | if (fds_to_close_bound <= index) | ||
| 114 | { | ||
| 115 | if (sizeof fds_to_close <= index) | ||
| 116 | /* Need to increase OPEN_MAX_MAX. */ | ||
| 117 | abort (); | ||
| 118 | memset (fds_to_close + fds_to_close_bound, '\0', | ||
| 119 | index + 1 - fds_to_close_bound); | ||
| 120 | fds_to_close_bound = index + 1; | ||
| 121 | } | ||
| 122 | fds_to_close[index] |= 1 << ((unsigned int) duplicated_fd % CHAR_BIT); | ||
| 123 | } | ||
| 124 | |||
| 125 | /* Close the previous fds that turned out to be too small. */ | ||
| 126 | { | ||
| 127 | int saved_errno = errno; | ||
| 128 | unsigned int duplicated_fd; | ||
| 129 | |||
| 130 | for (duplicated_fd = 0; | ||
| 131 | duplicated_fd < fds_to_close_bound * CHAR_BIT; | ||
| 132 | duplicated_fd++) | ||
| 133 | if ((fds_to_close[duplicated_fd / CHAR_BIT] | ||
| 134 | >> (duplicated_fd % CHAR_BIT)) | ||
| 135 | & 1) | ||
| 136 | close (duplicated_fd); | ||
| 137 | |||
| 138 | errno = saved_errno; | ||
| 139 | } | ||
| 140 | |||
| 141 | # if REPLACE_FCHDIR | ||
| 142 | if (0 <= result) | ||
| 143 | result = _gl_register_dup (oldfd, result); | ||
| 144 | # endif | ||
| 145 | return result; | ||
| 146 | } | ||
| 147 | #endif /* W32 */ | ||
| 148 | |||
| 149 | /* Perform the specified ACTION on the file descriptor FD, possibly | ||
| 150 | using the argument ARG further described below. This replacement | ||
| 151 | handles the following actions, and forwards all others on to the | ||
| 152 | native fcntl. An unrecognized ACTION returns -1 with errno set to | ||
| 153 | EINVAL. | ||
| 154 | |||
| 155 | F_DUPFD - duplicate FD, with int ARG being the minimum target fd. | ||
| 156 | If successful, return the duplicate, which will be inheritable; | ||
| 157 | otherwise return -1 and set errno. | ||
| 158 | |||
| 159 | F_DUPFD_CLOEXEC - duplicate FD, with int ARG being the minimum | ||
| 160 | target fd. If successful, return the duplicate, which will not be | ||
| 161 | inheritable; otherwise return -1 and set errno. | ||
| 162 | |||
| 163 | F_GETFD - ARG need not be present. If successful, return a | ||
| 164 | non-negative value containing the descriptor flags of FD (only | ||
| 165 | FD_CLOEXEC is portable, but other flags may be present); otherwise | ||
| 166 | return -1 and set errno. */ | ||
| 167 | |||
| 168 | int | ||
| 169 | rpl_fcntl (int fd, int action, /* arg */...) | ||
| 170 | { | ||
| 171 | va_list arg; | ||
| 172 | int result = -1; | ||
| 173 | va_start (arg, action); | ||
| 174 | switch (action) | ||
| 175 | { | ||
| 176 | |||
| 177 | #if !HAVE_FCNTL | ||
| 178 | case F_DUPFD: | ||
| 179 | { | ||
| 180 | int target = va_arg (arg, int); | ||
| 181 | result = dupfd (fd, target, 0); | ||
| 182 | break; | ||
| 183 | } | ||
| 184 | #elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR | ||
| 185 | case F_DUPFD: | ||
| 186 | { | ||
| 187 | int target = va_arg (arg, int); | ||
| 188 | /* Detect invalid target; needed for cygwin 1.5.x. */ | ||
| 189 | if (target < 0 || getdtablesize () <= target) | ||
| 190 | errno = EINVAL; | ||
| 191 | else | ||
| 192 | { | ||
| 193 | /* Haiku alpha 2 loses fd flags on original. */ | ||
| 194 | int flags = fcntl (fd, F_GETFD); | ||
| 195 | if (flags < 0) | ||
| 196 | { | ||
| 197 | result = -1; | ||
| 198 | break; | ||
| 199 | } | ||
| 200 | result = fcntl (fd, action, target); | ||
| 201 | if (0 <= result && fcntl (fd, F_SETFD, flags) == -1) | ||
| 202 | { | ||
| 203 | int saved_errno = errno; | ||
| 204 | close (result); | ||
| 205 | result = -1; | ||
| 206 | errno = saved_errno; | ||
| 207 | } | ||
| 208 | # if REPLACE_FCHDIR | ||
| 209 | if (0 <= result) | ||
| 210 | result = _gl_register_dup (fd, result); | ||
| 211 | # endif | ||
| 212 | } | ||
| 213 | break; | ||
| 214 | } /* F_DUPFD */ | ||
| 215 | #endif /* FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR */ | ||
| 216 | |||
| 217 | case F_DUPFD_CLOEXEC: | ||
| 218 | { | ||
| 219 | int target = va_arg (arg, int); | ||
| 220 | |||
| 221 | #if !HAVE_FCNTL | ||
| 222 | result = dupfd (fd, target, O_CLOEXEC); | ||
| 223 | break; | ||
| 224 | #else /* HAVE_FCNTL */ | ||
| 225 | /* Try the system call first, if the headers claim it exists | ||
| 226 | (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we | ||
| 227 | may be running with a glibc that has the macro but with an | ||
| 228 | older kernel that does not support it. Cache the | ||
| 229 | information on whether the system call really works, but | ||
| 230 | avoid caching failure if the corresponding F_DUPFD fails | ||
| 231 | for any reason. 0 = unknown, 1 = yes, -1 = no. */ | ||
| 232 | static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0; | ||
| 233 | if (0 <= have_dupfd_cloexec) | ||
| 234 | { | ||
| 235 | result = fcntl (fd, action, target); | ||
| 236 | if (0 <= result || errno != EINVAL) | ||
| 237 | { | ||
| 238 | have_dupfd_cloexec = 1; | ||
| 239 | # if REPLACE_FCHDIR | ||
| 240 | if (0 <= result) | ||
| 241 | result = _gl_register_dup (fd, result); | ||
| 242 | # endif | ||
| 243 | } | ||
| 244 | else | ||
| 245 | { | ||
| 246 | result = rpl_fcntl (fd, F_DUPFD, target); | ||
| 247 | if (result < 0) | ||
| 248 | break; | ||
| 249 | have_dupfd_cloexec = -1; | ||
| 250 | } | ||
| 251 | } | ||
| 252 | else | ||
| 253 | result = rpl_fcntl (fd, F_DUPFD, target); | ||
| 254 | if (0 <= result && have_dupfd_cloexec == -1) | ||
| 255 | { | ||
| 256 | int flags = fcntl (result, F_GETFD); | ||
| 257 | if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1) | ||
| 258 | { | ||
| 259 | int saved_errno = errno; | ||
| 260 | close (result); | ||
| 261 | errno = saved_errno; | ||
| 262 | result = -1; | ||
| 263 | } | ||
| 264 | } | ||
| 265 | break; | ||
| 266 | #endif /* HAVE_FCNTL */ | ||
| 267 | } /* F_DUPFD_CLOEXEC */ | ||
| 268 | |||
| 269 | #if !HAVE_FCNTL | ||
| 270 | case F_GETFD: | ||
| 271 | { | ||
| 272 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 273 | HANDLE handle = (HANDLE) _get_osfhandle (fd); | ||
| 274 | DWORD flags; | ||
| 275 | if (handle == INVALID_HANDLE_VALUE | ||
| 276 | || GetHandleInformation (handle, &flags) == 0) | ||
| 277 | errno = EBADF; | ||
| 278 | else | ||
| 279 | result = (flags & HANDLE_FLAG_INHERIT) ? 0 : FD_CLOEXEC; | ||
| 280 | # else /* !W32 */ | ||
| 281 | /* Use dup2 to reject invalid file descriptors. No way to | ||
| 282 | access this information, so punt. */ | ||
| 283 | if (0 <= dup2 (fd, fd)) | ||
| 284 | result = 0; | ||
| 285 | # endif /* !W32 */ | ||
| 286 | break; | ||
| 287 | } /* F_GETFD */ | ||
| 288 | #endif /* !HAVE_FCNTL */ | ||
| 289 | |||
| 290 | /* Implementing F_SETFD on mingw is not trivial - there is no | ||
| 291 | API for changing the O_NOINHERIT bit on an fd, and merely | ||
| 292 | changing the HANDLE_FLAG_INHERIT bit on the underlying handle | ||
| 293 | can lead to odd state. It may be possible by duplicating the | ||
| 294 | handle, using _open_osfhandle with the right flags, then | ||
| 295 | using dup2 to move the duplicate onto the original, but that | ||
| 296 | is not supported for now. */ | ||
| 297 | |||
| 298 | default: | ||
| 299 | { | ||
| 300 | #if HAVE_FCNTL | ||
| 301 | void *p = va_arg (arg, void *); | ||
| 302 | result = fcntl (fd, action, p); | ||
| 303 | #else | ||
| 304 | errno = EINVAL; | ||
| 305 | #endif | ||
| 306 | break; | ||
| 307 | } | ||
| 308 | } | ||
| 309 | va_end (arg); | ||
| 310 | return result; | ||
| 311 | } | ||
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h index 1e45a65a213..99f75e60fd4 100644 --- a/lib/fcntl.in.h +++ b/lib/fcntl.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Like <fcntl.h>, but with non-working flags defined to 0. | 1 | /* Like <fcntl.h>, but with non-working flags defined to 0. |
| 2 | 2 | ||
| 3 | Copyright (C) 2006-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2006-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/fdatasync.c b/lib/fdatasync.c new file mode 100644 index 00000000000..688543f8457 --- /dev/null +++ b/lib/fdatasync.c | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /* Emulate fdatasync on platforms that lack it. | ||
| 2 | |||
| 3 | Copyright (C) 2011-2014 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This library is free software; you can redistribute it and/or | ||
| 6 | modify it under the terms of the GNU General Public | ||
| 7 | License as published by the Free Software Foundation; either | ||
| 8 | version 3 of the License, or (at your option) any later version. | ||
| 9 | |||
| 10 | This library 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 GNU | ||
| 13 | 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 | #include <unistd.h> | ||
| 20 | |||
| 21 | int | ||
| 22 | fdatasync (int fd) | ||
| 23 | { | ||
| 24 | /* This does more work than strictly necessary, but is the best we | ||
| 25 | can do portably. */ | ||
| 26 | return fsync (fd); | ||
| 27 | } | ||
diff --git a/lib/fdopendir.c b/lib/fdopendir.c index 63e06b92ae8..b6c94a09901 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* provide a replacement fdopendir function | 1 | /* provide a replacement fdopendir function |
| 2 | Copyright (C) 2004-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2004-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c new file mode 100644 index 00000000000..5104a41eb6f --- /dev/null +++ b/lib/file-has-acl.c | |||
| @@ -0,0 +1,919 @@ | |||
| 1 | /* Test whether a file has a nontrivial access control list. | ||
| 2 | |||
| 3 | Copyright (C) 2002-2003, 2005-2014 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 | Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible. */ | ||
| 19 | |||
| 20 | /* Without this pragma, gcc 4.7.0 20120126 may suggest that the | ||
| 21 | file_has_acl function might be candidate for attribute 'const' */ | ||
| 22 | #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ | ||
| 23 | # pragma GCC diagnostic ignored "-Wsuggest-attribute=const" | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #include <config.h> | ||
| 27 | |||
| 28 | #include "acl.h" | ||
| 29 | |||
| 30 | #include "acl-internal.h" | ||
| 31 | |||
| 32 | |||
| 33 | #if USE_ACL && HAVE_ACL_GET_FILE | ||
| 34 | |||
| 35 | # if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */ | ||
| 36 | |||
| 37 | /* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED. | ||
| 38 | Return 1 if the given ACL is non-trivial. | ||
| 39 | Return 0 if it is trivial. */ | ||
| 40 | int | ||
| 41 | acl_extended_nontrivial (acl_t acl) | ||
| 42 | { | ||
| 43 | /* acl is non-trivial if it is non-empty. */ | ||
| 44 | return (acl_entries (acl) > 0); | ||
| 45 | } | ||
| 46 | |||
| 47 | # else /* Linux, FreeBSD, IRIX, Tru64 */ | ||
| 48 | |||
| 49 | /* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS. | ||
| 50 | Return 1 if the given ACL is non-trivial. | ||
| 51 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. | ||
| 52 | Return -1 and set errno upon failure to determine it. */ | ||
| 53 | int | ||
| 54 | acl_access_nontrivial (acl_t acl) | ||
| 55 | { | ||
| 56 | /* acl is non-trivial if it has some entries other than for "user::", | ||
| 57 | "group::", and "other::". Normally these three should be present | ||
| 58 | at least, allowing us to write | ||
| 59 | return (3 < acl_entries (acl)); | ||
| 60 | but the following code is more robust. */ | ||
| 61 | # if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD */ | ||
| 62 | |||
| 63 | acl_entry_t ace; | ||
| 64 | int got_one; | ||
| 65 | |||
| 66 | for (got_one = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace); | ||
| 67 | got_one > 0; | ||
| 68 | got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace)) | ||
| 69 | { | ||
| 70 | acl_tag_t tag; | ||
| 71 | if (acl_get_tag_type (ace, &tag) < 0) | ||
| 72 | return -1; | ||
| 73 | if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER)) | ||
| 74 | return 1; | ||
| 75 | } | ||
| 76 | return got_one; | ||
| 77 | |||
| 78 | # elif HAVE_ACL_TO_SHORT_TEXT /* IRIX */ | ||
| 79 | /* Don't use acl_get_entry: it is undocumented. */ | ||
| 80 | |||
| 81 | int count = acl->acl_cnt; | ||
| 82 | int i; | ||
| 83 | |||
| 84 | for (i = 0; i < count; i++) | ||
| 85 | { | ||
| 86 | acl_entry_t ace = &acl->acl_entry[i]; | ||
| 87 | acl_tag_t tag = ace->ae_tag; | ||
| 88 | |||
| 89 | if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ | ||
| 90 | || tag == ACL_OTHER_OBJ)) | ||
| 91 | return 1; | ||
| 92 | } | ||
| 93 | return 0; | ||
| 94 | |||
| 95 | # elif HAVE_ACL_FREE_TEXT /* Tru64 */ | ||
| 96 | /* Don't use acl_get_entry: it takes only one argument and does not work. */ | ||
| 97 | |||
| 98 | int count = acl->acl_num; | ||
| 99 | acl_entry_t ace; | ||
| 100 | |||
| 101 | for (ace = acl->acl_first; count > 0; ace = ace->next, count--) | ||
| 102 | { | ||
| 103 | acl_tag_t tag; | ||
| 104 | acl_perm_t perm; | ||
| 105 | |||
| 106 | tag = ace->entry->acl_type; | ||
| 107 | if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER)) | ||
| 108 | return 1; | ||
| 109 | |||
| 110 | perm = ace->entry->acl_perm; | ||
| 111 | /* On Tru64, perm can also contain non-standard bits such as | ||
| 112 | PERM_INSERT, PERM_DELETE, PERM_MODIFY, PERM_LOOKUP, ... */ | ||
| 113 | if ((perm & ~(ACL_READ | ACL_WRITE | ACL_EXECUTE)) != 0) | ||
| 114 | return 1; | ||
| 115 | } | ||
| 116 | return 0; | ||
| 117 | |||
| 118 | # else | ||
| 119 | |||
| 120 | errno = ENOSYS; | ||
| 121 | return -1; | ||
| 122 | # endif | ||
| 123 | } | ||
| 124 | |||
| 125 | # endif | ||
| 126 | |||
| 127 | |||
| 128 | #elif USE_ACL && HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ | ||
| 129 | |||
| 130 | /* Test an ACL retrieved with GETACL. | ||
| 131 | Return 1 if the given ACL, consisting of COUNT entries, is non-trivial. | ||
| 132 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 133 | int | ||
| 134 | acl_nontrivial (int count, aclent_t *entries) | ||
| 135 | { | ||
| 136 | int i; | ||
| 137 | |||
| 138 | for (i = 0; i < count; i++) | ||
| 139 | { | ||
| 140 | aclent_t *ace = &entries[i]; | ||
| 141 | |||
| 142 | /* Note: If ace->a_type = USER_OBJ, ace->a_id is the st_uid from stat(). | ||
| 143 | If ace->a_type = GROUP_OBJ, ace->a_id is the st_gid from stat(). | ||
| 144 | We don't need to check ace->a_id in these cases. */ | ||
| 145 | if (!(ace->a_type == USER_OBJ | ||
| 146 | || ace->a_type == GROUP_OBJ | ||
| 147 | || ace->a_type == OTHER_OBJ | ||
| 148 | /* Note: Cygwin does not return a CLASS_OBJ ("mask:") entry | ||
| 149 | sometimes. */ | ||
| 150 | || ace->a_type == CLASS_OBJ)) | ||
| 151 | return 1; | ||
| 152 | } | ||
| 153 | return 0; | ||
| 154 | } | ||
| 155 | |||
| 156 | # ifdef ACE_GETACL | ||
| 157 | |||
| 158 | /* A shortcut for a bitmask. */ | ||
| 159 | # define NEW_ACE_WRITEA_DATA (NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA) | ||
| 160 | |||
| 161 | /* Test an ACL retrieved with ACE_GETACL. | ||
| 162 | Return 1 if the given ACL, consisting of COUNT entries, is non-trivial. | ||
| 163 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 164 | int | ||
| 165 | acl_ace_nontrivial (int count, ace_t *entries) | ||
| 166 | { | ||
| 167 | int i; | ||
| 168 | |||
| 169 | /* The flags in the ace_t structure changed in a binary incompatible way | ||
| 170 | when ACL_NO_TRIVIAL etc. were introduced in <sys/acl.h> version 1.15. | ||
| 171 | How to distinguish the two conventions at runtime? | ||
| 172 | In the old convention, usually three ACEs have a_flags = ACE_OWNER / | ||
| 173 | ACE_GROUP / ACE_OTHER, in the range 0x0100..0x0400. In the new | ||
| 174 | convention, these values are not used. */ | ||
| 175 | int old_convention = 0; | ||
| 176 | |||
| 177 | for (i = 0; i < count; i++) | ||
| 178 | if (entries[i].a_flags & (OLD_ACE_OWNER | OLD_ACE_GROUP | OLD_ACE_OTHER)) | ||
| 179 | { | ||
| 180 | old_convention = 1; | ||
| 181 | break; | ||
| 182 | } | ||
| 183 | |||
| 184 | if (old_convention) | ||
| 185 | /* Running on Solaris 10. */ | ||
| 186 | for (i = 0; i < count; i++) | ||
| 187 | { | ||
| 188 | ace_t *ace = &entries[i]; | ||
| 189 | |||
| 190 | /* Note: | ||
| 191 | If ace->a_flags = ACE_OWNER, ace->a_who is the st_uid from stat(). | ||
| 192 | If ace->a_flags = ACE_GROUP, ace->a_who is the st_gid from stat(). | ||
| 193 | We don't need to check ace->a_who in these cases. */ | ||
| 194 | if (!(ace->a_type == OLD_ALLOW | ||
| 195 | && (ace->a_flags == OLD_ACE_OWNER | ||
| 196 | || ace->a_flags == OLD_ACE_GROUP | ||
| 197 | || ace->a_flags == OLD_ACE_OTHER))) | ||
| 198 | return 1; | ||
| 199 | } | ||
| 200 | else | ||
| 201 | { | ||
| 202 | /* Running on Solaris 10 (newer version) or Solaris 11. */ | ||
| 203 | unsigned int access_masks[6] = | ||
| 204 | { | ||
| 205 | 0, /* owner@ deny */ | ||
| 206 | 0, /* owner@ allow */ | ||
| 207 | 0, /* group@ deny */ | ||
| 208 | 0, /* group@ allow */ | ||
| 209 | 0, /* everyone@ deny */ | ||
| 210 | 0 /* everyone@ allow */ | ||
| 211 | }; | ||
| 212 | |||
| 213 | for (i = 0; i < count; i++) | ||
| 214 | { | ||
| 215 | ace_t *ace = &entries[i]; | ||
| 216 | unsigned int index1; | ||
| 217 | unsigned int index2; | ||
| 218 | |||
| 219 | if (ace->a_type == NEW_ACE_ACCESS_ALLOWED_ACE_TYPE) | ||
| 220 | index1 = 1; | ||
| 221 | else if (ace->a_type == NEW_ACE_ACCESS_DENIED_ACE_TYPE) | ||
| 222 | index1 = 0; | ||
| 223 | else | ||
| 224 | return 1; | ||
| 225 | |||
| 226 | if (ace->a_flags == NEW_ACE_OWNER) | ||
| 227 | index2 = 0; | ||
| 228 | else if (ace->a_flags == (NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP)) | ||
| 229 | index2 = 2; | ||
| 230 | else if (ace->a_flags == NEW_ACE_EVERYONE) | ||
| 231 | index2 = 4; | ||
| 232 | else | ||
| 233 | return 1; | ||
| 234 | |||
| 235 | access_masks[index1 + index2] |= ace->a_access_mask; | ||
| 236 | } | ||
| 237 | |||
| 238 | /* The same bit shouldn't be both allowed and denied. */ | ||
| 239 | if (access_masks[0] & access_masks[1]) | ||
| 240 | return 1; | ||
| 241 | if (access_masks[2] & access_masks[3]) | ||
| 242 | return 1; | ||
| 243 | if (access_masks[4] & access_masks[5]) | ||
| 244 | return 1; | ||
| 245 | |||
| 246 | /* Check minimum masks. */ | ||
| 247 | if ((NEW_ACE_WRITE_NAMED_ATTRS | ||
| 248 | | NEW_ACE_WRITE_ATTRIBUTES | ||
| 249 | | NEW_ACE_WRITE_ACL | ||
| 250 | | NEW_ACE_WRITE_OWNER) | ||
| 251 | & ~ access_masks[1]) | ||
| 252 | return 1; | ||
| 253 | access_masks[1] &= ~(NEW_ACE_WRITE_NAMED_ATTRS | ||
| 254 | | NEW_ACE_WRITE_ATTRIBUTES | ||
| 255 | | NEW_ACE_WRITE_ACL | ||
| 256 | | NEW_ACE_WRITE_OWNER); | ||
| 257 | if ((NEW_ACE_READ_NAMED_ATTRS | ||
| 258 | | NEW_ACE_READ_ATTRIBUTES | ||
| 259 | | NEW_ACE_READ_ACL | ||
| 260 | | NEW_ACE_SYNCHRONIZE) | ||
| 261 | & ~ access_masks[5]) | ||
| 262 | return 1; | ||
| 263 | access_masks[5] &= ~(NEW_ACE_READ_NAMED_ATTRS | ||
| 264 | | NEW_ACE_READ_ATTRIBUTES | ||
| 265 | | NEW_ACE_READ_ACL | ||
| 266 | | NEW_ACE_SYNCHRONIZE); | ||
| 267 | |||
| 268 | /* Check the allowed or denied bits. */ | ||
| 269 | switch ((access_masks[0] | access_masks[1]) | ||
| 270 | & ~(NEW_ACE_READ_NAMED_ATTRS | ||
| 271 | | NEW_ACE_READ_ATTRIBUTES | ||
| 272 | | NEW_ACE_READ_ACL | ||
| 273 | | NEW_ACE_SYNCHRONIZE)) | ||
| 274 | { | ||
| 275 | case 0: | ||
| 276 | case NEW_ACE_READ_DATA: | ||
| 277 | case NEW_ACE_WRITEA_DATA: | ||
| 278 | case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA: | ||
| 279 | case NEW_ACE_EXECUTE: | ||
| 280 | case NEW_ACE_READ_DATA | NEW_ACE_EXECUTE: | ||
| 281 | case NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE: | ||
| 282 | case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE: | ||
| 283 | break; | ||
| 284 | default: | ||
| 285 | return 1; | ||
| 286 | } | ||
| 287 | switch ((access_masks[2] | access_masks[3]) | ||
| 288 | & ~(NEW_ACE_READ_NAMED_ATTRS | ||
| 289 | | NEW_ACE_READ_ATTRIBUTES | ||
| 290 | | NEW_ACE_READ_ACL | ||
| 291 | | NEW_ACE_SYNCHRONIZE)) | ||
| 292 | { | ||
| 293 | case 0: | ||
| 294 | case NEW_ACE_READ_DATA: | ||
| 295 | case NEW_ACE_WRITEA_DATA: | ||
| 296 | case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA: | ||
| 297 | case NEW_ACE_EXECUTE: | ||
| 298 | case NEW_ACE_READ_DATA | NEW_ACE_EXECUTE: | ||
| 299 | case NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE: | ||
| 300 | case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE: | ||
| 301 | break; | ||
| 302 | default: | ||
| 303 | return 1; | ||
| 304 | } | ||
| 305 | switch ((access_masks[4] | access_masks[5]) | ||
| 306 | & ~(NEW_ACE_WRITE_NAMED_ATTRS | ||
| 307 | | NEW_ACE_WRITE_ATTRIBUTES | ||
| 308 | | NEW_ACE_WRITE_ACL | ||
| 309 | | NEW_ACE_WRITE_OWNER)) | ||
| 310 | { | ||
| 311 | case 0: | ||
| 312 | case NEW_ACE_READ_DATA: | ||
| 313 | case NEW_ACE_WRITEA_DATA: | ||
| 314 | case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA: | ||
| 315 | case NEW_ACE_EXECUTE: | ||
| 316 | case NEW_ACE_READ_DATA | NEW_ACE_EXECUTE: | ||
| 317 | case NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE: | ||
| 318 | case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE: | ||
| 319 | break; | ||
| 320 | default: | ||
| 321 | return 1; | ||
| 322 | } | ||
| 323 | |||
| 324 | /* Check that the NEW_ACE_WRITE_DATA and NEW_ACE_APPEND_DATA bits are | ||
| 325 | either both allowed or both denied. */ | ||
| 326 | if (((access_masks[0] & NEW_ACE_WRITE_DATA) != 0) | ||
| 327 | != ((access_masks[0] & NEW_ACE_APPEND_DATA) != 0)) | ||
| 328 | return 1; | ||
| 329 | if (((access_masks[2] & NEW_ACE_WRITE_DATA) != 0) | ||
| 330 | != ((access_masks[2] & NEW_ACE_APPEND_DATA) != 0)) | ||
| 331 | return 1; | ||
| 332 | if (((access_masks[4] & NEW_ACE_WRITE_DATA) != 0) | ||
| 333 | != ((access_masks[4] & NEW_ACE_APPEND_DATA) != 0)) | ||
| 334 | return 1; | ||
| 335 | } | ||
| 336 | |||
| 337 | return 0; | ||
| 338 | } | ||
| 339 | |||
| 340 | # endif | ||
| 341 | |||
| 342 | #elif USE_ACL && HAVE_GETACL /* HP-UX */ | ||
| 343 | |||
| 344 | /* Return 1 if the given ACL is non-trivial. | ||
| 345 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 346 | int | ||
| 347 | acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb) | ||
| 348 | { | ||
| 349 | int i; | ||
| 350 | |||
| 351 | for (i = 0; i < count; i++) | ||
| 352 | { | ||
| 353 | struct acl_entry *ace = &entries[i]; | ||
| 354 | |||
| 355 | if (!((ace->uid == sb->st_uid && ace->gid == ACL_NSGROUP) | ||
| 356 | || (ace->uid == ACL_NSUSER && ace->gid == sb->st_gid) | ||
| 357 | || (ace->uid == ACL_NSUSER && ace->gid == ACL_NSGROUP))) | ||
| 358 | return 1; | ||
| 359 | } | ||
| 360 | return 0; | ||
| 361 | } | ||
| 362 | |||
| 363 | # if HAVE_ACLV_H /* HP-UX >= 11.11 */ | ||
| 364 | |||
| 365 | /* Return 1 if the given ACL is non-trivial. | ||
| 366 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 367 | int | ||
| 368 | aclv_nontrivial (int count, struct acl *entries) | ||
| 369 | { | ||
| 370 | int i; | ||
| 371 | |||
| 372 | for (i = 0; i < count; i++) | ||
| 373 | { | ||
| 374 | struct acl *ace = &entries[i]; | ||
| 375 | |||
| 376 | /* Note: If ace->a_type = USER_OBJ, ace->a_id is the st_uid from stat(). | ||
| 377 | If ace->a_type = GROUP_OBJ, ace->a_id is the st_gid from stat(). | ||
| 378 | We don't need to check ace->a_id in these cases. */ | ||
| 379 | if (!(ace->a_type == USER_OBJ /* no need to check ace->a_id here */ | ||
| 380 | || ace->a_type == GROUP_OBJ /* no need to check ace->a_id here */ | ||
| 381 | || ace->a_type == CLASS_OBJ | ||
| 382 | || ace->a_type == OTHER_OBJ)) | ||
| 383 | return 1; | ||
| 384 | } | ||
| 385 | return 0; | ||
| 386 | } | ||
| 387 | |||
| 388 | # endif | ||
| 389 | |||
| 390 | #elif USE_ACL && (HAVE_ACLX_GET || HAVE_STATACL) /* AIX */ | ||
| 391 | |||
| 392 | /* Return 1 if the given ACL is non-trivial. | ||
| 393 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 394 | int | ||
| 395 | acl_nontrivial (struct acl *a) | ||
| 396 | { | ||
| 397 | /* The normal way to iterate through an ACL is like this: | ||
| 398 | struct acl_entry *ace; | ||
| 399 | for (ace = a->acl_ext; ace != acl_last (a); ace = acl_nxt (ace)) | ||
| 400 | { | ||
| 401 | struct ace_id *aei; | ||
| 402 | switch (ace->ace_type) | ||
| 403 | { | ||
| 404 | case ACC_PERMIT: | ||
| 405 | case ACC_DENY: | ||
| 406 | case ACC_SPECIFY: | ||
| 407 | ...; | ||
| 408 | } | ||
| 409 | for (aei = ace->ace_id; aei != id_last (ace); aei = id_nxt (aei)) | ||
| 410 | ... | ||
| 411 | } | ||
| 412 | */ | ||
| 413 | return (acl_last (a) != a->acl_ext ? 1 : 0); | ||
| 414 | } | ||
| 415 | |||
| 416 | # if HAVE_ACLX_GET && defined ACL_AIX_WIP /* newer AIX */ | ||
| 417 | |||
| 418 | /* Return 1 if the given ACL is non-trivial. | ||
| 419 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 420 | int | ||
| 421 | acl_nfs4_nontrivial (nfs4_acl_int_t *a) | ||
| 422 | { | ||
| 423 | # if 1 /* let's try this first */ | ||
| 424 | return (a->aclEntryN > 0 ? 1 : 0); | ||
| 425 | # else | ||
| 426 | int count = a->aclEntryN; | ||
| 427 | int i; | ||
| 428 | |||
| 429 | for (i = 0; i < count; i++) | ||
| 430 | { | ||
| 431 | nfs4_ace_int_t *ace = &a->aclEntry[i]; | ||
| 432 | |||
| 433 | if (!((ace->flags & ACE4_ID_SPECIAL) != 0 | ||
| 434 | && (ace->aceWho.special_whoid == ACE4_WHO_OWNER | ||
| 435 | || ace->aceWho.special_whoid == ACE4_WHO_GROUP | ||
| 436 | || ace->aceWho.special_whoid == ACE4_WHO_EVERYONE) | ||
| 437 | && ace->aceType == ACE4_ACCESS_ALLOWED_ACE_TYPE | ||
| 438 | && ace->aceFlags == 0 | ||
| 439 | && (ace->aceMask & ~(ACE4_READ_DATA | ACE4_LIST_DIRECTORY | ||
| 440 | | ACE4_WRITE_DATA | ACE4_ADD_FILE | ||
| 441 | | ACE4_EXECUTE)) == 0)) | ||
| 442 | return 1; | ||
| 443 | } | ||
| 444 | return 0; | ||
| 445 | # endif | ||
| 446 | } | ||
| 447 | |||
| 448 | # endif | ||
| 449 | |||
| 450 | #elif USE_ACL && HAVE_ACLSORT /* NonStop Kernel */ | ||
| 451 | |||
| 452 | /* Test an ACL retrieved with ACL_GET. | ||
| 453 | Return 1 if the given ACL, consisting of COUNT entries, is non-trivial. | ||
| 454 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 455 | int | ||
| 456 | acl_nontrivial (int count, struct acl *entries) | ||
| 457 | { | ||
| 458 | int i; | ||
| 459 | |||
| 460 | for (i = 0; i < count; i++) | ||
| 461 | { | ||
| 462 | struct acl *ace = &entries[i]; | ||
| 463 | |||
| 464 | /* Note: If ace->a_type = USER_OBJ, ace->a_id is the st_uid from stat(). | ||
| 465 | If ace->a_type = GROUP_OBJ, ace->a_id is the st_gid from stat(). | ||
| 466 | We don't need to check ace->a_id in these cases. */ | ||
| 467 | if (!(ace->a_type == USER_OBJ /* no need to check ace->a_id here */ | ||
| 468 | || ace->a_type == GROUP_OBJ /* no need to check ace->a_id here */ | ||
| 469 | || ace->a_type == CLASS_OBJ | ||
| 470 | || ace->a_type == OTHER_OBJ)) | ||
| 471 | return 1; | ||
| 472 | } | ||
| 473 | return 0; | ||
| 474 | } | ||
| 475 | |||
| 476 | #endif | ||
| 477 | |||
| 478 | |||
| 479 | /* Return 1 if NAME has a nontrivial access control list, 0 if NAME | ||
| 480 | only has no or a base access control list, and -1 (setting errno) | ||
| 481 | on error. SB must be set to the stat buffer of NAME, obtained | ||
| 482 | through stat() or lstat(). */ | ||
| 483 | |||
| 484 | int | ||
| 485 | file_has_acl (char const *name, struct stat const *sb) | ||
| 486 | { | ||
| 487 | #if USE_ACL | ||
| 488 | if (! S_ISLNK (sb->st_mode)) | ||
| 489 | { | ||
| 490 | # if HAVE_ACL_GET_FILE | ||
| 491 | |||
| 492 | /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ | ||
| 493 | /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ | ||
| 494 | int ret; | ||
| 495 | |||
| 496 | if (HAVE_ACL_EXTENDED_FILE) /* Linux */ | ||
| 497 | { | ||
| 498 | /* On Linux, acl_extended_file is an optimized function: It only | ||
| 499 | makes two calls to getxattr(), one for ACL_TYPE_ACCESS, one for | ||
| 500 | ACL_TYPE_DEFAULT. */ | ||
| 501 | ret = acl_extended_file (name); | ||
| 502 | } | ||
| 503 | else /* FreeBSD, Mac OS X, IRIX, Tru64 */ | ||
| 504 | { | ||
| 505 | # if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */ | ||
| 506 | /* On Mac OS X, acl_get_file (name, ACL_TYPE_ACCESS) | ||
| 507 | and acl_get_file (name, ACL_TYPE_DEFAULT) | ||
| 508 | always return NULL / EINVAL. There is no point in making | ||
| 509 | these two useless calls. The real ACL is retrieved through | ||
| 510 | acl_get_file (name, ACL_TYPE_EXTENDED). */ | ||
| 511 | acl_t acl = acl_get_file (name, ACL_TYPE_EXTENDED); | ||
| 512 | if (acl) | ||
| 513 | { | ||
| 514 | ret = acl_extended_nontrivial (acl); | ||
| 515 | acl_free (acl); | ||
| 516 | } | ||
| 517 | else | ||
| 518 | ret = -1; | ||
| 519 | # else /* FreeBSD, IRIX, Tru64 */ | ||
| 520 | acl_t acl = acl_get_file (name, ACL_TYPE_ACCESS); | ||
| 521 | if (acl) | ||
| 522 | { | ||
| 523 | int saved_errno; | ||
| 524 | |||
| 525 | ret = acl_access_nontrivial (acl); | ||
| 526 | saved_errno = errno; | ||
| 527 | acl_free (acl); | ||
| 528 | errno = saved_errno; | ||
| 529 | # if HAVE_ACL_FREE_TEXT /* Tru64 */ | ||
| 530 | /* On OSF/1, acl_get_file (name, ACL_TYPE_DEFAULT) always | ||
| 531 | returns NULL with errno not set. There is no point in | ||
| 532 | making this call. */ | ||
| 533 | # else /* FreeBSD, IRIX */ | ||
| 534 | /* On Linux, FreeBSD, IRIX, acl_get_file (name, ACL_TYPE_ACCESS) | ||
| 535 | and acl_get_file (name, ACL_TYPE_DEFAULT) on a directory | ||
| 536 | either both succeed or both fail; it depends on the | ||
| 537 | file system. Therefore there is no point in making the second | ||
| 538 | call if the first one already failed. */ | ||
| 539 | if (ret == 0 && S_ISDIR (sb->st_mode)) | ||
| 540 | { | ||
| 541 | acl = acl_get_file (name, ACL_TYPE_DEFAULT); | ||
| 542 | if (acl) | ||
| 543 | { | ||
| 544 | ret = (0 < acl_entries (acl)); | ||
| 545 | acl_free (acl); | ||
| 546 | } | ||
| 547 | else | ||
| 548 | ret = -1; | ||
| 549 | } | ||
| 550 | # endif | ||
| 551 | } | ||
| 552 | else | ||
| 553 | ret = -1; | ||
| 554 | # endif | ||
| 555 | } | ||
| 556 | if (ret < 0) | ||
| 557 | return - acl_errno_valid (errno); | ||
| 558 | return ret; | ||
| 559 | |||
| 560 | # elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ | ||
| 561 | |||
| 562 | # if defined ACL_NO_TRIVIAL | ||
| 563 | |||
| 564 | /* Solaris 10 (newer version), which has additional API declared in | ||
| 565 | <sys/acl.h> (acl_t) and implemented in libsec (acl_set, acl_trivial, | ||
| 566 | acl_fromtext, ...). */ | ||
| 567 | return acl_trivial (name); | ||
| 568 | |||
| 569 | # else /* Solaris, Cygwin, general case */ | ||
| 570 | |||
| 571 | /* Solaris 2.5 through Solaris 10, Cygwin, and contemporaneous versions | ||
| 572 | of Unixware. The acl() call returns the access and default ACL both | ||
| 573 | at once. */ | ||
| 574 | { | ||
| 575 | /* Initially, try to read the entries into a stack-allocated buffer. | ||
| 576 | Use malloc if it does not fit. */ | ||
| 577 | enum | ||
| 578 | { | ||
| 579 | alloc_init = 4000 / sizeof (aclent_t), /* >= 3 */ | ||
| 580 | alloc_max = MIN (INT_MAX, SIZE_MAX / sizeof (aclent_t)) | ||
| 581 | }; | ||
| 582 | aclent_t buf[alloc_init]; | ||
| 583 | size_t alloc = alloc_init; | ||
| 584 | aclent_t *entries = buf; | ||
| 585 | aclent_t *malloced = NULL; | ||
| 586 | int count; | ||
| 587 | |||
| 588 | for (;;) | ||
| 589 | { | ||
| 590 | count = acl (name, GETACL, alloc, entries); | ||
| 591 | if (count < 0 && errno == ENOSPC) | ||
| 592 | { | ||
| 593 | /* Increase the size of the buffer. */ | ||
| 594 | free (malloced); | ||
| 595 | if (alloc > alloc_max / 2) | ||
| 596 | { | ||
| 597 | errno = ENOMEM; | ||
| 598 | return -1; | ||
| 599 | } | ||
| 600 | alloc = 2 * alloc; /* <= alloc_max */ | ||
| 601 | entries = malloced = | ||
| 602 | (aclent_t *) malloc (alloc * sizeof (aclent_t)); | ||
| 603 | if (entries == NULL) | ||
| 604 | { | ||
| 605 | errno = ENOMEM; | ||
| 606 | return -1; | ||
| 607 | } | ||
| 608 | continue; | ||
| 609 | } | ||
| 610 | break; | ||
| 611 | } | ||
| 612 | if (count < 0) | ||
| 613 | { | ||
| 614 | if (errno == ENOSYS || errno == ENOTSUP) | ||
| 615 | ; | ||
| 616 | else | ||
| 617 | { | ||
| 618 | int saved_errno = errno; | ||
| 619 | free (malloced); | ||
| 620 | errno = saved_errno; | ||
| 621 | return -1; | ||
| 622 | } | ||
| 623 | } | ||
| 624 | else if (count == 0) | ||
| 625 | ; | ||
| 626 | else | ||
| 627 | { | ||
| 628 | /* Don't use MIN_ACL_ENTRIES: It's set to 4 on Cygwin, but Cygwin | ||
| 629 | returns only 3 entries for files with no ACL. But this is safe: | ||
| 630 | If there are more than 4 entries, there cannot be only the | ||
| 631 | "user::", "group::", "other:", and "mask:" entries. */ | ||
| 632 | if (count > 4) | ||
| 633 | { | ||
| 634 | free (malloced); | ||
| 635 | return 1; | ||
| 636 | } | ||
| 637 | |||
| 638 | if (acl_nontrivial (count, entries)) | ||
| 639 | { | ||
| 640 | free (malloced); | ||
| 641 | return 1; | ||
| 642 | } | ||
| 643 | } | ||
| 644 | free (malloced); | ||
| 645 | } | ||
| 646 | |||
| 647 | # ifdef ACE_GETACL | ||
| 648 | /* Solaris also has a different variant of ACLs, used in ZFS and NFSv4 | ||
| 649 | file systems (whereas the other ones are used in UFS file systems). */ | ||
| 650 | { | ||
| 651 | /* Initially, try to read the entries into a stack-allocated buffer. | ||
| 652 | Use malloc if it does not fit. */ | ||
| 653 | enum | ||
| 654 | { | ||
| 655 | alloc_init = 4000 / sizeof (ace_t), /* >= 3 */ | ||
| 656 | alloc_max = MIN (INT_MAX, SIZE_MAX / sizeof (ace_t)) | ||
| 657 | }; | ||
| 658 | ace_t buf[alloc_init]; | ||
| 659 | size_t alloc = alloc_init; | ||
| 660 | ace_t *entries = buf; | ||
| 661 | ace_t *malloced = NULL; | ||
| 662 | int count; | ||
| 663 | |||
| 664 | for (;;) | ||
| 665 | { | ||
| 666 | count = acl (name, ACE_GETACL, alloc, entries); | ||
| 667 | if (count < 0 && errno == ENOSPC) | ||
| 668 | { | ||
| 669 | /* Increase the size of the buffer. */ | ||
| 670 | free (malloced); | ||
| 671 | if (alloc > alloc_max / 2) | ||
| 672 | { | ||
| 673 | errno = ENOMEM; | ||
| 674 | return -1; | ||
| 675 | } | ||
| 676 | alloc = 2 * alloc; /* <= alloc_max */ | ||
| 677 | entries = malloced = (ace_t *) malloc (alloc * sizeof (ace_t)); | ||
| 678 | if (entries == NULL) | ||
| 679 | { | ||
| 680 | errno = ENOMEM; | ||
| 681 | return -1; | ||
| 682 | } | ||
| 683 | continue; | ||
| 684 | } | ||
| 685 | break; | ||
| 686 | } | ||
| 687 | if (count < 0) | ||
| 688 | { | ||
| 689 | if (errno == ENOSYS || errno == EINVAL) | ||
| 690 | ; | ||
| 691 | else | ||
| 692 | { | ||
| 693 | int saved_errno = errno; | ||
| 694 | free (malloced); | ||
| 695 | errno = saved_errno; | ||
| 696 | return -1; | ||
| 697 | } | ||
| 698 | } | ||
| 699 | else if (count == 0) | ||
| 700 | ; | ||
| 701 | else | ||
| 702 | { | ||
| 703 | /* In the old (original Solaris 10) convention: | ||
| 704 | If there are more than 3 entries, there cannot be only the | ||
| 705 | ACE_OWNER, ACE_GROUP, ACE_OTHER entries. | ||
| 706 | In the newer Solaris 10 and Solaris 11 convention: | ||
| 707 | If there are more than 6 entries, there cannot be only the | ||
| 708 | ACE_OWNER, ACE_GROUP, ACE_EVERYONE entries, each once with | ||
| 709 | NEW_ACE_ACCESS_ALLOWED_ACE_TYPE and once with | ||
| 710 | NEW_ACE_ACCESS_DENIED_ACE_TYPE. */ | ||
| 711 | if (count > 6) | ||
| 712 | { | ||
| 713 | free (malloced); | ||
| 714 | return 1; | ||
| 715 | } | ||
| 716 | |||
| 717 | if (acl_ace_nontrivial (count, entries)) | ||
| 718 | { | ||
| 719 | free (malloced); | ||
| 720 | return 1; | ||
| 721 | } | ||
| 722 | } | ||
| 723 | free (malloced); | ||
| 724 | } | ||
| 725 | # endif | ||
| 726 | |||
| 727 | return 0; | ||
| 728 | # endif | ||
| 729 | |||
| 730 | # elif HAVE_GETACL /* HP-UX */ | ||
| 731 | |||
| 732 | { | ||
| 733 | struct acl_entry entries[NACLENTRIES]; | ||
| 734 | int count; | ||
| 735 | |||
| 736 | count = getacl (name, NACLENTRIES, entries); | ||
| 737 | |||
| 738 | if (count < 0) | ||
| 739 | { | ||
| 740 | /* ENOSYS is seen on newer HP-UX versions. | ||
| 741 | EOPNOTSUPP is typically seen on NFS mounts. | ||
| 742 | ENOTSUP was seen on Quantum StorNext file systems (cvfs). */ | ||
| 743 | if (errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP) | ||
| 744 | ; | ||
| 745 | else | ||
| 746 | return -1; | ||
| 747 | } | ||
| 748 | else if (count == 0) | ||
| 749 | return 0; | ||
| 750 | else /* count > 0 */ | ||
| 751 | { | ||
| 752 | if (count > NACLENTRIES) | ||
| 753 | /* If NACLENTRIES cannot be trusted, use dynamic memory | ||
| 754 | allocation. */ | ||
| 755 | abort (); | ||
| 756 | |||
| 757 | /* If there are more than 3 entries, there cannot be only the | ||
| 758 | (uid,%), (%,gid), (%,%) entries. */ | ||
| 759 | if (count > 3) | ||
| 760 | return 1; | ||
| 761 | |||
| 762 | { | ||
| 763 | struct stat statbuf; | ||
| 764 | |||
| 765 | if (stat (name, &statbuf) < 0) | ||
| 766 | return -1; | ||
| 767 | |||
| 768 | return acl_nontrivial (count, entries, &statbuf); | ||
| 769 | } | ||
| 770 | } | ||
| 771 | } | ||
| 772 | |||
| 773 | # if HAVE_ACLV_H /* HP-UX >= 11.11 */ | ||
| 774 | |||
| 775 | { | ||
| 776 | struct acl entries[NACLVENTRIES]; | ||
| 777 | int count; | ||
| 778 | |||
| 779 | count = acl ((char *) name, ACL_GET, NACLVENTRIES, entries); | ||
| 780 | |||
| 781 | if (count < 0) | ||
| 782 | { | ||
| 783 | /* EOPNOTSUPP is seen on NFS in HP-UX 11.11, 11.23. | ||
| 784 | EINVAL is seen on NFS in HP-UX 11.31. */ | ||
| 785 | if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL) | ||
| 786 | ; | ||
| 787 | else | ||
| 788 | return -1; | ||
| 789 | } | ||
| 790 | else if (count == 0) | ||
| 791 | return 0; | ||
| 792 | else /* count > 0 */ | ||
| 793 | { | ||
| 794 | if (count > NACLVENTRIES) | ||
| 795 | /* If NACLVENTRIES cannot be trusted, use dynamic memory | ||
| 796 | allocation. */ | ||
| 797 | abort (); | ||
| 798 | |||
| 799 | /* If there are more than 4 entries, there cannot be only the | ||
| 800 | four base ACL entries. */ | ||
| 801 | if (count > 4) | ||
| 802 | return 1; | ||
| 803 | |||
| 804 | return aclv_nontrivial (count, entries); | ||
| 805 | } | ||
| 806 | } | ||
| 807 | |||
| 808 | # endif | ||
| 809 | |||
| 810 | # elif HAVE_ACLX_GET && defined ACL_AIX_WIP /* AIX */ | ||
| 811 | |||
| 812 | acl_type_t type; | ||
| 813 | char aclbuf[1024]; | ||
| 814 | void *acl = aclbuf; | ||
| 815 | size_t aclsize = sizeof (aclbuf); | ||
| 816 | mode_t mode; | ||
| 817 | |||
| 818 | for (;;) | ||
| 819 | { | ||
| 820 | /* The docs say that type being 0 is equivalent to ACL_ANY, but it | ||
| 821 | is not true, in AIX 5.3. */ | ||
| 822 | type.u64 = ACL_ANY; | ||
| 823 | if (aclx_get (name, 0, &type, aclbuf, &aclsize, &mode) >= 0) | ||
| 824 | break; | ||
| 825 | if (errno == ENOSYS) | ||
| 826 | return 0; | ||
| 827 | if (errno != ENOSPC) | ||
| 828 | { | ||
| 829 | if (acl != aclbuf) | ||
| 830 | { | ||
| 831 | int saved_errno = errno; | ||
| 832 | free (acl); | ||
| 833 | errno = saved_errno; | ||
| 834 | } | ||
| 835 | return -1; | ||
| 836 | } | ||
| 837 | aclsize = 2 * aclsize; | ||
| 838 | if (acl != aclbuf) | ||
| 839 | free (acl); | ||
| 840 | acl = malloc (aclsize); | ||
| 841 | if (acl == NULL) | ||
| 842 | { | ||
| 843 | errno = ENOMEM; | ||
| 844 | return -1; | ||
| 845 | } | ||
| 846 | } | ||
| 847 | |||
| 848 | if (type.u64 == ACL_AIXC) | ||
| 849 | { | ||
| 850 | int result = acl_nontrivial ((struct acl *) acl); | ||
| 851 | if (acl != aclbuf) | ||
| 852 | free (acl); | ||
| 853 | return result; | ||
| 854 | } | ||
| 855 | else if (type.u64 == ACL_NFS4) | ||
| 856 | { | ||
| 857 | int result = acl_nfs4_nontrivial ((nfs4_acl_int_t *) acl); | ||
| 858 | if (acl != aclbuf) | ||
| 859 | free (acl); | ||
| 860 | return result; | ||
| 861 | } | ||
| 862 | else | ||
| 863 | { | ||
| 864 | /* A newer type of ACL has been introduced in the system. | ||
| 865 | We should better support it. */ | ||
| 866 | if (acl != aclbuf) | ||
| 867 | free (acl); | ||
| 868 | errno = EINVAL; | ||
| 869 | return -1; | ||
| 870 | } | ||
| 871 | |||
| 872 | # elif HAVE_STATACL /* older AIX */ | ||
| 873 | |||
| 874 | union { struct acl a; char room[4096]; } u; | ||
| 875 | |||
| 876 | if (statacl (name, STX_NORMAL, &u.a, sizeof (u)) < 0) | ||
| 877 | return -1; | ||
| 878 | |||
| 879 | return acl_nontrivial (&u.a); | ||
| 880 | |||
| 881 | # elif HAVE_ACLSORT /* NonStop Kernel */ | ||
| 882 | |||
| 883 | { | ||
| 884 | struct acl entries[NACLENTRIES]; | ||
| 885 | int count; | ||
| 886 | |||
| 887 | count = acl ((char *) name, ACL_GET, NACLENTRIES, entries); | ||
| 888 | |||
| 889 | if (count < 0) | ||
| 890 | { | ||
| 891 | if (errno == ENOSYS || errno == ENOTSUP) | ||
| 892 | ; | ||
| 893 | else | ||
| 894 | return -1; | ||
| 895 | } | ||
| 896 | else if (count == 0) | ||
| 897 | return 0; | ||
| 898 | else /* count > 0 */ | ||
| 899 | { | ||
| 900 | if (count > NACLENTRIES) | ||
| 901 | /* If NACLENTRIES cannot be trusted, use dynamic memory | ||
| 902 | allocation. */ | ||
| 903 | abort (); | ||
| 904 | |||
| 905 | /* If there are more than 4 entries, there cannot be only the | ||
| 906 | four base ACL entries. */ | ||
| 907 | if (count > 4) | ||
| 908 | return 1; | ||
| 909 | |||
| 910 | return acl_nontrivial (count, entries); | ||
| 911 | } | ||
| 912 | } | ||
| 913 | |||
| 914 | # endif | ||
| 915 | } | ||
| 916 | #endif | ||
| 917 | |||
| 918 | return 0; | ||
| 919 | } | ||
diff --git a/lib/filemode.c b/lib/filemode.c index 9e8735a5d7d..3e2f8c039f7 100644 --- a/lib/filemode.c +++ b/lib/filemode.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* filemode.c -- make a string describing file modes | 1 | /* filemode.c -- make a string describing file modes |
| 2 | 2 | ||
| 3 | Copyright (C) 1985, 1990, 1993, 1998-2000, 2004, 2006, 2009-2013 Free | 3 | Copyright (C) 1985, 1990, 1993, 1998-2000, 2004, 2006, 2009-2014 Free |
| 4 | Software Foundation, Inc. | 4 | Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify |
diff --git a/lib/filemode.h b/lib/filemode.h index a235cb0c106..c51e6a3a3e9 100644 --- a/lib/filemode.h +++ b/lib/filemode.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Make a string describing file modes. | 1 | /* Make a string describing file modes. |
| 2 | 2 | ||
| 3 | Copyright (C) 1998-1999, 2003, 2006, 2009-2013 Free Software Foundation, | 3 | Copyright (C) 1998-1999, 2003, 2006, 2009-2014 Free Software Foundation, |
| 4 | Inc. | 4 | Inc. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify |
diff --git a/lib/fpending.c b/lib/fpending.c index e917f4f15f6..31aba1ada3d 100644 --- a/lib/fpending.c +++ b/lib/fpending.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* fpending.c -- return the number of pending output bytes on a stream | 1 | /* fpending.c -- return the number of pending output bytes on a stream |
| 2 | Copyright (C) 2000, 2004, 2006-2007, 2009-2013 Free Software Foundation, | 2 | Copyright (C) 2000, 2004, 2006-2007, 2009-2014 Free Software Foundation, |
| 3 | Inc. | 3 | Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 5 | This program is free software: you can redistribute it and/or modify |
diff --git a/lib/fpending.h b/lib/fpending.h index bf40d3732e7..dd607fe20c1 100644 --- a/lib/fpending.h +++ b/lib/fpending.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Declare __fpending. | 1 | /* Declare __fpending. |
| 2 | 2 | ||
| 3 | Copyright (C) 2000, 2003, 2005-2006, 2009-2013 Free Software Foundation, | 3 | Copyright (C) 2000, 2003, 2005-2006, 2009-2014 Free Software Foundation, |
| 4 | Inc. | 4 | Inc. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify |
| @@ -20,11 +20,10 @@ | |||
| 20 | 20 | ||
| 21 | #include <stddef.h> | 21 | #include <stddef.h> |
| 22 | #include <stdio.h> | 22 | #include <stdio.h> |
| 23 | #if HAVE_STDIO_EXT_H | ||
| 24 | # include <stdio_ext.h> | ||
| 25 | #endif | ||
| 23 | 26 | ||
| 24 | #if HAVE_DECL___FPENDING | 27 | #if !HAVE_DECL___FPENDING |
| 25 | # if HAVE_STDIO_EXT_H | 28 | size_t __fpending (FILE *) _GL_ATTRIBUTE_PURE; |
| 26 | # include <stdio_ext.h> | ||
| 27 | # endif | ||
| 28 | #else | ||
| 29 | size_t __fpending (FILE *); | ||
| 30 | #endif | 29 | #endif |
diff --git a/lib/fstatat.c b/lib/fstatat.c index 845c171fb45..44e32668351 100644 --- a/lib/fstatat.c +++ b/lib/fstatat.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Work around an fstatat bug on Solaris 9. | 1 | /* Work around an fstatat bug on Solaris 9. |
| 2 | 2 | ||
| 3 | Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2006, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/fsync.c b/lib/fsync.c new file mode 100644 index 00000000000..b09a8e64949 --- /dev/null +++ b/lib/fsync.c | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /* Emulate fsync on platforms that lack it, primarily Windows and | ||
| 2 | cross-compilers like MinGW. | ||
| 3 | |||
| 4 | This is derived from sqlite3 sources. | ||
| 5 | http://www.sqlite.org/cvstrac/rlog?f=sqlite/src/os_win.c | ||
| 6 | http://www.sqlite.org/copyright.html | ||
| 7 | |||
| 8 | Written by Richard W.M. Jones <rjones.at.redhat.com> | ||
| 9 | |||
| 10 | Copyright (C) 2008-2014 Free Software Foundation, Inc. | ||
| 11 | |||
| 12 | This library is free software; you can redistribute it and/or | ||
| 13 | modify it under the terms of the GNU General Public | ||
| 14 | License as published by the Free Software Foundation; either | ||
| 15 | version 3 of the License, or (at your option) any later version. | ||
| 16 | |||
| 17 | This library is distributed in the hope that it will be useful, | ||
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 20 | General Public License for more details. | ||
| 21 | |||
| 22 | You should have received a copy of the GNU General Public License | ||
| 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 24 | |||
| 25 | #include <config.h> | ||
| 26 | #include <unistd.h> | ||
| 27 | |||
| 28 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 29 | |||
| 30 | /* FlushFileBuffers */ | ||
| 31 | # define WIN32_LEAN_AND_MEAN | ||
| 32 | # include <windows.h> | ||
| 33 | |||
| 34 | # include <errno.h> | ||
| 35 | |||
| 36 | /* Get _get_osfhandle. */ | ||
| 37 | # include "msvc-nothrow.h" | ||
| 38 | |||
| 39 | int | ||
| 40 | fsync (int fd) | ||
| 41 | { | ||
| 42 | HANDLE h = (HANDLE) _get_osfhandle (fd); | ||
| 43 | DWORD err; | ||
| 44 | |||
| 45 | if (h == INVALID_HANDLE_VALUE) | ||
| 46 | { | ||
| 47 | errno = EBADF; | ||
| 48 | return -1; | ||
| 49 | } | ||
| 50 | |||
| 51 | if (!FlushFileBuffers (h)) | ||
| 52 | { | ||
| 53 | /* Translate some Windows errors into rough approximations of Unix | ||
| 54 | * errors. MSDN is useless as usual - in this case it doesn't | ||
| 55 | * document the full range of errors. | ||
| 56 | */ | ||
| 57 | err = GetLastError (); | ||
| 58 | switch (err) | ||
| 59 | { | ||
| 60 | case ERROR_ACCESS_DENIED: | ||
| 61 | /* For a read-only handle, fsync should succeed, even though we have | ||
| 62 | no way to sync the access-time changes. */ | ||
| 63 | return 0; | ||
| 64 | |||
| 65 | /* eg. Trying to fsync a tty. */ | ||
| 66 | case ERROR_INVALID_HANDLE: | ||
| 67 | errno = EINVAL; | ||
| 68 | break; | ||
| 69 | |||
| 70 | default: | ||
| 71 | errno = EIO; | ||
| 72 | } | ||
| 73 | return -1; | ||
| 74 | } | ||
| 75 | |||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | #else /* !Windows */ | ||
| 80 | |||
| 81 | # error "This platform lacks fsync function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib." | ||
| 82 | |||
| 83 | #endif /* !Windows */ | ||
diff --git a/lib/ftoastr.c b/lib/ftoastr.c index 518074f8a5a..7780d00860c 100644 --- a/lib/ftoastr.c +++ b/lib/ftoastr.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* floating point to accurate string | 1 | /* floating point to accurate string |
| 2 | 2 | ||
| 3 | Copyright (C) 2010-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2010-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/ftoastr.h b/lib/ftoastr.h index 5aa0930d29e..6236292d9d9 100644 --- a/lib/ftoastr.h +++ b/lib/ftoastr.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* floating point to accurate string | 1 | /* floating point to accurate string |
| 2 | 2 | ||
| 3 | Copyright (C) 2010-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2010-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c new file mode 100644 index 00000000000..946738cdb68 --- /dev/null +++ b/lib/getdtablesize.c | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | /* getdtablesize() function for platforms that don't have it. | ||
| 2 | Copyright (C) 2008-2014 Free Software Foundation, Inc. | ||
| 3 | Written by Bruno Haible <bruno@clisp.org>, 2008. | ||
| 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 <unistd.h> | ||
| 22 | |||
| 23 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 24 | |||
| 25 | # include <stdio.h> | ||
| 26 | |||
| 27 | # include "msvc-inval.h" | ||
| 28 | |||
| 29 | # if HAVE_MSVC_INVALID_PARAMETER_HANDLER | ||
| 30 | static int | ||
| 31 | _setmaxstdio_nothrow (int newmax) | ||
| 32 | { | ||
| 33 | int result; | ||
| 34 | |||
| 35 | TRY_MSVC_INVAL | ||
| 36 | { | ||
| 37 | result = _setmaxstdio (newmax); | ||
| 38 | } | ||
| 39 | CATCH_MSVC_INVAL | ||
| 40 | { | ||
| 41 | result = -1; | ||
| 42 | } | ||
| 43 | DONE_MSVC_INVAL; | ||
| 44 | |||
| 45 | return result; | ||
| 46 | } | ||
| 47 | # define _setmaxstdio _setmaxstdio_nothrow | ||
| 48 | # endif | ||
| 49 | |||
| 50 | /* Cache for the previous getdtablesize () result. Safe to cache because | ||
| 51 | Windows also lacks setrlimit. */ | ||
| 52 | static int dtablesize; | ||
| 53 | |||
| 54 | int | ||
| 55 | getdtablesize (void) | ||
| 56 | { | ||
| 57 | if (dtablesize == 0) | ||
| 58 | { | ||
| 59 | /* We are looking for the number N such that the valid file descriptors | ||
| 60 | are 0..N-1. It can be obtained through a loop as follows: | ||
| 61 | { | ||
| 62 | int fd; | ||
| 63 | for (fd = 3; fd < 65536; fd++) | ||
| 64 | if (dup2 (0, fd) == -1) | ||
| 65 | break; | ||
| 66 | return fd; | ||
| 67 | } | ||
| 68 | On Windows XP, the result is 2048. | ||
| 69 | The drawback of this loop is that it allocates memory for a libc | ||
| 70 | internal array that is never freed. | ||
| 71 | |||
| 72 | The number N can also be obtained as the upper bound for | ||
| 73 | _getmaxstdio (). _getmaxstdio () returns the maximum number of open | ||
| 74 | FILE objects. The sanity check in _setmaxstdio reveals the maximum | ||
| 75 | number of file descriptors. This too allocates memory, but it is | ||
| 76 | freed when we call _setmaxstdio with the original value. */ | ||
| 77 | int orig_max_stdio = _getmaxstdio (); | ||
| 78 | unsigned int bound; | ||
| 79 | for (bound = 0x10000; _setmaxstdio (bound) < 0; bound = bound / 2) | ||
| 80 | ; | ||
| 81 | _setmaxstdio (orig_max_stdio); | ||
| 82 | dtablesize = bound; | ||
| 83 | } | ||
| 84 | return dtablesize; | ||
| 85 | } | ||
| 86 | |||
| 87 | #elif HAVE_GETDTABLESIZE | ||
| 88 | |||
| 89 | # include <sys/resource.h> | ||
| 90 | # undef getdtablesize | ||
| 91 | |||
| 92 | int | ||
| 93 | rpl_getdtablesize(void) | ||
| 94 | { | ||
| 95 | /* To date, this replacement is only compiled for Cygwin 1.7.25, | ||
| 96 | which auto-increased the RLIMIT_NOFILE soft limit until it | ||
| 97 | hits the compile-time constant hard limit of 3200. Although | ||
| 98 | that version of cygwin supported a child process inheriting | ||
| 99 | a smaller soft limit, the smaller limit is not enforced, so | ||
| 100 | we might as well just report the hard limit. */ | ||
| 101 | struct rlimit lim; | ||
| 102 | if (!getrlimit (RLIMIT_NOFILE, &lim) && lim.rlim_max != RLIM_INFINITY) | ||
| 103 | return lim.rlim_max; | ||
| 104 | return getdtablesize (); | ||
| 105 | } | ||
| 106 | |||
| 107 | #endif | ||
diff --git a/lib/getgroups.c b/lib/getgroups.c index 9856adc1a4d..91a340f3d6d 100644 --- a/lib/getgroups.c +++ b/lib/getgroups.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* provide consistent interface to getgroups for systems that don't allow N==0 | 1 | /* provide consistent interface to getgroups for systems that don't allow N==0 |
| 2 | 2 | ||
| 3 | Copyright (C) 1996, 1999, 2003, 2006-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 1996, 1999, 2003, 2006-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -43,6 +43,21 @@ getgroups (int n _GL_UNUSED, GETGROUPS_T *groups _GL_UNUSED) | |||
| 43 | # define GETGROUPS_ZERO_BUG 0 | 43 | # define GETGROUPS_ZERO_BUG 0 |
| 44 | # endif | 44 | # endif |
| 45 | 45 | ||
| 46 | /* On OS X 10.6 and later, use the usual getgroups, not the one | ||
| 47 | supplied when _DARWIN_C_SOURCE is defined. _DARWIN_C_SOURCE is | ||
| 48 | normally defined, since it means "conform to POSIX, but add | ||
| 49 | non-POSIX extensions even if that violates the POSIX namespace | ||
| 50 | rules", which is what we normally want. But with getgroups there | ||
| 51 | is an inconsistency, and _DARWIN_C_SOURCE means "change getgroups() | ||
| 52 | so that it no longer works right". The BUGS section of compat(5) | ||
| 53 | says that the behavior is dubious if you compile different sections | ||
| 54 | of a program with different _DARWIN_C_SOURCE settings, so fix only | ||
| 55 | the offending symbol. */ | ||
| 56 | # ifdef __APPLE__ | ||
| 57 | int posix_getgroups (int, gid_t []) __asm ("_getgroups"); | ||
| 58 | # define getgroups posix_getgroups | ||
| 59 | # endif | ||
| 60 | |||
| 46 | /* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always | 61 | /* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always |
| 47 | fails. On other systems, it returns the number of supplemental | 62 | fails. On other systems, it returns the number of supplemental |
| 48 | groups for the process. This function handles that special case | 63 | groups for the process. This function handles that special case |
| @@ -86,7 +101,7 @@ rpl_getgroups (int n, gid_t *group) | |||
| 86 | } | 101 | } |
| 87 | saved_errno = errno; | 102 | saved_errno = errno; |
| 88 | free (gbuf); | 103 | free (gbuf); |
| 89 | errno == saved_errno; | 104 | errno = saved_errno; |
| 90 | return result; | 105 | return result; |
| 91 | } | 106 | } |
| 92 | 107 | ||
diff --git a/lib/getloadavg.c b/lib/getloadavg.c index 6e228191ee8..cdba52593fa 100644 --- a/lib/getloadavg.c +++ b/lib/getloadavg.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Get the system load averages. | 1 | /* Get the system load averages. |
| 2 | 2 | ||
| 3 | Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2013 Free Software | 3 | Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2014 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | 5 | ||
| 6 | NOTE: The canonical source of this file is maintained with gnulib. | 6 | NOTE: The canonical source of this file is maintained with gnulib. |
diff --git a/lib/getopt.c b/lib/getopt.c index ef0f4ceec7c..7d950af1a5f 100644 --- a/lib/getopt.c +++ b/lib/getopt.c | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | NOTE: getopt is part of the C library, so if you don't know what | 2 | NOTE: getopt is part of the C library, so if you don't know what |
| 3 | "Keep this file name-space clean" means, talk to drepper@gnu.org | 3 | "Keep this file name-space clean" means, talk to drepper@gnu.org |
| 4 | before changing it! | 4 | before changing it! |
| 5 | Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2013 Free Software | 5 | Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2014 Free Software |
| 6 | Foundation, Inc. | 6 | Foundation, Inc. |
| 7 | This file is part of the GNU C Library. | 7 | This file is part of the GNU C Library. |
| 8 | 8 | ||
diff --git a/lib/getopt.in.h b/lib/getopt.in.h index d9c7d8144ae..7ab99fb8323 100644 --- a/lib/getopt.in.h +++ b/lib/getopt.in.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Declarations for getopt. | 1 | /* Declarations for getopt. |
| 2 | Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2013 Free Software | 2 | Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2014 Free Software |
| 3 | Foundation, Inc. | 3 | Foundation, Inc. |
| 4 | This file is part of the GNU C Library. | 4 | This file is part of the GNU C Library. |
| 5 | 5 | ||
diff --git a/lib/getopt1.c b/lib/getopt1.c index 55a6b4eae45..a184865ea63 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* getopt_long and getopt_long_only entry points for GNU getopt. | 1 | /* getopt_long and getopt_long_only entry points for GNU getopt. |
| 2 | Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2013 Free Software | 2 | Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2014 Free Software |
| 3 | Foundation, Inc. | 3 | Foundation, Inc. |
| 4 | This file is part of the GNU C Library. | 4 | This file is part of the GNU C Library. |
| 5 | 5 | ||
diff --git a/lib/getopt_.h b/lib/getopt_.h index dd958138b22..6c356c314e9 100644 --- a/lib/getopt_.h +++ b/lib/getopt_.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Declarations for getopt. | 1 | /* Declarations for getopt. |
| 2 | Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2013 Free Software | 2 | Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2014 Free |
| 3 | Foundation, Inc. | 3 | Software Foundation, Inc. |
| 4 | This file is part of the GNU C Library. | 4 | This file is part of the GNU C Library. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify |
| @@ -130,7 +130,7 @@ | |||
| 130 | 130 | ||
| 131 | /* The definition of _GL_ARG_NONNULL is copied here. */ | 131 | /* The definition of _GL_ARG_NONNULL is copied here. */ |
| 132 | /* A C macro for declaring that specific arguments must not be NULL. | 132 | /* A C macro for declaring that specific arguments must not be NULL. |
| 133 | Copyright (C) 2009-2013 Free Software Foundation, Inc. | 133 | Copyright (C) 2009-2014 Free Software Foundation, Inc. |
| 134 | 134 | ||
| 135 | This program is free software: you can redistribute it and/or modify it | 135 | This program is free software: you can redistribute it and/or modify it |
| 136 | under the terms of the GNU General Public License as published | 136 | under the terms of the GNU General Public License as published |
diff --git a/lib/getopt_int.h b/lib/getopt_int.h index a6e4b9ea71c..24ed672e2eb 100644 --- a/lib/getopt_int.h +++ b/lib/getopt_int.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Internal declarations for getopt. | 1 | /* Internal declarations for getopt. |
| 2 | Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2013 Free Software | 2 | Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2014 Free Software |
| 3 | Foundation, Inc. | 3 | Foundation, Inc. |
| 4 | This file is part of the GNU C Library. | 4 | This file is part of the GNU C Library. |
| 5 | 5 | ||
diff --git a/lib/gettext.h b/lib/gettext.h index d0215715a97..c7d6fd345ce 100644 --- a/lib/gettext.h +++ b/lib/gettext.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Convenience header for conditional use of GNU <libintl.h>. | 1 | /* Convenience header for conditional use of GNU <libintl.h>. |
| 2 | Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2013 Free Software | 2 | Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2014 Free Software |
| 3 | Foundation, Inc. | 3 | Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
diff --git a/lib/gettime.c b/lib/gettime.c index 0a642dd2015..1b4ca8d2f3a 100644 --- a/lib/gettime.c +++ b/lib/gettime.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* gettime -- get the system clock | 1 | /* gettime -- get the system clock |
| 2 | 2 | ||
| 3 | Copyright (C) 2002, 2004-2007, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2002, 2004-2007, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c index ad65c6da8be..8b2058e8c87 100644 --- a/lib/gettimeofday.c +++ b/lib/gettimeofday.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Provide gettimeofday for systems that don't have it or for which it's broken. | 1 | /* Provide gettimeofday for systems that don't have it or for which it's broken. |
| 2 | 2 | ||
| 3 | Copyright (C) 2001-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2001-2003, 2005-2007, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/gnulib.mk b/lib/gnulib.mk index c130cbc65b8..0f22beb3f5f 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ## DO NOT EDIT! GENERATED AUTOMATICALLY! | 1 | ## DO NOT EDIT! GENERATED AUTOMATICALLY! |
| 2 | ## Process this file with automake to produce Makefile.in. | 2 | ## Process this file with automake to produce Makefile.in. |
| 3 | # Copyright (C) 2002-2013 Free Software Foundation, Inc. | 3 | # Copyright (C) 2002-2014 Free Software Foundation, Inc. |
| 4 | # | 4 | # |
| 5 | # This file is free software; you can redistribute it and/or modify | 5 | # This file is free software; you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License as published by | 6 | # it under the terms of the GNU General Public License as published by |
| @@ -21,7 +21,7 @@ | |||
| 21 | # the same distribution terms as the rest of that program. | 21 | # the same distribution terms as the rest of that program. |
| 22 | # | 22 | # |
| 23 | # Generated by gnulib-tool. | 23 | # Generated by gnulib-tool. |
| 24 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=dup --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h fdopendir filemode fstatat getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings memrchr mktime pselect pthread_sigmask putenv readlink readlinkat sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings | 24 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=close --avoid=dup --avoid=fchdir --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt byteswap c-ctype c-strcase careadlinkat close-stream count-one-bits count-trailing-zeros crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl fcntl-h fdatasync fdopendir filemode fstatat fsync getloadavg getopt-gnu gettime gettimeofday intprops largefile lstat manywarnings memrchr mkostemp mktime pipe2 pselect pthread_sigmask putenv qacl readlink readlinkat sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub unsetenv update-copyright utimens warnings |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | MOSTLYCLEANFILES += core *.stackdump | 27 | MOSTLYCLEANFILES += core *.stackdump |
| @@ -33,6 +33,15 @@ libgnu_a_LIBADD = $(gl_LIBOBJS) | |||
| 33 | libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) | 33 | libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) |
| 34 | EXTRA_libgnu_a_SOURCES = | 34 | EXTRA_libgnu_a_SOURCES = |
| 35 | 35 | ||
| 36 | ## begin gnulib module absolute-header | ||
| 37 | |||
| 38 | # Use this preprocessor expression to decide whether #include_next works. | ||
| 39 | # Do not rely on a 'configure'-time test for this, since the expression | ||
| 40 | # might appear in an installed header, which is used by some other compiler. | ||
| 41 | HAVE_INCLUDE_NEXT = (__GNUC__ || 60000000 <= __DECC_VER) | ||
| 42 | |||
| 43 | ## end gnulib module absolute-header | ||
| 44 | |||
| 36 | ## begin gnulib module alloca-opt | 45 | ## begin gnulib module alloca-opt |
| 37 | 46 | ||
| 38 | BUILT_SOURCES += $(ALLOCA_H) | 47 | BUILT_SOURCES += $(ALLOCA_H) |
| @@ -75,6 +84,35 @@ EXTRA_libgnu_a_SOURCES += openat-proc.c | |||
| 75 | 84 | ||
| 76 | ## end gnulib module at-internal | 85 | ## end gnulib module at-internal |
| 77 | 86 | ||
| 87 | ## begin gnulib module binary-io | ||
| 88 | |||
| 89 | libgnu_a_SOURCES += binary-io.h binary-io.c | ||
| 90 | |||
| 91 | ## end gnulib module binary-io | ||
| 92 | |||
| 93 | ## begin gnulib module byteswap | ||
| 94 | |||
| 95 | BUILT_SOURCES += $(BYTESWAP_H) | ||
| 96 | |||
| 97 | # We need the following in order to create <byteswap.h> when the system | ||
| 98 | # doesn't have one. | ||
| 99 | if GL_GENERATE_BYTESWAP_H | ||
| 100 | byteswap.h: byteswap.in.h $(top_builddir)/config.status | ||
| 101 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 102 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | ||
| 103 | cat $(srcdir)/byteswap.in.h; \ | ||
| 104 | } > $@-t && \ | ||
| 105 | mv -f $@-t $@ | ||
| 106 | else | ||
| 107 | byteswap.h: $(top_builddir)/config.status | ||
| 108 | rm -f $@ | ||
| 109 | endif | ||
| 110 | MOSTLYCLEANFILES += byteswap.h byteswap.h-t | ||
| 111 | |||
| 112 | EXTRA_DIST += byteswap.in.h | ||
| 113 | |||
| 114 | ## end gnulib module byteswap | ||
| 115 | |||
| 78 | ## begin gnulib module c-ctype | 116 | ## begin gnulib module c-ctype |
| 79 | 117 | ||
| 80 | libgnu_a_SOURCES += c-ctype.h c-ctype.c | 118 | libgnu_a_SOURCES += c-ctype.h c-ctype.c |
| @@ -103,11 +141,27 @@ EXTRA_DIST += close-stream.h | |||
| 103 | 141 | ||
| 104 | ## end gnulib module close-stream | 142 | ## end gnulib module close-stream |
| 105 | 143 | ||
| 144 | ## begin gnulib module count-one-bits | ||
| 145 | |||
| 146 | libgnu_a_SOURCES += count-one-bits.c | ||
| 147 | |||
| 148 | EXTRA_DIST += count-one-bits.h | ||
| 149 | |||
| 150 | ## end gnulib module count-one-bits | ||
| 151 | |||
| 152 | ## begin gnulib module count-trailing-zeros | ||
| 153 | |||
| 154 | libgnu_a_SOURCES += count-trailing-zeros.c | ||
| 155 | |||
| 156 | EXTRA_DIST += count-trailing-zeros.h | ||
| 157 | |||
| 158 | ## end gnulib module count-trailing-zeros | ||
| 159 | |||
| 106 | ## begin gnulib module crypto/md5 | 160 | ## begin gnulib module crypto/md5 |
| 107 | 161 | ||
| 108 | libgnu_a_SOURCES += md5.c | 162 | libgnu_a_SOURCES += md5.c |
| 109 | 163 | ||
| 110 | EXTRA_DIST += md5.h | 164 | EXTRA_DIST += gl_openssl.h md5.h |
| 111 | 165 | ||
| 112 | ## end gnulib module crypto/md5 | 166 | ## end gnulib module crypto/md5 |
| 113 | 167 | ||
| @@ -115,7 +169,7 @@ EXTRA_DIST += md5.h | |||
| 115 | 169 | ||
| 116 | libgnu_a_SOURCES += sha1.c | 170 | libgnu_a_SOURCES += sha1.c |
| 117 | 171 | ||
| 118 | EXTRA_DIST += sha1.h | 172 | EXTRA_DIST += gl_openssl.h sha1.h |
| 119 | 173 | ||
| 120 | ## end gnulib module crypto/sha1 | 174 | ## end gnulib module crypto/sha1 |
| 121 | 175 | ||
| @@ -123,7 +177,7 @@ EXTRA_DIST += sha1.h | |||
| 123 | 177 | ||
| 124 | libgnu_a_SOURCES += sha256.c | 178 | libgnu_a_SOURCES += sha256.c |
| 125 | 179 | ||
| 126 | EXTRA_DIST += sha256.h | 180 | EXTRA_DIST += gl_openssl.h sha256.h |
| 127 | 181 | ||
| 128 | ## end gnulib module crypto/sha256 | 182 | ## end gnulib module crypto/sha256 |
| 129 | 183 | ||
| @@ -131,7 +185,7 @@ EXTRA_DIST += sha256.h | |||
| 131 | 185 | ||
| 132 | libgnu_a_SOURCES += sha512.c | 186 | libgnu_a_SOURCES += sha512.c |
| 133 | 187 | ||
| 134 | EXTRA_DIST += sha512.h | 188 | EXTRA_DIST += gl_openssl.h sha512.h |
| 135 | 189 | ||
| 136 | ## end gnulib module crypto/sha512 | 190 | ## end gnulib module crypto/sha512 |
| 137 | 191 | ||
| @@ -217,6 +271,40 @@ EXTRA_libgnu_a_SOURCES += dup2.c | |||
| 217 | 271 | ||
| 218 | ## end gnulib module dup2 | 272 | ## end gnulib module dup2 |
| 219 | 273 | ||
| 274 | ## begin gnulib module errno | ||
| 275 | |||
| 276 | BUILT_SOURCES += $(ERRNO_H) | ||
| 277 | |||
| 278 | # We need the following in order to create <errno.h> when the system | ||
| 279 | # doesn't have one that is POSIX compliant. | ||
| 280 | if GL_GENERATE_ERRNO_H | ||
| 281 | errno.h: errno.in.h $(top_builddir)/config.status | ||
| 282 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 283 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ | ||
| 284 | sed -e 's|@''GUARD_PREFIX''@|GL|g' \ | ||
| 285 | -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ | ||
| 286 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ | ||
| 287 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ | ||
| 288 | -e 's|@''NEXT_ERRNO_H''@|$(NEXT_ERRNO_H)|g' \ | ||
| 289 | -e 's|@''EMULTIHOP_HIDDEN''@|$(EMULTIHOP_HIDDEN)|g' \ | ||
| 290 | -e 's|@''EMULTIHOP_VALUE''@|$(EMULTIHOP_VALUE)|g' \ | ||
| 291 | -e 's|@''ENOLINK_HIDDEN''@|$(ENOLINK_HIDDEN)|g' \ | ||
| 292 | -e 's|@''ENOLINK_VALUE''@|$(ENOLINK_VALUE)|g' \ | ||
| 293 | -e 's|@''EOVERFLOW_HIDDEN''@|$(EOVERFLOW_HIDDEN)|g' \ | ||
| 294 | -e 's|@''EOVERFLOW_VALUE''@|$(EOVERFLOW_VALUE)|g' \ | ||
| 295 | < $(srcdir)/errno.in.h; \ | ||
| 296 | } > $@-t && \ | ||
| 297 | mv $@-t $@ | ||
| 298 | else | ||
| 299 | errno.h: $(top_builddir)/config.status | ||
| 300 | rm -f $@ | ||
| 301 | endif | ||
| 302 | MOSTLYCLEANFILES += errno.h errno.h-t | ||
| 303 | |||
| 304 | EXTRA_DIST += errno.in.h | ||
| 305 | |||
| 306 | ## end gnulib module errno | ||
| 307 | |||
| 220 | ## begin gnulib module euidaccess | 308 | ## begin gnulib module euidaccess |
| 221 | 309 | ||
| 222 | if gl_GNULIB_ENABLED_euidaccess | 310 | if gl_GNULIB_ENABLED_euidaccess |
| @@ -262,6 +350,15 @@ EXTRA_libgnu_a_SOURCES += at-func.c faccessat.c | |||
| 262 | 350 | ||
| 263 | ## end gnulib module faccessat | 351 | ## end gnulib module faccessat |
| 264 | 352 | ||
| 353 | ## begin gnulib module fcntl | ||
| 354 | |||
| 355 | |||
| 356 | EXTRA_DIST += fcntl.c | ||
| 357 | |||
| 358 | EXTRA_libgnu_a_SOURCES += fcntl.c | ||
| 359 | |||
| 360 | ## end gnulib module fcntl | ||
| 361 | |||
| 265 | ## begin gnulib module fcntl-h | 362 | ## begin gnulib module fcntl-h |
| 266 | 363 | ||
| 267 | BUILT_SOURCES += fcntl.h | 364 | BUILT_SOURCES += fcntl.h |
| @@ -297,6 +394,15 @@ EXTRA_DIST += fcntl.in.h | |||
| 297 | 394 | ||
| 298 | ## end gnulib module fcntl-h | 395 | ## end gnulib module fcntl-h |
| 299 | 396 | ||
| 397 | ## begin gnulib module fdatasync | ||
| 398 | |||
| 399 | |||
| 400 | EXTRA_DIST += fdatasync.c | ||
| 401 | |||
| 402 | EXTRA_libgnu_a_SOURCES += fdatasync.c | ||
| 403 | |||
| 404 | ## end gnulib module fdatasync | ||
| 405 | |||
| 300 | ## begin gnulib module fdopendir | 406 | ## begin gnulib module fdopendir |
| 301 | 407 | ||
| 302 | 408 | ||
| @@ -332,6 +438,26 @@ EXTRA_libgnu_a_SOURCES += at-func.c fstatat.c | |||
| 332 | 438 | ||
| 333 | ## end gnulib module fstatat | 439 | ## end gnulib module fstatat |
| 334 | 440 | ||
| 441 | ## begin gnulib module fsync | ||
| 442 | |||
| 443 | |||
| 444 | EXTRA_DIST += fsync.c | ||
| 445 | |||
| 446 | EXTRA_libgnu_a_SOURCES += fsync.c | ||
| 447 | |||
| 448 | ## end gnulib module fsync | ||
| 449 | |||
| 450 | ## begin gnulib module getdtablesize | ||
| 451 | |||
| 452 | if gl_GNULIB_ENABLED_getdtablesize | ||
| 453 | |||
| 454 | endif | ||
| 455 | EXTRA_DIST += getdtablesize.c | ||
| 456 | |||
| 457 | EXTRA_libgnu_a_SOURCES += getdtablesize.c | ||
| 458 | |||
| 459 | ## end gnulib module getdtablesize | ||
| 460 | |||
| 335 | ## begin gnulib module getgroups | 461 | ## begin gnulib module getgroups |
| 336 | 462 | ||
| 337 | if gl_GNULIB_ENABLED_getgroups | 463 | if gl_GNULIB_ENABLED_getgroups |
| @@ -413,13 +539,6 @@ EXTRA_libgnu_a_SOURCES += group-member.c | |||
| 413 | 539 | ||
| 414 | ## end gnulib module group-member | 540 | ## end gnulib module group-member |
| 415 | 541 | ||
| 416 | ## begin gnulib module ignore-value | ||
| 417 | |||
| 418 | |||
| 419 | EXTRA_DIST += ignore-value.h | ||
| 420 | |||
| 421 | ## end gnulib module ignore-value | ||
| 422 | |||
| 423 | ## begin gnulib module intprops | 542 | ## begin gnulib module intprops |
| 424 | 543 | ||
| 425 | 544 | ||
| @@ -455,6 +574,7 @@ inttypes.h: inttypes.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_U | |||
| 455 | -e 's/@''HAVE_DECL_STRTOIMAX''@/$(HAVE_DECL_STRTOIMAX)/g' \ | 574 | -e 's/@''HAVE_DECL_STRTOIMAX''@/$(HAVE_DECL_STRTOIMAX)/g' \ |
| 456 | -e 's/@''HAVE_DECL_STRTOUMAX''@/$(HAVE_DECL_STRTOUMAX)/g' \ | 575 | -e 's/@''HAVE_DECL_STRTOUMAX''@/$(HAVE_DECL_STRTOUMAX)/g' \ |
| 457 | -e 's/@''REPLACE_STRTOIMAX''@/$(REPLACE_STRTOIMAX)/g' \ | 576 | -e 's/@''REPLACE_STRTOIMAX''@/$(REPLACE_STRTOIMAX)/g' \ |
| 577 | -e 's/@''REPLACE_STRTOUMAX''@/$(REPLACE_STRTOUMAX)/g' \ | ||
| 458 | -e 's/@''INT32_MAX_LT_INTMAX_MAX''@/$(INT32_MAX_LT_INTMAX_MAX)/g' \ | 578 | -e 's/@''INT32_MAX_LT_INTMAX_MAX''@/$(INT32_MAX_LT_INTMAX_MAX)/g' \ |
| 459 | -e 's/@''INT64_MAX_EQ_LONG_MAX''@/$(INT64_MAX_EQ_LONG_MAX)/g' \ | 579 | -e 's/@''INT64_MAX_EQ_LONG_MAX''@/$(INT64_MAX_EQ_LONG_MAX)/g' \ |
| 460 | -e 's/@''UINT32_MAX_LT_UINTMAX_MAX''@/$(UINT32_MAX_LT_UINTMAX_MAX)/g' \ | 580 | -e 's/@''UINT32_MAX_LT_UINTMAX_MAX''@/$(UINT32_MAX_LT_UINTMAX_MAX)/g' \ |
| @@ -489,6 +609,15 @@ EXTRA_libgnu_a_SOURCES += memrchr.c | |||
| 489 | 609 | ||
| 490 | ## end gnulib module memrchr | 610 | ## end gnulib module memrchr |
| 491 | 611 | ||
| 612 | ## begin gnulib module mkostemp | ||
| 613 | |||
| 614 | |||
| 615 | EXTRA_DIST += mkostemp.c | ||
| 616 | |||
| 617 | EXTRA_libgnu_a_SOURCES += mkostemp.c | ||
| 618 | |||
| 619 | ## end gnulib module mkostemp | ||
| 620 | |||
| 492 | ## begin gnulib module mktime | 621 | ## begin gnulib module mktime |
| 493 | 622 | ||
| 494 | 623 | ||
| @@ -516,6 +645,12 @@ EXTRA_DIST += pathmax.h | |||
| 516 | 645 | ||
| 517 | ## end gnulib module pathmax | 646 | ## end gnulib module pathmax |
| 518 | 647 | ||
| 648 | ## begin gnulib module pipe2 | ||
| 649 | |||
| 650 | libgnu_a_SOURCES += pipe2.c | ||
| 651 | |||
| 652 | ## end gnulib module pipe2 | ||
| 653 | |||
| 519 | ## begin gnulib module pselect | 654 | ## begin gnulib module pselect |
| 520 | 655 | ||
| 521 | 656 | ||
| @@ -543,6 +678,16 @@ EXTRA_libgnu_a_SOURCES += putenv.c | |||
| 543 | 678 | ||
| 544 | ## end gnulib module putenv | 679 | ## end gnulib module putenv |
| 545 | 680 | ||
| 681 | ## begin gnulib module qacl | ||
| 682 | |||
| 683 | libgnu_a_SOURCES += acl-errno-valid.c file-has-acl.c qcopy-acl.c qset-acl.c | ||
| 684 | |||
| 685 | EXTRA_DIST += acl-internal.h acl.h acl_entries.c | ||
| 686 | |||
| 687 | EXTRA_libgnu_a_SOURCES += acl_entries.c | ||
| 688 | |||
| 689 | ## end gnulib module qacl | ||
| 690 | |||
| 546 | ## begin gnulib module readlink | 691 | ## begin gnulib module readlink |
| 547 | 692 | ||
| 548 | 693 | ||
| @@ -570,6 +715,17 @@ EXTRA_DIST += root-uid.h | |||
| 570 | 715 | ||
| 571 | ## end gnulib module root-uid | 716 | ## end gnulib module root-uid |
| 572 | 717 | ||
| 718 | ## begin gnulib module secure_getenv | ||
| 719 | |||
| 720 | if gl_GNULIB_ENABLED_secure_getenv | ||
| 721 | |||
| 722 | endif | ||
| 723 | EXTRA_DIST += secure_getenv.c | ||
| 724 | |||
| 725 | EXTRA_libgnu_a_SOURCES += secure_getenv.c | ||
| 726 | |||
| 727 | ## end gnulib module secure_getenv | ||
| 728 | |||
| 573 | ## begin gnulib module sig2str | 729 | ## begin gnulib module sig2str |
| 574 | 730 | ||
| 575 | 731 | ||
| @@ -1393,6 +1549,16 @@ EXTRA_DIST += sys_time.in.h | |||
| 1393 | 1549 | ||
| 1394 | ## end gnulib module sys_time | 1550 | ## end gnulib module sys_time |
| 1395 | 1551 | ||
| 1552 | ## begin gnulib module tempname | ||
| 1553 | |||
| 1554 | if gl_GNULIB_ENABLED_tempname | ||
| 1555 | libgnu_a_SOURCES += tempname.c | ||
| 1556 | |||
| 1557 | endif | ||
| 1558 | EXTRA_DIST += tempname.h | ||
| 1559 | |||
| 1560 | ## end gnulib module tempname | ||
| 1561 | |||
| 1396 | ## begin gnulib module time | 1562 | ## begin gnulib module time |
| 1397 | 1563 | ||
| 1398 | BUILT_SOURCES += time.h | 1564 | BUILT_SOURCES += time.h |
| @@ -1407,6 +1573,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( | |||
| 1407 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ | 1573 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ |
| 1408 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ | 1574 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ |
| 1409 | -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ | 1575 | -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ |
| 1576 | -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ | ||
| 1410 | -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \ | 1577 | -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \ |
| 1411 | -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \ | 1578 | -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \ |
| 1412 | -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \ | 1579 | -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \ |
| @@ -1416,6 +1583,8 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( | |||
| 1416 | -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ | 1583 | -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ |
| 1417 | -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ | 1584 | -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ |
| 1418 | -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ | 1585 | -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ |
| 1586 | -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \ | ||
| 1587 | -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \ | ||
| 1419 | -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ | 1588 | -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ |
| 1420 | -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ | 1589 | -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ |
| 1421 | -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ | 1590 | -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ |
| @@ -1590,6 +1759,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H | |||
| 1590 | -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \ | 1759 | -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \ |
| 1591 | -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ | 1760 | -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ |
| 1592 | -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \ | 1761 | -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \ |
| 1762 | -e 's|@''REPLACE_GETDTABLESIZE''@|$(REPLACE_GETDTABLESIZE)|g' \ | ||
| 1593 | -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \ | 1763 | -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \ |
| 1594 | -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ | 1764 | -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ |
| 1595 | -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ | 1765 | -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ |
| @@ -1632,6 +1802,13 @@ EXTRA_libgnu_a_SOURCES += unsetenv.c | |||
| 1632 | 1802 | ||
| 1633 | ## end gnulib module unsetenv | 1803 | ## end gnulib module unsetenv |
| 1634 | 1804 | ||
| 1805 | ## begin gnulib module update-copyright | ||
| 1806 | |||
| 1807 | |||
| 1808 | EXTRA_DIST += $(top_srcdir)/build-aux/update-copyright | ||
| 1809 | |||
| 1810 | ## end gnulib module update-copyright | ||
| 1811 | |||
| 1635 | ## begin gnulib module utimens | 1812 | ## begin gnulib module utimens |
| 1636 | 1813 | ||
| 1637 | libgnu_a_SOURCES += utimens.c | 1814 | libgnu_a_SOURCES += utimens.c |
| @@ -1642,9 +1819,7 @@ EXTRA_DIST += utimens.h | |||
| 1642 | 1819 | ||
| 1643 | ## begin gnulib module verify | 1820 | ## begin gnulib module verify |
| 1644 | 1821 | ||
| 1645 | if gl_GNULIB_ENABLED_verify | ||
| 1646 | 1822 | ||
| 1647 | endif | ||
| 1648 | EXTRA_DIST += verify.h | 1823 | EXTRA_DIST += verify.h |
| 1649 | 1824 | ||
| 1650 | ## end gnulib module verify | 1825 | ## end gnulib module verify |
diff --git a/lib/group-member.c b/lib/group-member.c index da015842c21..e869dca92b7 100644 --- a/lib/group-member.c +++ b/lib/group-member.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* group-member.c -- determine whether group id is in calling user's group list | 1 | /* group-member.c -- determine whether group id is in calling user's group list |
| 2 | 2 | ||
| 3 | Copyright (C) 1994, 1997-1998, 2003, 2005-2006, 2009-2013 Free Software | 3 | Copyright (C) 1994, 1997-1998, 2003, 2005-2006, 2009-2014 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify |
diff --git a/lib/ignore-value.h b/lib/ignore-value.h deleted file mode 100644 index 63ecde85136..00000000000 --- a/lib/ignore-value.h +++ /dev/null | |||
| @@ -1,47 +0,0 @@ | |||
| 1 | /* ignore a function return without a compiler warning | ||
| 2 | |||
| 3 | Copyright (C) 2008-2013 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 | /* Written by Jim Meyering, Eric Blake and Pádraig Brady. */ | ||
| 19 | |||
| 20 | /* Use "ignore_value" to avoid a warning when using a function declared with | ||
| 21 | gcc's warn_unused_result attribute, but for which you really do want to | ||
| 22 | ignore the result. Traditionally, people have used a "(void)" cast to | ||
| 23 | indicate that a function's return value is deliberately unused. However, | ||
| 24 | if the function is declared with __attribute__((warn_unused_result)), | ||
| 25 | gcc issues a warning even with the cast. | ||
| 26 | |||
| 27 | Caution: most of the time, you really should heed gcc's warning, and | ||
| 28 | check the return value. However, in those exceptional cases in which | ||
| 29 | you're sure you know what you're doing, use this function. | ||
| 30 | |||
| 31 | For the record, here's one of the ignorable warnings: | ||
| 32 | "copy.c:233: warning: ignoring return value of 'fchown', | ||
| 33 | declared with attribute warn_unused_result". */ | ||
| 34 | |||
| 35 | #ifndef _GL_IGNORE_VALUE_H | ||
| 36 | # define _GL_IGNORE_VALUE_H | ||
| 37 | |||
| 38 | /* The __attribute__((__warn_unused_result__)) feature | ||
| 39 | is available in gcc versions 3.4 and newer, | ||
| 40 | while the typeof feature has been available since 2.7 at least. */ | ||
| 41 | # if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4) | ||
| 42 | # define ignore_value(x) ((void) (x)) | ||
| 43 | # else | ||
| 44 | # define ignore_value(x) (({ __typeof__ (x) __x = (x); (void) __x; })) | ||
| 45 | # endif | ||
| 46 | |||
| 47 | #endif | ||
diff --git a/lib/intprops.h b/lib/intprops.h index b473052d114..d0bb7a6f577 100644 --- a/lib/intprops.h +++ b/lib/intprops.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* intprops.h -- properties of integer types | 1 | /* intprops.h -- properties of integer types |
| 2 | 2 | ||
| 3 | Copyright (C) 2001-2005, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2001-2005, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -89,7 +89,8 @@ | |||
| 89 | 89 | ||
| 90 | /* Return 1 if the __typeof__ keyword works. This could be done by | 90 | /* Return 1 if the __typeof__ keyword works. This could be done by |
| 91 | 'configure', but for now it's easier to do it by hand. */ | 91 | 'configure', but for now it's easier to do it by hand. */ |
| 92 | #if 2 <= __GNUC__ || 0x5110 <= __SUNPRO_C | 92 | #if (2 <= __GNUC__ || defined __IBM__TYPEOF__ \ |
| 93 | || (0x5110 <= __SUNPRO_C && !__STDC__)) | ||
| 93 | # define _GL_HAVE___TYPEOF__ 1 | 94 | # define _GL_HAVE___TYPEOF__ 1 |
| 94 | #else | 95 | #else |
| 95 | # define _GL_HAVE___TYPEOF__ 0 | 96 | # define _GL_HAVE___TYPEOF__ 0 |
diff --git a/lib/inttypes.in.h b/lib/inttypes.in.h index 1893f5569d3..4b2a13be1da 100644 --- a/lib/inttypes.in.h +++ b/lib/inttypes.in.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* Copyright (C) 2006-2013 Free Software Foundation, Inc. | 1 | /* Copyright (C) 2006-2014 Free Software Foundation, Inc. |
| 2 | Written by Paul Eggert, Bruno Haible, Derek Price. | 2 | Written by Paul Eggert, Bruno Haible, Derek Price. |
| 3 | This file is part of gnulib. | 3 | This file is part of gnulib. |
| 4 | 4 | ||
| @@ -1105,12 +1105,22 @@ _GL_WARN_ON_USE (strtoimax, "strtoimax is unportable - " | |||
| 1105 | #endif | 1105 | #endif |
| 1106 | 1106 | ||
| 1107 | #if @GNULIB_STRTOUMAX@ | 1107 | #if @GNULIB_STRTOUMAX@ |
| 1108 | # if !@HAVE_DECL_STRTOUMAX@ | 1108 | # if @REPLACE_STRTOUMAX@ |
| 1109 | # undef strtoumax | 1109 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1110 | # undef strtoumax | ||
| 1111 | # define strtoumax rpl_strtoumax | ||
| 1112 | # endif | ||
| 1113 | _GL_FUNCDECL_RPL (strtoumax, uintmax_t, | ||
| 1114 | (const char *, char **, int) _GL_ARG_NONNULL ((1))); | ||
| 1115 | _GL_CXXALIAS_RPL (strtoumax, uintmax_t, (const char *, char **, int)); | ||
| 1116 | # else | ||
| 1117 | # if !@HAVE_DECL_STRTOUMAX@ | ||
| 1118 | # undef strtoumax | ||
| 1110 | _GL_FUNCDECL_SYS (strtoumax, uintmax_t, | 1119 | _GL_FUNCDECL_SYS (strtoumax, uintmax_t, |
| 1111 | (const char *, char **, int) _GL_ARG_NONNULL ((1))); | 1120 | (const char *, char **, int) _GL_ARG_NONNULL ((1))); |
| 1112 | # endif | 1121 | # endif |
| 1113 | _GL_CXXALIAS_SYS (strtoumax, uintmax_t, (const char *, char **, int)); | 1122 | _GL_CXXALIAS_SYS (strtoumax, uintmax_t, (const char *, char **, int)); |
| 1123 | # endif | ||
| 1114 | _GL_CXXALIASWARN (strtoumax); | 1124 | _GL_CXXALIASWARN (strtoumax); |
| 1115 | #elif defined GNULIB_POSIXCHECK | 1125 | #elif defined GNULIB_POSIXCHECK |
| 1116 | # undef strtoumax | 1126 | # undef strtoumax |
diff --git a/lib/lstat.c b/lib/lstat.c index 1a613a89c8d..f70fd435c03 100644 --- a/lib/lstat.c +++ b/lib/lstat.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Work around a bug of lstat on some systems | 1 | /* Work around a bug of lstat on some systems |
| 2 | 2 | ||
| 3 | Copyright (C) 1997-2006, 2008-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 1997-2006, 2008-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/makefile.w32-in b/lib/makefile.w32-in index cd62fbcd13d..bf624e6abfb 100644 --- a/lib/makefile.w32-in +++ b/lib/makefile.w32-in | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | # -*- Makefile -*- for GNU Emacs on the Microsoft Windows API. | 1 | # -*- Makefile -*- for GNU Emacs on the Microsoft Windows API. |
| 2 | # Copyright (C) 2011-2013 Free Software Foundation, Inc. | 2 | # Copyright (C) 2011-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | # This file is part of GNU Emacs. | 4 | # This file is part of GNU Emacs. |
| 5 | 5 | ||
| @@ -23,7 +23,8 @@ ALL = gnulib | |||
| 23 | LOCAL_FLAGS = -I. -I../nt/inc -I../src | 23 | LOCAL_FLAGS = -I. -I../nt/inc -I../src |
| 24 | LIBS = | 24 | LIBS = |
| 25 | 25 | ||
| 26 | GNULIBOBJS = $(BLD)/c-ctype.$(O) \ | 26 | GNULIBOBJS = $(BLD)/acl-errno-valid.$(O) \ |
| 27 | $(BLD)/c-ctype.$(O) \ | ||
| 27 | $(BLD)/c-strcasecmp.$(O) \ | 28 | $(BLD)/c-strcasecmp.$(O) \ |
| 28 | $(BLD)/c-strncasecmp.$(O) \ | 29 | $(BLD)/c-strncasecmp.$(O) \ |
| 29 | $(BLD)/close-stream.$(O) \ | 30 | $(BLD)/close-stream.$(O) \ |
| @@ -77,6 +78,9 @@ GNU_LIB = . | |||
| 77 | SRC = $(EMACS_ROOT)/src | 78 | SRC = $(EMACS_ROOT)/src |
| 78 | NT_INC = $(EMACS_ROOT)/nt/inc | 79 | NT_INC = $(EMACS_ROOT)/nt/inc |
| 79 | 80 | ||
| 81 | ACL_H = $(GNU_LIB)/acl.h \ | ||
| 82 | $(NT_INC)/sys/stat.h \ | ||
| 83 | $(NT_INC)/stdbool.h | ||
| 80 | C_CTYPE_H = $(GNU_LIB)/c-ctype.h \ | 84 | C_CTYPE_H = $(GNU_LIB)/c-ctype.h \ |
| 81 | $(NT_INC)/stdbool.h | 85 | $(NT_INC)/stdbool.h |
| 82 | MS_W32_H = $(NT_INC)/ms-w32.h \ | 86 | MS_W32_H = $(NT_INC)/ms-w32.h \ |
| @@ -109,6 +113,11 @@ SIG2STR_H = $(GNU_LIB)/sig2str.h \ | |||
| 109 | STAT_TIME_H = $(GNU_LIB)/stat-time.h \ | 113 | STAT_TIME_H = $(GNU_LIB)/stat-time.h \ |
| 110 | $(NT_INC)/sys/stat.h | 114 | $(NT_INC)/sys/stat.h |
| 111 | 115 | ||
| 116 | $(BLD)/acl-errno-valid.$(O) : \ | ||
| 117 | $(GNU_LIB)/acl-errno-valid.c \ | ||
| 118 | $(ACL_H) \ | ||
| 119 | $(CONFIG_H) | ||
| 120 | |||
| 112 | $(BLD)/c-ctype.$(O) : \ | 121 | $(BLD)/c-ctype.$(O) : \ |
| 113 | $(GNU_LIB)/c-ctype.c \ | 122 | $(GNU_LIB)/c-ctype.c \ |
| 114 | $(CONFIG_H) \ | 123 | $(CONFIG_H) \ |
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Functions to compute MD5 message digest of files or memory blocks. | 1 | /* Functions to compute MD5 message digest of files or memory blocks. |
| 2 | according to the definition of MD5 in RFC 1321 from April 1992. | 2 | according to the definition of MD5 in RFC 1321 from April 1992. |
| 3 | Copyright (C) 1995-1997, 1999-2001, 2005-2006, 2008-2013 Free Software | 3 | Copyright (C) 1995-1997, 1999-2001, 2005-2006, 2008-2014 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | This file is part of the GNU C Library. | 5 | This file is part of the GNU C Library. |
| 6 | 6 | ||
| @@ -21,6 +21,9 @@ | |||
| 21 | 21 | ||
| 22 | #include <config.h> | 22 | #include <config.h> |
| 23 | 23 | ||
| 24 | #if HAVE_OPENSSL_MD5 | ||
| 25 | # define GL_OPENSSL_INLINE _GL_EXTERN_INLINE | ||
| 26 | #endif | ||
| 24 | #include "md5.h" | 27 | #include "md5.h" |
| 25 | 28 | ||
| 26 | #include <stdalign.h> | 29 | #include <stdalign.h> |
| @@ -61,6 +64,7 @@ | |||
| 61 | # error "invalid BLOCKSIZE" | 64 | # error "invalid BLOCKSIZE" |
| 62 | #endif | 65 | #endif |
| 63 | 66 | ||
| 67 | #if ! HAVE_OPENSSL_MD5 | ||
| 64 | /* This array contains the bytes used to pad the buffer to the next | 68 | /* This array contains the bytes used to pad the buffer to the next |
| 65 | 64-byte boundary. (RFC 1321, 3.1: Step 1) */ | 69 | 64-byte boundary. (RFC 1321, 3.1: Step 1) */ |
| 66 | static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; | 70 | static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; |
| @@ -128,6 +132,7 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) | |||
| 128 | 132 | ||
| 129 | return md5_read_ctx (ctx, resbuf); | 133 | return md5_read_ctx (ctx, resbuf); |
| 130 | } | 134 | } |
| 135 | #endif | ||
| 131 | 136 | ||
| 132 | /* Compute MD5 message digest for bytes read from STREAM. The | 137 | /* Compute MD5 message digest for bytes read from STREAM. The |
| 133 | resulting message digest number will be written into the 16 bytes | 138 | resulting message digest number will be written into the 16 bytes |
| @@ -202,6 +207,7 @@ process_partial_block: | |||
| 202 | return 0; | 207 | return 0; |
| 203 | } | 208 | } |
| 204 | 209 | ||
| 210 | #if ! HAVE_OPENSSL_MD5 | ||
| 205 | /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The | 211 | /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The |
| 206 | result is always in little endian byte order, so that a byte-wise | 212 | result is always in little endian byte order, so that a byte-wise |
| 207 | output yields to the wanted ASCII representation of the message | 213 | output yields to the wanted ASCII representation of the message |
| @@ -459,3 +465,4 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx) | |||
| 459 | ctx->C = C; | 465 | ctx->C = C; |
| 460 | ctx->D = D; | 466 | ctx->D = D; |
| 461 | } | 467 | } |
| 468 | #endif | ||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Declaration of functions and data types used for MD5 sum computing | 1 | /* Declaration of functions and data types used for MD5 sum computing |
| 2 | library functions. | 2 | library functions. |
| 3 | Copyright (C) 1995-1997, 1999-2001, 2004-2006, 2008-2013 Free Software | 3 | Copyright (C) 1995-1997, 1999-2001, 2004-2006, 2008-2014 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | This file is part of the GNU C Library. | 5 | This file is part of the GNU C Library. |
| 6 | 6 | ||
| @@ -23,6 +23,10 @@ | |||
| 23 | #include <stdio.h> | 23 | #include <stdio.h> |
| 24 | #include <stdint.h> | 24 | #include <stdint.h> |
| 25 | 25 | ||
| 26 | # if HAVE_OPENSSL_MD5 | ||
| 27 | # include <openssl/md5.h> | ||
| 28 | # endif | ||
| 29 | |||
| 26 | #define MD5_DIGEST_SIZE 16 | 30 | #define MD5_DIGEST_SIZE 16 |
| 27 | #define MD5_BLOCK_SIZE 64 | 31 | #define MD5_BLOCK_SIZE 64 |
| 28 | 32 | ||
| @@ -57,6 +61,10 @@ | |||
| 57 | extern "C" { | 61 | extern "C" { |
| 58 | # endif | 62 | # endif |
| 59 | 63 | ||
| 64 | # if HAVE_OPENSSL_MD5 | ||
| 65 | # define GL_OPENSSL_NAME 5 | ||
| 66 | # include "gl_openssl.h" | ||
| 67 | # else | ||
| 60 | /* Structure to save state of computation between the single steps. */ | 68 | /* Structure to save state of computation between the single steps. */ |
| 61 | struct md5_ctx | 69 | struct md5_ctx |
| 62 | { | 70 | { |
| @@ -106,11 +114,6 @@ extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW; | |||
| 106 | extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW; | 114 | extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW; |
| 107 | 115 | ||
| 108 | 116 | ||
| 109 | /* Compute MD5 message digest for bytes read from STREAM. The | ||
| 110 | resulting message digest number will be written into the 16 bytes | ||
| 111 | beginning at RESBLOCK. */ | ||
| 112 | extern int __md5_stream (FILE *stream, void *resblock) __THROW; | ||
| 113 | |||
| 114 | /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The | 117 | /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The |
| 115 | result is always in little endian byte order, so that a byte-wise | 118 | result is always in little endian byte order, so that a byte-wise |
| 116 | output yields to the wanted ASCII representation of the message | 119 | output yields to the wanted ASCII representation of the message |
| @@ -118,6 +121,13 @@ extern int __md5_stream (FILE *stream, void *resblock) __THROW; | |||
| 118 | extern void *__md5_buffer (const char *buffer, size_t len, | 121 | extern void *__md5_buffer (const char *buffer, size_t len, |
| 119 | void *resblock) __THROW; | 122 | void *resblock) __THROW; |
| 120 | 123 | ||
| 124 | # endif | ||
| 125 | /* Compute MD5 message digest for bytes read from STREAM. The | ||
| 126 | resulting message digest number will be written into the 16 bytes | ||
| 127 | beginning at RESBLOCK. */ | ||
| 128 | extern int __md5_stream (FILE *stream, void *resblock) __THROW; | ||
| 129 | |||
| 130 | |||
| 121 | # ifdef __cplusplus | 131 | # ifdef __cplusplus |
| 122 | } | 132 | } |
| 123 | # endif | 133 | # endif |
diff --git a/lib/memrchr.c b/lib/memrchr.c index 5a023e0638a..742a0c9bfb5 100644 --- a/lib/memrchr.c +++ b/lib/memrchr.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* memrchr -- find the last occurrence of a byte in a memory block | 1 | /* memrchr -- find the last occurrence of a byte in a memory block |
| 2 | 2 | ||
| 3 | Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2013 Free Software | 3 | Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2014 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | 5 | ||
| 6 | Based on strlen implementation by Torbjorn Granlund (tege@sics.se), | 6 | Based on strlen implementation by Torbjorn Granlund (tege@sics.se), |
diff --git a/lib/mkostemp.c b/lib/mkostemp.c new file mode 100644 index 00000000000..94e5788b373 --- /dev/null +++ b/lib/mkostemp.c | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | /* Copyright (C) 1998-1999, 2001, 2005-2007, 2009-2014 Free Software | ||
| 2 | Foundation, Inc. | ||
| 3 | This file is derived from the one in the GNU C Library. | ||
| 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 !_LIBC | ||
| 19 | # include <config.h> | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #include <stdlib.h> | ||
| 23 | |||
| 24 | #if !_LIBC | ||
| 25 | # include "tempname.h" | ||
| 26 | # define __gen_tempname gen_tempname | ||
| 27 | # ifndef __GTFILE | ||
| 28 | # define __GT_FILE GT_FILE | ||
| 29 | # endif | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #include <stdio.h> | ||
| 33 | |||
| 34 | #ifndef __GT_FILE | ||
| 35 | # define __GT_FILE 0 | ||
| 36 | #endif | ||
| 37 | |||
| 38 | /* Generate a unique temporary file name from XTEMPLATE. | ||
| 39 | The last six characters of XTEMPLATE must be "XXXXXX"; | ||
| 40 | they are replaced with a string that makes the file name unique. | ||
| 41 | Then open the file and return a fd. */ | ||
| 42 | int | ||
| 43 | mkostemp (char *xtemplate, int flags) | ||
| 44 | { | ||
| 45 | return __gen_tempname (xtemplate, 0, flags, __GT_FILE); | ||
| 46 | } | ||
diff --git a/lib/mktime.c b/lib/mktime.c index e660a23c3be..29438237760 100644 --- a/lib/mktime.c +++ b/lib/mktime.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Convert a 'struct tm' to a time_t value. | 1 | /* Convert a 'struct tm' to a time_t value. |
| 2 | Copyright (C) 1993-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 1993-2014 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
| 4 | Contributed by Paul Eggert <eggert@twinsun.com>. | 4 | Contributed by Paul Eggert <eggert@twinsun.com>. |
| 5 | 5 | ||
diff --git a/lib/openat-priv.h b/lib/openat-priv.h index 829cf7d0855..326c739e5fd 100644 --- a/lib/openat-priv.h +++ b/lib/openat-priv.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Internals for openat-like functions. | 1 | /* Internals for openat-like functions. |
| 2 | 2 | ||
| 3 | Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2005-2006, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/openat-proc.c b/lib/openat-proc.c index d7a68e26d0b..6a4f6ad1cf1 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Create /proc/self/fd-related names for subfiles of open directories. | 1 | /* Create /proc/self/fd-related names for subfiles of open directories. |
| 2 | 2 | ||
| 3 | Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2006, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/openat.h b/lib/openat.h index eb90990da1d..29e23a547a5 100644 --- a/lib/openat.h +++ b/lib/openat.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* provide a replacement openat function | 1 | /* provide a replacement openat function |
| 2 | Copyright (C) 2004-2006, 2008-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2004-2006, 2008-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
| @@ -26,6 +26,9 @@ | |||
| 26 | #include <unistd.h> | 26 | #include <unistd.h> |
| 27 | #include <stdbool.h> | 27 | #include <stdbool.h> |
| 28 | 28 | ||
| 29 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 30 | #error "Please include config.h first." | ||
| 31 | #endif | ||
| 29 | _GL_INLINE_HEADER_BEGIN | 32 | _GL_INLINE_HEADER_BEGIN |
| 30 | 33 | ||
| 31 | #if !HAVE_OPENAT | 34 | #if !HAVE_OPENAT |
diff --git a/lib/pathmax.h b/lib/pathmax.h index a9ddc33d17f..33fc3553d75 100644 --- a/lib/pathmax.h +++ b/lib/pathmax.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Define PATH_MAX somehow. Requires sys/types.h. | 1 | /* Define PATH_MAX somehow. Requires sys/types.h. |
| 2 | Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2013 Free Software | 2 | Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2014 Free Software |
| 3 | Foundation, Inc. | 3 | Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
diff --git a/lib/pipe2.c b/lib/pipe2.c new file mode 100644 index 00000000000..61c42a0b5d2 --- /dev/null +++ b/lib/pipe2.c | |||
| @@ -0,0 +1,168 @@ | |||
| 1 | /* Create a pipe, with specific opening flags. | ||
| 2 | Copyright (C) 2009-2014 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, 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 along | ||
| 15 | with this program; if not, see <http://www.gnu.org/licenses/>. */ | ||
| 16 | |||
| 17 | #include <config.h> | ||
| 18 | |||
| 19 | /* Specification. */ | ||
| 20 | #include <unistd.h> | ||
| 21 | |||
| 22 | #include <errno.h> | ||
| 23 | #include <fcntl.h> | ||
| 24 | |||
| 25 | #include "binary-io.h" | ||
| 26 | #include "verify.h" | ||
| 27 | |||
| 28 | #if GNULIB_defined_O_NONBLOCK | ||
| 29 | # include "nonblocking.h" | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 33 | /* Native Windows API. */ | ||
| 34 | |||
| 35 | # include <io.h> | ||
| 36 | |||
| 37 | #endif | ||
| 38 | |||
| 39 | int | ||
| 40 | pipe2 (int fd[2], int flags) | ||
| 41 | { | ||
| 42 | /* Mingw _pipe() corrupts fd on failure; also, if we succeed at | ||
| 43 | creating the pipe but later fail at changing fcntl, we want | ||
| 44 | to leave fd unchanged: http://austingroupbugs.net/view.php?id=467 */ | ||
| 45 | int tmp[2]; | ||
| 46 | tmp[0] = fd[0]; | ||
| 47 | tmp[1] = fd[1]; | ||
| 48 | |||
| 49 | #if HAVE_PIPE2 | ||
| 50 | # undef pipe2 | ||
| 51 | /* Try the system call first, if it exists. (We may be running with a glibc | ||
| 52 | that has the function but with an older kernel that lacks it.) */ | ||
| 53 | { | ||
| 54 | /* Cache the information whether the system call really exists. */ | ||
| 55 | static int have_pipe2_really; /* 0 = unknown, 1 = yes, -1 = no */ | ||
| 56 | if (have_pipe2_really >= 0) | ||
| 57 | { | ||
| 58 | int result = pipe2 (fd, flags); | ||
| 59 | if (!(result < 0 && errno == ENOSYS)) | ||
| 60 | { | ||
| 61 | have_pipe2_really = 1; | ||
| 62 | return result; | ||
| 63 | } | ||
| 64 | have_pipe2_really = -1; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | #endif | ||
| 68 | |||
| 69 | /* Check the supported flags. */ | ||
| 70 | if ((flags & ~(O_CLOEXEC | O_NONBLOCK | O_BINARY | O_TEXT)) != 0) | ||
| 71 | { | ||
| 72 | errno = EINVAL; | ||
| 73 | return -1; | ||
| 74 | } | ||
| 75 | |||
| 76 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 77 | /* Native Windows API. */ | ||
| 78 | |||
| 79 | if (_pipe (fd, 4096, flags & ~O_NONBLOCK) < 0) | ||
| 80 | { | ||
| 81 | fd[0] = tmp[0]; | ||
| 82 | fd[1] = tmp[1]; | ||
| 83 | return -1; | ||
| 84 | } | ||
| 85 | |||
| 86 | /* O_NONBLOCK handling. | ||
| 87 | On native Windows platforms, O_NONBLOCK is defined by gnulib. Use the | ||
| 88 | functions defined by the gnulib module 'nonblocking'. */ | ||
| 89 | # if GNULIB_defined_O_NONBLOCK | ||
| 90 | if (flags & O_NONBLOCK) | ||
| 91 | { | ||
| 92 | if (set_nonblocking_flag (fd[0], true) != 0 | ||
| 93 | || set_nonblocking_flag (fd[1], true) != 0) | ||
| 94 | goto fail; | ||
| 95 | } | ||
| 96 | # else | ||
| 97 | { | ||
| 98 | verify (O_NONBLOCK == 0); | ||
| 99 | } | ||
| 100 | # endif | ||
| 101 | |||
| 102 | return 0; | ||
| 103 | |||
| 104 | #else | ||
| 105 | /* Unix API. */ | ||
| 106 | |||
| 107 | if (pipe (fd) < 0) | ||
| 108 | return -1; | ||
| 109 | |||
| 110 | /* POSIX <http://www.opengroup.org/onlinepubs/9699919799/functions/pipe.html> | ||
| 111 | says that initially, the O_NONBLOCK and FD_CLOEXEC flags are cleared on | ||
| 112 | both fd[0] and fd[1]. */ | ||
| 113 | |||
| 114 | /* O_NONBLOCK handling. | ||
| 115 | On Unix platforms, O_NONBLOCK is defined by the system. Use fcntl(). */ | ||
| 116 | if (flags & O_NONBLOCK) | ||
| 117 | { | ||
| 118 | int fcntl_flags; | ||
| 119 | |||
| 120 | if ((fcntl_flags = fcntl (fd[1], F_GETFL, 0)) < 0 | ||
| 121 | || fcntl (fd[1], F_SETFL, fcntl_flags | O_NONBLOCK) == -1 | ||
| 122 | || (fcntl_flags = fcntl (fd[0], F_GETFL, 0)) < 0 | ||
| 123 | || fcntl (fd[0], F_SETFL, fcntl_flags | O_NONBLOCK) == -1) | ||
| 124 | goto fail; | ||
| 125 | } | ||
| 126 | |||
| 127 | if (flags & O_CLOEXEC) | ||
| 128 | { | ||
| 129 | int fcntl_flags; | ||
| 130 | |||
| 131 | if ((fcntl_flags = fcntl (fd[1], F_GETFD, 0)) < 0 | ||
| 132 | || fcntl (fd[1], F_SETFD, fcntl_flags | FD_CLOEXEC) == -1 | ||
| 133 | || (fcntl_flags = fcntl (fd[0], F_GETFD, 0)) < 0 | ||
| 134 | || fcntl (fd[0], F_SETFD, fcntl_flags | FD_CLOEXEC) == -1) | ||
| 135 | goto fail; | ||
| 136 | } | ||
| 137 | |||
| 138 | # if O_BINARY | ||
| 139 | if (flags & O_BINARY) | ||
| 140 | { | ||
| 141 | set_binary_mode (fd[1], O_BINARY); | ||
| 142 | set_binary_mode (fd[0], O_BINARY); | ||
| 143 | } | ||
| 144 | else if (flags & O_TEXT) | ||
| 145 | { | ||
| 146 | set_binary_mode (fd[1], O_TEXT); | ||
| 147 | set_binary_mode (fd[0], O_TEXT); | ||
| 148 | } | ||
| 149 | # endif | ||
| 150 | |||
| 151 | return 0; | ||
| 152 | |||
| 153 | #endif | ||
| 154 | |||
| 155 | #if GNULIB_defined_O_NONBLOCK || \ | ||
| 156 | !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) | ||
| 157 | fail: | ||
| 158 | { | ||
| 159 | int saved_errno = errno; | ||
| 160 | close (fd[0]); | ||
| 161 | close (fd[1]); | ||
| 162 | fd[0] = tmp[0]; | ||
| 163 | fd[1] = tmp[1]; | ||
| 164 | errno = saved_errno; | ||
| 165 | return -1; | ||
| 166 | } | ||
| 167 | #endif | ||
| 168 | } | ||
diff --git a/lib/pselect.c b/lib/pselect.c index f4ea4883c39..695a3e84832 100644 --- a/lib/pselect.c +++ b/lib/pselect.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* pselect - synchronous I/O multiplexing | 1 | /* pselect - synchronous I/O multiplexing |
| 2 | 2 | ||
| 3 | Copyright 2011-2013 Free Software Foundation, Inc. | 3 | Copyright 2011-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of gnulib. | 5 | This file is part of gnulib. |
| 6 | 6 | ||
diff --git a/lib/pthread_sigmask.c b/lib/pthread_sigmask.c index 21919731ee4..19439348ca5 100644 --- a/lib/pthread_sigmask.c +++ b/lib/pthread_sigmask.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* POSIX compatible signal blocking for threads. | 1 | /* POSIX compatible signal blocking for threads. |
| 2 | Copyright (C) 2011-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/putenv.c b/lib/putenv.c index ed666afc3bb..b9f507926cb 100644 --- a/lib/putenv.c +++ b/lib/putenv.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* Copyright (C) 1991, 1994, 1997-1998, 2000, 2003-2013 Free Software | 1 | /* Copyright (C) 1991, 1994, 1997-1998, 2000, 2003-2014 Free Software |
| 2 | Foundation, Inc. | 2 | Foundation, Inc. |
| 3 | 3 | ||
| 4 | NOTE: The canonical source of this file is maintained with the GNU C | 4 | NOTE: The canonical source of this file is maintained with the GNU C |
| @@ -62,7 +62,9 @@ static int | |||
| 62 | _unsetenv (const char *name) | 62 | _unsetenv (const char *name) |
| 63 | { | 63 | { |
| 64 | size_t len; | 64 | size_t len; |
| 65 | #if !HAVE_DECL__PUTENV | ||
| 65 | char **ep; | 66 | char **ep; |
| 67 | #endif | ||
| 66 | 68 | ||
| 67 | if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) | 69 | if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) |
| 68 | { | 70 | { |
| @@ -72,7 +74,7 @@ _unsetenv (const char *name) | |||
| 72 | 74 | ||
| 73 | len = strlen (name); | 75 | len = strlen (name); |
| 74 | 76 | ||
| 75 | #if HAVE__PUTENV | 77 | #if HAVE_DECL__PUTENV |
| 76 | { | 78 | { |
| 77 | int putenv_result, putenv_errno; | 79 | int putenv_result, putenv_errno; |
| 78 | char *name_ = malloc (len + 2); | 80 | char *name_ = malloc (len + 2); |
| @@ -125,46 +127,46 @@ putenv (char *string) | |||
| 125 | return _unsetenv (string); | 127 | return _unsetenv (string); |
| 126 | } | 128 | } |
| 127 | 129 | ||
| 128 | #if HAVE__PUTENV | 130 | #if HAVE_DECL__PUTENV |
| 129 | /* Rely on _putenv to allocate the new environment. If other | 131 | /* Rely on _putenv to allocate the new environment. If other |
| 130 | parts of the application use _putenv, the !HAVE__PUTENV code | 132 | parts of the application use _putenv, the !HAVE_DECL__PUTENV code |
| 131 | would fight over who owns the environ vector, causing a crash. */ | 133 | would fight over who owns the environ vector, causing a crash. */ |
| 132 | if (name_end[1]) | 134 | if (name_end[1]) |
| 133 | return _putenv (string); | 135 | return _putenv (string); |
| 134 | else | 136 | else |
| 135 | { | 137 | { |
| 136 | /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ") | 138 | /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ") |
| 137 | to allocate the environ vector and then replace the new | 139 | to allocate the environ vector and then replace the new |
| 138 | entry with "NAME=". */ | 140 | entry with "NAME=". */ |
| 139 | int putenv_result, putenv_errno; | 141 | int putenv_result, putenv_errno; |
| 140 | char *name_x = malloc (name_end - string + sizeof "= "); | 142 | char *name_x = malloc (name_end - string + sizeof "= "); |
| 141 | if (!name_x) | 143 | if (!name_x) |
| 142 | return -1; | 144 | return -1; |
| 143 | memcpy (name_x, string, name_end - string + 1); | 145 | memcpy (name_x, string, name_end - string + 1); |
| 144 | name_x[name_end - string + 1] = ' '; | 146 | name_x[name_end - string + 1] = ' '; |
| 145 | name_x[name_end - string + 2] = 0; | 147 | name_x[name_end - string + 2] = 0; |
| 146 | putenv_result = _putenv (name_x); | 148 | putenv_result = _putenv (name_x); |
| 147 | putenv_errno = errno; | 149 | putenv_errno = errno; |
| 148 | for (ep = environ; *ep; ep++) | 150 | for (ep = environ; *ep; ep++) |
| 149 | if (strcmp (*ep, name_x) == 0) | 151 | if (strcmp (*ep, name_x) == 0) |
| 150 | { | 152 | { |
| 151 | *ep = string; | 153 | *ep = string; |
| 152 | break; | 154 | break; |
| 153 | } | 155 | } |
| 154 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | 156 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
| 155 | if (putenv_result == 0) | 157 | if (putenv_result == 0) |
| 156 | { | 158 | { |
| 157 | /* _putenv propagated "NAME= " into the subprocess environment; | 159 | /* _putenv propagated "NAME= " into the subprocess environment; |
| 158 | fix that by calling SetEnvironmentVariable directly. */ | 160 | fix that by calling SetEnvironmentVariable directly. */ |
| 159 | name_x[name_end - string] = 0; | 161 | name_x[name_end - string] = 0; |
| 160 | putenv_result = SetEnvironmentVariable (name_x, "") ? 0 : -1; | 162 | putenv_result = SetEnvironmentVariable (name_x, "") ? 0 : -1; |
| 161 | putenv_errno = ENOMEM; /* ENOMEM is the only way to fail. */ | 163 | putenv_errno = ENOMEM; /* ENOMEM is the only way to fail. */ |
| 162 | } | ||
| 163 | # endif | ||
| 164 | free (name_x); | ||
| 165 | __set_errno (putenv_errno); | ||
| 166 | return putenv_result; | ||
| 167 | } | 164 | } |
| 165 | # endif | ||
| 166 | free (name_x); | ||
| 167 | __set_errno (putenv_errno); | ||
| 168 | return putenv_result; | ||
| 169 | } | ||
| 168 | #else | 170 | #else |
| 169 | for (ep = environ; *ep; ep++) | 171 | for (ep = environ; *ep; ep++) |
| 170 | if (strncmp (*ep, string, name_end - string) == 0 | 172 | if (strncmp (*ep, string, name_end - string) == 0 |
| @@ -186,7 +188,7 @@ putenv (char *string) | |||
| 186 | last_environ = new_environ; | 188 | last_environ = new_environ; |
| 187 | environ = new_environ; | 189 | environ = new_environ; |
| 188 | } | 190 | } |
| 189 | #endif | ||
| 190 | 191 | ||
| 191 | return 0; | 192 | return 0; |
| 193 | #endif | ||
| 192 | } | 194 | } |
diff --git a/lib/qcopy-acl.c b/lib/qcopy-acl.c new file mode 100644 index 00000000000..4e53b6331a4 --- /dev/null +++ b/lib/qcopy-acl.c | |||
| @@ -0,0 +1,583 @@ | |||
| 1 | /* copy-acl.c - copy access control list from one file to another file | ||
| 2 | |||
| 3 | Copyright (C) 2002-2003, 2005-2014 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 | Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible. */ | ||
| 19 | |||
| 20 | #include <config.h> | ||
| 21 | |||
| 22 | #include "acl.h" | ||
| 23 | |||
| 24 | #include "acl-internal.h" | ||
| 25 | |||
| 26 | |||
| 27 | /* Copy access control lists from one file to another. If SOURCE_DESC is | ||
| 28 | a valid file descriptor, use file descriptor operations, else use | ||
| 29 | filename based operations on SRC_NAME. Likewise for DEST_DESC and | ||
| 30 | DST_NAME. | ||
| 31 | If access control lists are not available, fchmod the target file to | ||
| 32 | MODE. Also sets the non-permission bits of the destination file | ||
| 33 | (S_ISUID, S_ISGID, S_ISVTX) to those from MODE if any are set. | ||
| 34 | Return 0 if successful. | ||
| 35 | Return -2 and set errno for an error relating to the source file. | ||
| 36 | Return -1 and set errno for an error relating to the destination file. */ | ||
| 37 | |||
| 38 | int | ||
| 39 | qcopy_acl (const char *src_name, int source_desc, const char *dst_name, | ||
| 40 | int dest_desc, mode_t mode) | ||
| 41 | { | ||
| 42 | #if USE_ACL && HAVE_ACL_GET_FILE | ||
| 43 | /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ | ||
| 44 | /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ | ||
| 45 | # if !HAVE_ACL_TYPE_EXTENDED | ||
| 46 | /* Linux, FreeBSD, IRIX, Tru64 */ | ||
| 47 | |||
| 48 | acl_t acl; | ||
| 49 | int ret; | ||
| 50 | |||
| 51 | if (HAVE_ACL_GET_FD && source_desc != -1) | ||
| 52 | acl = acl_get_fd (source_desc); | ||
| 53 | else | ||
| 54 | acl = acl_get_file (src_name, ACL_TYPE_ACCESS); | ||
| 55 | if (acl == NULL) | ||
| 56 | { | ||
| 57 | if (! acl_errno_valid (errno)) | ||
| 58 | return qset_acl (dst_name, dest_desc, mode); | ||
| 59 | else | ||
| 60 | return -2; | ||
| 61 | } | ||
| 62 | |||
| 63 | if (HAVE_ACL_SET_FD && dest_desc != -1) | ||
| 64 | ret = acl_set_fd (dest_desc, acl); | ||
| 65 | else | ||
| 66 | ret = acl_set_file (dst_name, ACL_TYPE_ACCESS, acl); | ||
| 67 | if (ret != 0) | ||
| 68 | { | ||
| 69 | int saved_errno = errno; | ||
| 70 | |||
| 71 | if (! acl_errno_valid (errno) && !acl_access_nontrivial (acl)) | ||
| 72 | { | ||
| 73 | acl_free (acl); | ||
| 74 | return chmod_or_fchmod (dst_name, dest_desc, mode); | ||
| 75 | } | ||
| 76 | else | ||
| 77 | { | ||
| 78 | acl_free (acl); | ||
| 79 | chmod_or_fchmod (dst_name, dest_desc, mode); | ||
| 80 | errno = saved_errno; | ||
| 81 | return -1; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | else | ||
| 85 | acl_free (acl); | ||
| 86 | |||
| 87 | if (!MODE_INSIDE_ACL || (mode & (S_ISUID | S_ISGID | S_ISVTX))) | ||
| 88 | { | ||
| 89 | /* We did not call chmod so far, and either the mode and the ACL are | ||
| 90 | separate or special bits are to be set which don't fit into ACLs. */ | ||
| 91 | |||
| 92 | if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) | ||
| 93 | return -1; | ||
| 94 | } | ||
| 95 | |||
| 96 | if (S_ISDIR (mode)) | ||
| 97 | { | ||
| 98 | acl = acl_get_file (src_name, ACL_TYPE_DEFAULT); | ||
| 99 | if (acl == NULL) | ||
| 100 | return -2; | ||
| 101 | |||
| 102 | if (acl_set_file (dst_name, ACL_TYPE_DEFAULT, acl)) | ||
| 103 | { | ||
| 104 | int saved_errno = errno; | ||
| 105 | |||
| 106 | acl_free (acl); | ||
| 107 | errno = saved_errno; | ||
| 108 | return -1; | ||
| 109 | } | ||
| 110 | else | ||
| 111 | acl_free (acl); | ||
| 112 | } | ||
| 113 | return 0; | ||
| 114 | |||
| 115 | # else /* HAVE_ACL_TYPE_EXTENDED */ | ||
| 116 | /* Mac OS X */ | ||
| 117 | |||
| 118 | /* On Mac OS X, acl_get_file (name, ACL_TYPE_ACCESS) | ||
| 119 | and acl_get_file (name, ACL_TYPE_DEFAULT) | ||
| 120 | always return NULL / EINVAL. You have to use | ||
| 121 | acl_get_file (name, ACL_TYPE_EXTENDED) | ||
| 122 | or acl_get_fd (open (name, ...)) | ||
| 123 | to retrieve an ACL. | ||
| 124 | On the other hand, | ||
| 125 | acl_set_file (name, ACL_TYPE_ACCESS, acl) | ||
| 126 | and acl_set_file (name, ACL_TYPE_DEFAULT, acl) | ||
| 127 | have the same effect as | ||
| 128 | acl_set_file (name, ACL_TYPE_EXTENDED, acl): | ||
| 129 | Each of these calls sets the file's ACL. */ | ||
| 130 | |||
| 131 | acl_t acl; | ||
| 132 | int ret; | ||
| 133 | |||
| 134 | if (HAVE_ACL_GET_FD && source_desc != -1) | ||
| 135 | acl = acl_get_fd (source_desc); | ||
| 136 | else | ||
| 137 | acl = acl_get_file (src_name, ACL_TYPE_EXTENDED); | ||
| 138 | if (acl == NULL) | ||
| 139 | { | ||
| 140 | if (!acl_errno_valid (errno)) | ||
| 141 | return qset_acl (dst_name, dest_desc, mode); | ||
| 142 | else | ||
| 143 | return -2; | ||
| 144 | } | ||
| 145 | |||
| 146 | if (HAVE_ACL_SET_FD && dest_desc != -1) | ||
| 147 | ret = acl_set_fd (dest_desc, acl); | ||
| 148 | else | ||
| 149 | ret = acl_set_file (dst_name, ACL_TYPE_EXTENDED, acl); | ||
| 150 | if (ret != 0) | ||
| 151 | { | ||
| 152 | int saved_errno = errno; | ||
| 153 | |||
| 154 | if (!acl_errno_valid (saved_errno) && !acl_extended_nontrivial (acl)) | ||
| 155 | { | ||
| 156 | acl_free (acl); | ||
| 157 | return chmod_or_fchmod (dst_name, dest_desc, mode); | ||
| 158 | } | ||
| 159 | else | ||
| 160 | { | ||
| 161 | acl_free (acl); | ||
| 162 | chmod_or_fchmod (dst_name, dest_desc, mode); | ||
| 163 | errno = saved_errno; | ||
| 164 | return -1; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | else | ||
| 168 | acl_free (acl); | ||
| 169 | |||
| 170 | /* Since !MODE_INSIDE_ACL, we have to call chmod explicitly. */ | ||
| 171 | return chmod_or_fchmod (dst_name, dest_desc, mode); | ||
| 172 | |||
| 173 | # endif | ||
| 174 | |||
| 175 | #elif USE_ACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ | ||
| 176 | |||
| 177 | /* Solaris 2.5 through Solaris 10, Cygwin, and contemporaneous versions | ||
| 178 | of Unixware. The acl() call returns the access and default ACL both | ||
| 179 | at once. */ | ||
| 180 | # ifdef ACE_GETACL | ||
| 181 | int ace_count; | ||
| 182 | ace_t *ace_entries; | ||
| 183 | # endif | ||
| 184 | int count; | ||
| 185 | aclent_t *entries; | ||
| 186 | int did_chmod; | ||
| 187 | int saved_errno; | ||
| 188 | int ret; | ||
| 189 | |||
| 190 | # ifdef ACE_GETACL | ||
| 191 | /* Solaris also has a different variant of ACLs, used in ZFS and NFSv4 | ||
| 192 | file systems (whereas the other ones are used in UFS file systems). | ||
| 193 | There is an API | ||
| 194 | pathconf (name, _PC_ACL_ENABLED) | ||
| 195 | fpathconf (desc, _PC_ACL_ENABLED) | ||
| 196 | that allows to determine which of the two kinds of ACLs is supported | ||
| 197 | for the given file. But some file systems may implement this call | ||
| 198 | incorrectly, so better not use it. | ||
| 199 | When fetching the source ACL, we simply fetch both ACL types. | ||
| 200 | When setting the destination ACL, we try either ACL types, assuming | ||
| 201 | that the kernel will translate the ACL from one form to the other. | ||
| 202 | (See in <http://docs.sun.com/app/docs/doc/819-2241/6n4huc7ia?l=en&a=view> | ||
| 203 | the description of ENOTSUP.) */ | ||
| 204 | for (;;) | ||
| 205 | { | ||
| 206 | ace_count = (source_desc != -1 | ||
| 207 | ? facl (source_desc, ACE_GETACLCNT, 0, NULL) | ||
| 208 | : acl (src_name, ACE_GETACLCNT, 0, NULL)); | ||
| 209 | |||
| 210 | if (ace_count < 0) | ||
| 211 | { | ||
| 212 | if (errno == ENOSYS || errno == EINVAL) | ||
| 213 | { | ||
| 214 | ace_count = 0; | ||
| 215 | ace_entries = NULL; | ||
| 216 | break; | ||
| 217 | } | ||
| 218 | else | ||
| 219 | return -2; | ||
| 220 | } | ||
| 221 | |||
| 222 | if (ace_count == 0) | ||
| 223 | { | ||
| 224 | ace_entries = NULL; | ||
| 225 | break; | ||
| 226 | } | ||
| 227 | |||
| 228 | ace_entries = (ace_t *) malloc (ace_count * sizeof (ace_t)); | ||
| 229 | if (ace_entries == NULL) | ||
| 230 | { | ||
| 231 | errno = ENOMEM; | ||
| 232 | return -2; | ||
| 233 | } | ||
| 234 | |||
| 235 | ret = (source_desc != -1 | ||
| 236 | ? facl (source_desc, ACE_GETACL, ace_count, ace_entries) | ||
| 237 | : acl (src_name, ACE_GETACL, ace_count, ace_entries)); | ||
| 238 | if (ret < 0) | ||
| 239 | { | ||
| 240 | free (ace_entries); | ||
| 241 | if (errno == ENOSYS || errno == EINVAL) | ||
| 242 | { | ||
| 243 | ace_count = 0; | ||
| 244 | ace_entries = NULL; | ||
| 245 | break; | ||
| 246 | } | ||
| 247 | else | ||
| 248 | return -2; | ||
| 249 | } | ||
| 250 | if (ret == ace_count) | ||
| 251 | break; | ||
| 252 | /* Huh? The number of ACL entries changed since the last call. | ||
| 253 | Repeat. */ | ||
| 254 | } | ||
| 255 | # endif | ||
| 256 | |||
| 257 | for (;;) | ||
| 258 | { | ||
| 259 | count = (source_desc != -1 | ||
| 260 | ? facl (source_desc, GETACLCNT, 0, NULL) | ||
| 261 | : acl (src_name, GETACLCNT, 0, NULL)); | ||
| 262 | |||
| 263 | if (count < 0) | ||
| 264 | { | ||
| 265 | if (errno == ENOSYS || errno == ENOTSUP || errno == EOPNOTSUPP) | ||
| 266 | { | ||
| 267 | count = 0; | ||
| 268 | entries = NULL; | ||
| 269 | break; | ||
| 270 | } | ||
| 271 | else | ||
| 272 | return -2; | ||
| 273 | } | ||
| 274 | |||
| 275 | if (count == 0) | ||
| 276 | { | ||
| 277 | entries = NULL; | ||
| 278 | break; | ||
| 279 | } | ||
| 280 | |||
| 281 | entries = (aclent_t *) malloc (count * sizeof (aclent_t)); | ||
| 282 | if (entries == NULL) | ||
| 283 | { | ||
| 284 | errno = ENOMEM; | ||
| 285 | return -2; | ||
| 286 | } | ||
| 287 | |||
| 288 | if ((source_desc != -1 | ||
| 289 | ? facl (source_desc, GETACL, count, entries) | ||
| 290 | : acl (src_name, GETACL, count, entries)) | ||
| 291 | == count) | ||
| 292 | break; | ||
| 293 | /* Huh? The number of ACL entries changed since the last call. | ||
| 294 | Repeat. */ | ||
| 295 | } | ||
| 296 | |||
| 297 | /* Is there an ACL of either kind? */ | ||
| 298 | # ifdef ACE_GETACL | ||
| 299 | if (ace_count == 0) | ||
| 300 | # endif | ||
| 301 | if (count == 0) | ||
| 302 | return qset_acl (dst_name, dest_desc, mode); | ||
| 303 | |||
| 304 | did_chmod = 0; /* set to 1 once the mode bits in 0777 have been set */ | ||
| 305 | saved_errno = 0; /* the first non-ignorable error code */ | ||
| 306 | |||
| 307 | if (!MODE_INSIDE_ACL) | ||
| 308 | { | ||
| 309 | /* On Cygwin, it is necessary to call chmod before acl, because | ||
| 310 | chmod can change the contents of the ACL (in ways that don't | ||
| 311 | change the allowed accesses, but still visible). */ | ||
| 312 | if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) | ||
| 313 | saved_errno = errno; | ||
| 314 | did_chmod = 1; | ||
| 315 | } | ||
| 316 | |||
| 317 | /* If both ace_entries and entries are available, try SETACL before | ||
| 318 | ACE_SETACL, because SETACL cannot fail with ENOTSUP whereas ACE_SETACL | ||
| 319 | can. */ | ||
| 320 | |||
| 321 | if (count > 0) | ||
| 322 | { | ||
| 323 | ret = (dest_desc != -1 | ||
| 324 | ? facl (dest_desc, SETACL, count, entries) | ||
| 325 | : acl (dst_name, SETACL, count, entries)); | ||
| 326 | if (ret < 0 && saved_errno == 0) | ||
| 327 | { | ||
| 328 | saved_errno = errno; | ||
| 329 | if ((errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL) | ||
| 330 | && !acl_nontrivial (count, entries)) | ||
| 331 | saved_errno = 0; | ||
| 332 | } | ||
| 333 | else | ||
| 334 | did_chmod = 1; | ||
| 335 | } | ||
| 336 | free (entries); | ||
| 337 | |||
| 338 | # ifdef ACE_GETACL | ||
| 339 | if (ace_count > 0) | ||
| 340 | { | ||
| 341 | ret = (dest_desc != -1 | ||
| 342 | ? facl (dest_desc, ACE_SETACL, ace_count, ace_entries) | ||
| 343 | : acl (dst_name, ACE_SETACL, ace_count, ace_entries)); | ||
| 344 | if (ret < 0 && saved_errno == 0) | ||
| 345 | { | ||
| 346 | saved_errno = errno; | ||
| 347 | if ((errno == ENOSYS || errno == EINVAL || errno == ENOTSUP) | ||
| 348 | && !acl_ace_nontrivial (ace_count, ace_entries)) | ||
| 349 | saved_errno = 0; | ||
| 350 | } | ||
| 351 | } | ||
| 352 | free (ace_entries); | ||
| 353 | # endif | ||
| 354 | |||
| 355 | if (MODE_INSIDE_ACL | ||
| 356 | && did_chmod <= ((mode & (S_ISUID | S_ISGID | S_ISVTX)) ? 1 : 0)) | ||
| 357 | { | ||
| 358 | /* We did not call chmod so far, and either the mode and the ACL are | ||
| 359 | separate or special bits are to be set which don't fit into ACLs. */ | ||
| 360 | |||
| 361 | if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) | ||
| 362 | { | ||
| 363 | if (saved_errno == 0) | ||
| 364 | saved_errno = errno; | ||
| 365 | } | ||
| 366 | } | ||
| 367 | |||
| 368 | if (saved_errno) | ||
| 369 | { | ||
| 370 | errno = saved_errno; | ||
| 371 | return -1; | ||
| 372 | } | ||
| 373 | return 0; | ||
| 374 | |||
| 375 | #elif USE_ACL && HAVE_GETACL /* HP-UX */ | ||
| 376 | |||
| 377 | struct acl_entry entries[NACLENTRIES]; | ||
| 378 | int count; | ||
| 379 | # if HAVE_ACLV_H | ||
| 380 | struct acl aclv_entries[NACLVENTRIES]; | ||
| 381 | int aclv_count; | ||
| 382 | # endif | ||
| 383 | int did_chmod; | ||
| 384 | int saved_errno; | ||
| 385 | int ret; | ||
| 386 | |||
| 387 | count = (source_desc != -1 | ||
| 388 | ? fgetacl (source_desc, NACLENTRIES, entries) | ||
| 389 | : getacl (src_name, NACLENTRIES, entries)); | ||
| 390 | |||
| 391 | if (count < 0) | ||
| 392 | { | ||
| 393 | if (errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP) | ||
| 394 | count = 0; | ||
| 395 | else | ||
| 396 | return -2; | ||
| 397 | } | ||
| 398 | else if (count > 0) | ||
| 399 | { | ||
| 400 | if (count > NACLENTRIES) | ||
| 401 | /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */ | ||
| 402 | abort (); | ||
| 403 | } | ||
| 404 | |||
| 405 | # if HAVE_ACLV_H | ||
| 406 | aclv_count = acl ((char *) src_name, ACL_GET, NACLVENTRIES, aclv_entries); | ||
| 407 | |||
| 408 | if (aclv_count < 0) | ||
| 409 | { | ||
| 410 | if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL) | ||
| 411 | count = 0; | ||
| 412 | else | ||
| 413 | return -2; | ||
| 414 | } | ||
| 415 | else if (aclv_count > 0) | ||
| 416 | { | ||
| 417 | if (aclv_count > NACLVENTRIES) | ||
| 418 | /* If NACLVENTRIES cannot be trusted, use dynamic memory allocation. */ | ||
| 419 | abort (); | ||
| 420 | } | ||
| 421 | # endif | ||
| 422 | |||
| 423 | if (count == 0) | ||
| 424 | # if HAVE_ACLV_H | ||
| 425 | if (aclv_count == 0) | ||
| 426 | # endif | ||
| 427 | return qset_acl (dst_name, dest_desc, mode); | ||
| 428 | |||
| 429 | did_chmod = 0; /* set to 1 once the mode bits in 0777 have been set */ | ||
| 430 | saved_errno = 0; /* the first non-ignorable error code */ | ||
| 431 | |||
| 432 | if (count > 0) | ||
| 433 | { | ||
| 434 | ret = (dest_desc != -1 | ||
| 435 | ? fsetacl (dest_desc, count, entries) | ||
| 436 | : setacl (dst_name, count, entries)); | ||
| 437 | if (ret < 0 && saved_errno == 0) | ||
| 438 | { | ||
| 439 | saved_errno = errno; | ||
| 440 | if (errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP) | ||
| 441 | { | ||
| 442 | struct stat source_statbuf; | ||
| 443 | |||
| 444 | if ((source_desc != -1 | ||
| 445 | ? fstat (source_desc, &source_statbuf) | ||
| 446 | : stat (src_name, &source_statbuf)) == 0) | ||
| 447 | { | ||
| 448 | if (!acl_nontrivial (count, entries, &source_statbuf)) | ||
| 449 | saved_errno = 0; | ||
| 450 | } | ||
| 451 | else | ||
| 452 | saved_errno = errno; | ||
| 453 | } | ||
| 454 | } | ||
| 455 | else | ||
| 456 | did_chmod = 1; | ||
| 457 | } | ||
| 458 | |||
| 459 | # if HAVE_ACLV_H | ||
| 460 | if (aclv_count > 0) | ||
| 461 | { | ||
| 462 | ret = acl ((char *) dst_name, ACL_SET, aclv_count, aclv_entries); | ||
| 463 | if (ret < 0 && saved_errno == 0) | ||
| 464 | { | ||
| 465 | saved_errno = errno; | ||
| 466 | if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL) | ||
| 467 | { | ||
| 468 | if (!aclv_nontrivial (aclv_count, aclv_entries)) | ||
| 469 | saved_errno = 0; | ||
| 470 | } | ||
| 471 | } | ||
| 472 | else | ||
| 473 | did_chmod = 1; | ||
| 474 | } | ||
| 475 | # endif | ||
| 476 | |||
| 477 | if (did_chmod <= ((mode & (S_ISUID | S_ISGID | S_ISVTX)) ? 1 : 0)) | ||
| 478 | { | ||
| 479 | /* We did not call chmod so far, and special bits are to be set which | ||
| 480 | don't fit into ACLs. */ | ||
| 481 | |||
| 482 | if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) | ||
| 483 | { | ||
| 484 | if (saved_errno == 0) | ||
| 485 | saved_errno = errno; | ||
| 486 | } | ||
| 487 | } | ||
| 488 | |||
| 489 | if (saved_errno) | ||
| 490 | { | ||
| 491 | errno = saved_errno; | ||
| 492 | return -1; | ||
| 493 | } | ||
| 494 | return 0; | ||
| 495 | |||
| 496 | #elif USE_ACL && HAVE_ACLX_GET && 0 /* AIX */ | ||
| 497 | |||
| 498 | /* TODO */ | ||
| 499 | |||
| 500 | #elif USE_ACL && HAVE_STATACL /* older AIX */ | ||
| 501 | |||
| 502 | union { struct acl a; char room[4096]; } u; | ||
| 503 | int ret; | ||
| 504 | |||
| 505 | if ((source_desc != -1 | ||
| 506 | ? fstatacl (source_desc, STX_NORMAL, &u.a, sizeof (u)) | ||
| 507 | : statacl (src_name, STX_NORMAL, &u.a, sizeof (u))) | ||
| 508 | < 0) | ||
| 509 | return -2; | ||
| 510 | |||
| 511 | ret = (dest_desc != -1 | ||
| 512 | ? fchacl (dest_desc, &u.a, u.a.acl_len) | ||
| 513 | : chacl (dst_name, &u.a, u.a.acl_len)); | ||
| 514 | if (ret < 0) | ||
| 515 | { | ||
| 516 | int saved_errno = errno; | ||
| 517 | |||
| 518 | chmod_or_fchmod (dst_name, dest_desc, mode); | ||
| 519 | errno = saved_errno; | ||
| 520 | return -1; | ||
| 521 | } | ||
| 522 | |||
| 523 | /* No need to call chmod_or_fchmod at this point, since the mode bits | ||
| 524 | S_ISUID, S_ISGID, S_ISVTX are also stored in the ACL. */ | ||
| 525 | |||
| 526 | return 0; | ||
| 527 | |||
| 528 | #elif USE_ACL && HAVE_ACLSORT /* NonStop Kernel */ | ||
| 529 | |||
| 530 | struct acl entries[NACLENTRIES]; | ||
| 531 | int count; | ||
| 532 | int ret; | ||
| 533 | |||
| 534 | count = acl ((char *) src_name, ACL_GET, NACLENTRIES, entries); | ||
| 535 | |||
| 536 | if (count < 0) | ||
| 537 | { | ||
| 538 | if (0) | ||
| 539 | count = 0; | ||
| 540 | else | ||
| 541 | return -2; | ||
| 542 | } | ||
| 543 | else if (count > 0) | ||
| 544 | { | ||
| 545 | if (count > NACLENTRIES) | ||
| 546 | /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */ | ||
| 547 | abort (); | ||
| 548 | } | ||
| 549 | |||
| 550 | if (count == 0) | ||
| 551 | return qset_acl (dst_name, dest_desc, mode); | ||
| 552 | |||
| 553 | ret = acl ((char *) dst_name, ACL_SET, count, entries); | ||
| 554 | if (ret < 0) | ||
| 555 | { | ||
| 556 | int saved_errno = errno; | ||
| 557 | |||
| 558 | if (0) | ||
| 559 | { | ||
| 560 | if (!acl_nontrivial (count, entries)) | ||
| 561 | return chmod_or_fchmod (dst_name, dest_desc, mode); | ||
| 562 | } | ||
| 563 | |||
| 564 | chmod_or_fchmod (dst_name, dest_desc, mode); | ||
| 565 | errno = saved_errno; | ||
| 566 | return -1; | ||
| 567 | } | ||
| 568 | |||
| 569 | if (mode & (S_ISUID | S_ISGID | S_ISVTX)) | ||
| 570 | { | ||
| 571 | /* We did not call chmod so far, and either the mode and the ACL are | ||
| 572 | separate or special bits are to be set which don't fit into ACLs. */ | ||
| 573 | |||
| 574 | return chmod_or_fchmod (dst_name, dest_desc, mode); | ||
| 575 | } | ||
| 576 | return 0; | ||
| 577 | |||
| 578 | #else | ||
| 579 | |||
| 580 | return qset_acl (dst_name, dest_desc, mode); | ||
| 581 | |||
| 582 | #endif | ||
| 583 | } | ||
diff --git a/lib/qset-acl.c b/lib/qset-acl.c new file mode 100644 index 00000000000..7d9af573fbf --- /dev/null +++ b/lib/qset-acl.c | |||
| @@ -0,0 +1,676 @@ | |||
| 1 | /* qset-acl.c - set access control list equivalent to a mode | ||
| 2 | |||
| 3 | Copyright (C) 2002-2003, 2005-2014 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 | Written by Paul Eggert and Andreas Gruenbacher, and Bruno Haible. */ | ||
| 19 | |||
| 20 | #include <config.h> | ||
| 21 | |||
| 22 | #define ACL_INTERNAL_INLINE _GL_EXTERN_INLINE | ||
| 23 | |||
| 24 | #include "acl.h" | ||
| 25 | |||
| 26 | #include "acl-internal.h" | ||
| 27 | |||
| 28 | |||
| 29 | /* If DESC is a valid file descriptor use fchmod to change the | ||
| 30 | file's mode to MODE on systems that have fchmod. On systems | ||
| 31 | that don't have fchmod and if DESC is invalid, use chmod on | ||
| 32 | NAME instead. | ||
| 33 | Return 0 if successful. Return -1 and set errno upon failure. */ | ||
| 34 | |||
| 35 | int | ||
| 36 | chmod_or_fchmod (const char *name, int desc, mode_t mode) | ||
| 37 | { | ||
| 38 | if (HAVE_FCHMOD && desc != -1) | ||
| 39 | return fchmod (desc, mode); | ||
| 40 | else | ||
| 41 | return chmod (name, mode); | ||
| 42 | } | ||
| 43 | |||
| 44 | /* Set the access control lists of a file. If DESC is a valid file | ||
| 45 | descriptor, use file descriptor operations where available, else use | ||
| 46 | filename based operations on NAME. If access control lists are not | ||
| 47 | available, fchmod the target file to MODE. Also sets the | ||
| 48 | non-permission bits of the destination file (S_ISUID, S_ISGID, S_ISVTX) | ||
| 49 | to those from MODE if any are set. | ||
| 50 | Return 0 if successful. Return -1 and set errno upon failure. */ | ||
| 51 | |||
| 52 | int | ||
| 53 | qset_acl (char const *name, int desc, mode_t mode) | ||
| 54 | { | ||
| 55 | #if USE_ACL | ||
| 56 | # if HAVE_ACL_GET_FILE | ||
| 57 | /* POSIX 1003.1e draft 17 (abandoned) specific version. */ | ||
| 58 | /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ | ||
| 59 | # if !HAVE_ACL_TYPE_EXTENDED | ||
| 60 | /* Linux, FreeBSD, IRIX, Tru64 */ | ||
| 61 | |||
| 62 | /* We must also have acl_from_text and acl_delete_def_file. | ||
| 63 | (acl_delete_def_file could be emulated with acl_init followed | ||
| 64 | by acl_set_file, but acl_set_file with an empty acl is | ||
| 65 | unspecified.) */ | ||
| 66 | |||
| 67 | # ifndef HAVE_ACL_FROM_TEXT | ||
| 68 | # error Must have acl_from_text (see POSIX 1003.1e draft 17). | ||
| 69 | # endif | ||
| 70 | # ifndef HAVE_ACL_DELETE_DEF_FILE | ||
| 71 | # error Must have acl_delete_def_file (see POSIX 1003.1e draft 17). | ||
| 72 | # endif | ||
| 73 | |||
| 74 | acl_t acl; | ||
| 75 | int ret; | ||
| 76 | |||
| 77 | if (HAVE_ACL_FROM_MODE) /* Linux */ | ||
| 78 | { | ||
| 79 | acl = acl_from_mode (mode); | ||
| 80 | if (!acl) | ||
| 81 | return -1; | ||
| 82 | } | ||
| 83 | else /* FreeBSD, IRIX, Tru64 */ | ||
| 84 | { | ||
| 85 | /* If we were to create the ACL using the functions acl_init(), | ||
| 86 | acl_create_entry(), acl_set_tag_type(), acl_set_qualifier(), | ||
| 87 | acl_get_permset(), acl_clear_perm[s](), acl_add_perm(), we | ||
| 88 | would need to create a qualifier. I don't know how to do this. | ||
| 89 | So create it using acl_from_text(). */ | ||
| 90 | |||
| 91 | # if HAVE_ACL_FREE_TEXT /* Tru64 */ | ||
| 92 | char acl_text[] = "u::---,g::---,o::---,"; | ||
| 93 | # else /* FreeBSD, IRIX */ | ||
| 94 | char acl_text[] = "u::---,g::---,o::---"; | ||
| 95 | # endif | ||
| 96 | |||
| 97 | if (mode & S_IRUSR) acl_text[ 3] = 'r'; | ||
| 98 | if (mode & S_IWUSR) acl_text[ 4] = 'w'; | ||
| 99 | if (mode & S_IXUSR) acl_text[ 5] = 'x'; | ||
| 100 | if (mode & S_IRGRP) acl_text[10] = 'r'; | ||
| 101 | if (mode & S_IWGRP) acl_text[11] = 'w'; | ||
| 102 | if (mode & S_IXGRP) acl_text[12] = 'x'; | ||
| 103 | if (mode & S_IROTH) acl_text[17] = 'r'; | ||
| 104 | if (mode & S_IWOTH) acl_text[18] = 'w'; | ||
| 105 | if (mode & S_IXOTH) acl_text[19] = 'x'; | ||
| 106 | |||
| 107 | acl = acl_from_text (acl_text); | ||
| 108 | if (!acl) | ||
| 109 | return -1; | ||
| 110 | } | ||
| 111 | if (HAVE_ACL_SET_FD && desc != -1) | ||
| 112 | ret = acl_set_fd (desc, acl); | ||
| 113 | else | ||
| 114 | ret = acl_set_file (name, ACL_TYPE_ACCESS, acl); | ||
| 115 | if (ret != 0) | ||
| 116 | { | ||
| 117 | int saved_errno = errno; | ||
| 118 | acl_free (acl); | ||
| 119 | if (! acl_errno_valid (errno)) | ||
| 120 | return chmod_or_fchmod (name, desc, mode); | ||
| 121 | errno = saved_errno; | ||
| 122 | return -1; | ||
| 123 | } | ||
| 124 | else | ||
| 125 | acl_free (acl); | ||
| 126 | |||
| 127 | if (S_ISDIR (mode) && acl_delete_def_file (name)) | ||
| 128 | return -1; | ||
| 129 | |||
| 130 | if (!MODE_INSIDE_ACL || (mode & (S_ISUID | S_ISGID | S_ISVTX))) | ||
| 131 | { | ||
| 132 | /* We did not call chmod so far, and either the mode and the ACL are | ||
| 133 | separate or special bits are to be set which don't fit into ACLs. */ | ||
| 134 | return chmod_or_fchmod (name, desc, mode); | ||
| 135 | } | ||
| 136 | return 0; | ||
| 137 | |||
| 138 | # else /* HAVE_ACL_TYPE_EXTENDED */ | ||
| 139 | /* Mac OS X */ | ||
| 140 | |||
| 141 | /* On Mac OS X, acl_get_file (name, ACL_TYPE_ACCESS) | ||
| 142 | and acl_get_file (name, ACL_TYPE_DEFAULT) | ||
| 143 | always return NULL / EINVAL. You have to use | ||
| 144 | acl_get_file (name, ACL_TYPE_EXTENDED) | ||
| 145 | or acl_get_fd (open (name, ...)) | ||
| 146 | to retrieve an ACL. | ||
| 147 | On the other hand, | ||
| 148 | acl_set_file (name, ACL_TYPE_ACCESS, acl) | ||
| 149 | and acl_set_file (name, ACL_TYPE_DEFAULT, acl) | ||
| 150 | have the same effect as | ||
| 151 | acl_set_file (name, ACL_TYPE_EXTENDED, acl): | ||
| 152 | Each of these calls sets the file's ACL. */ | ||
| 153 | |||
| 154 | acl_t acl; | ||
| 155 | int ret; | ||
| 156 | |||
| 157 | /* Remove the ACL if the file has ACLs. */ | ||
| 158 | if (HAVE_ACL_GET_FD && desc != -1) | ||
| 159 | acl = acl_get_fd (desc); | ||
| 160 | else | ||
| 161 | acl = acl_get_file (name, ACL_TYPE_EXTENDED); | ||
| 162 | if (acl) | ||
| 163 | { | ||
| 164 | acl_free (acl); | ||
| 165 | |||
| 166 | acl = acl_init (0); | ||
| 167 | if (acl) | ||
| 168 | { | ||
| 169 | if (HAVE_ACL_SET_FD && desc != -1) | ||
| 170 | ret = acl_set_fd (desc, acl); | ||
| 171 | else | ||
| 172 | ret = acl_set_file (name, ACL_TYPE_EXTENDED, acl); | ||
| 173 | if (ret != 0) | ||
| 174 | { | ||
| 175 | int saved_errno = errno; | ||
| 176 | acl_free (acl); | ||
| 177 | if (! acl_errno_valid (saved_errno)) | ||
| 178 | return chmod_or_fchmod (name, desc, mode); | ||
| 179 | errno = saved_errno; | ||
| 180 | return -1; | ||
| 181 | } | ||
| 182 | acl_free (acl); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | /* Since !MODE_INSIDE_ACL, we have to call chmod explicitly. */ | ||
| 187 | return chmod_or_fchmod (name, desc, mode); | ||
| 188 | # endif | ||
| 189 | |||
| 190 | # elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ | ||
| 191 | |||
| 192 | int done_setacl = 0; | ||
| 193 | |||
| 194 | # ifdef ACE_GETACL | ||
| 195 | /* Solaris also has a different variant of ACLs, used in ZFS and NFSv4 | ||
| 196 | file systems (whereas the other ones are used in UFS file systems). */ | ||
| 197 | |||
| 198 | /* The flags in the ace_t structure changed in a binary incompatible way | ||
| 199 | when ACL_NO_TRIVIAL etc. were introduced in <sys/acl.h> version 1.15. | ||
| 200 | How to distinguish the two conventions at runtime? | ||
| 201 | We fetch the existing ACL. In the old convention, usually three ACEs have | ||
| 202 | a_flags = ACE_OWNER / ACE_GROUP / ACE_OTHER, in the range 0x0100..0x0400. | ||
| 203 | In the new convention, these values are not used. */ | ||
| 204 | int convention; | ||
| 205 | |||
| 206 | { | ||
| 207 | /* Initially, try to read the entries into a stack-allocated buffer. | ||
| 208 | Use malloc if it does not fit. */ | ||
| 209 | enum | ||
| 210 | { | ||
| 211 | alloc_init = 4000 / sizeof (ace_t), /* >= 3 */ | ||
| 212 | alloc_max = MIN (INT_MAX, SIZE_MAX / sizeof (ace_t)) | ||
| 213 | }; | ||
| 214 | ace_t buf[alloc_init]; | ||
| 215 | size_t alloc = alloc_init; | ||
| 216 | ace_t *entries = buf; | ||
| 217 | ace_t *malloced = NULL; | ||
| 218 | int count; | ||
| 219 | |||
| 220 | for (;;) | ||
| 221 | { | ||
| 222 | count = (desc != -1 | ||
| 223 | ? facl (desc, ACE_GETACL, alloc, entries) | ||
| 224 | : acl (name, ACE_GETACL, alloc, entries)); | ||
| 225 | if (count < 0 && errno == ENOSPC) | ||
| 226 | { | ||
| 227 | /* Increase the size of the buffer. */ | ||
| 228 | free (malloced); | ||
| 229 | if (alloc > alloc_max / 2) | ||
| 230 | { | ||
| 231 | errno = ENOMEM; | ||
| 232 | return -1; | ||
| 233 | } | ||
| 234 | alloc = 2 * alloc; /* <= alloc_max */ | ||
| 235 | entries = malloced = (ace_t *) malloc (alloc * sizeof (ace_t)); | ||
| 236 | if (entries == NULL) | ||
| 237 | { | ||
| 238 | errno = ENOMEM; | ||
| 239 | return -1; | ||
| 240 | } | ||
| 241 | continue; | ||
| 242 | } | ||
| 243 | break; | ||
| 244 | } | ||
| 245 | |||
| 246 | if (count <= 0) | ||
| 247 | convention = -1; | ||
| 248 | else | ||
| 249 | { | ||
| 250 | int i; | ||
| 251 | |||
| 252 | convention = 0; | ||
| 253 | for (i = 0; i < count; i++) | ||
| 254 | if (entries[i].a_flags & (OLD_ACE_OWNER | OLD_ACE_GROUP | OLD_ACE_OTHER)) | ||
| 255 | { | ||
| 256 | convention = 1; | ||
| 257 | break; | ||
| 258 | } | ||
| 259 | } | ||
| 260 | free (malloced); | ||
| 261 | } | ||
| 262 | |||
| 263 | if (convention >= 0) | ||
| 264 | { | ||
| 265 | ace_t entries[6]; | ||
| 266 | int count; | ||
| 267 | int ret; | ||
| 268 | |||
| 269 | if (convention) | ||
| 270 | { | ||
| 271 | /* Running on Solaris 10. */ | ||
| 272 | entries[0].a_type = OLD_ALLOW; | ||
| 273 | entries[0].a_flags = OLD_ACE_OWNER; | ||
| 274 | entries[0].a_who = 0; /* irrelevant */ | ||
| 275 | entries[0].a_access_mask = (mode >> 6) & 7; | ||
| 276 | entries[1].a_type = OLD_ALLOW; | ||
| 277 | entries[1].a_flags = OLD_ACE_GROUP; | ||
| 278 | entries[1].a_who = 0; /* irrelevant */ | ||
| 279 | entries[1].a_access_mask = (mode >> 3) & 7; | ||
| 280 | entries[2].a_type = OLD_ALLOW; | ||
| 281 | entries[2].a_flags = OLD_ACE_OTHER; | ||
| 282 | entries[2].a_who = 0; | ||
| 283 | entries[2].a_access_mask = mode & 7; | ||
| 284 | count = 3; | ||
| 285 | } | ||
| 286 | else | ||
| 287 | { | ||
| 288 | /* Running on Solaris 10 (newer version) or Solaris 11. | ||
| 289 | The details here were found through "/bin/ls -lvd somefiles". */ | ||
| 290 | entries[0].a_type = NEW_ACE_ACCESS_DENIED_ACE_TYPE; | ||
| 291 | entries[0].a_flags = NEW_ACE_OWNER; | ||
| 292 | entries[0].a_who = 0; /* irrelevant */ | ||
| 293 | entries[0].a_access_mask = 0; | ||
| 294 | entries[1].a_type = NEW_ACE_ACCESS_ALLOWED_ACE_TYPE; | ||
| 295 | entries[1].a_flags = NEW_ACE_OWNER; | ||
| 296 | entries[1].a_who = 0; /* irrelevant */ | ||
| 297 | entries[1].a_access_mask = NEW_ACE_WRITE_NAMED_ATTRS | ||
| 298 | | NEW_ACE_WRITE_ATTRIBUTES | ||
| 299 | | NEW_ACE_WRITE_ACL | ||
| 300 | | NEW_ACE_WRITE_OWNER; | ||
| 301 | if (mode & 0400) | ||
| 302 | entries[1].a_access_mask |= NEW_ACE_READ_DATA; | ||
| 303 | else | ||
| 304 | entries[0].a_access_mask |= NEW_ACE_READ_DATA; | ||
| 305 | if (mode & 0200) | ||
| 306 | entries[1].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA; | ||
| 307 | else | ||
| 308 | entries[0].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA; | ||
| 309 | if (mode & 0100) | ||
| 310 | entries[1].a_access_mask |= NEW_ACE_EXECUTE; | ||
| 311 | else | ||
| 312 | entries[0].a_access_mask |= NEW_ACE_EXECUTE; | ||
| 313 | entries[2].a_type = NEW_ACE_ACCESS_DENIED_ACE_TYPE; | ||
| 314 | entries[2].a_flags = NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP; | ||
| 315 | entries[2].a_who = 0; /* irrelevant */ | ||
| 316 | entries[2].a_access_mask = 0; | ||
| 317 | entries[3].a_type = NEW_ACE_ACCESS_ALLOWED_ACE_TYPE; | ||
| 318 | entries[3].a_flags = NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP; | ||
| 319 | entries[3].a_who = 0; /* irrelevant */ | ||
| 320 | entries[3].a_access_mask = 0; | ||
| 321 | if (mode & 0040) | ||
| 322 | entries[3].a_access_mask |= NEW_ACE_READ_DATA; | ||
| 323 | else | ||
| 324 | entries[2].a_access_mask |= NEW_ACE_READ_DATA; | ||
| 325 | if (mode & 0020) | ||
| 326 | entries[3].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA; | ||
| 327 | else | ||
| 328 | entries[2].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA; | ||
| 329 | if (mode & 0010) | ||
| 330 | entries[3].a_access_mask |= NEW_ACE_EXECUTE; | ||
| 331 | else | ||
| 332 | entries[2].a_access_mask |= NEW_ACE_EXECUTE; | ||
| 333 | entries[4].a_type = NEW_ACE_ACCESS_DENIED_ACE_TYPE; | ||
| 334 | entries[4].a_flags = NEW_ACE_EVERYONE; | ||
| 335 | entries[4].a_who = 0; | ||
| 336 | entries[4].a_access_mask = NEW_ACE_WRITE_NAMED_ATTRS | ||
| 337 | | NEW_ACE_WRITE_ATTRIBUTES | ||
| 338 | | NEW_ACE_WRITE_ACL | ||
| 339 | | NEW_ACE_WRITE_OWNER; | ||
| 340 | entries[5].a_type = NEW_ACE_ACCESS_ALLOWED_ACE_TYPE; | ||
| 341 | entries[5].a_flags = NEW_ACE_EVERYONE; | ||
| 342 | entries[5].a_who = 0; | ||
| 343 | entries[5].a_access_mask = NEW_ACE_READ_NAMED_ATTRS | ||
| 344 | | NEW_ACE_READ_ATTRIBUTES | ||
| 345 | | NEW_ACE_READ_ACL | ||
| 346 | | NEW_ACE_SYNCHRONIZE; | ||
| 347 | if (mode & 0004) | ||
| 348 | entries[5].a_access_mask |= NEW_ACE_READ_DATA; | ||
| 349 | else | ||
| 350 | entries[4].a_access_mask |= NEW_ACE_READ_DATA; | ||
| 351 | if (mode & 0002) | ||
| 352 | entries[5].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA; | ||
| 353 | else | ||
| 354 | entries[4].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA; | ||
| 355 | if (mode & 0001) | ||
| 356 | entries[5].a_access_mask |= NEW_ACE_EXECUTE; | ||
| 357 | else | ||
| 358 | entries[4].a_access_mask |= NEW_ACE_EXECUTE; | ||
| 359 | count = 6; | ||
| 360 | } | ||
| 361 | if (desc != -1) | ||
| 362 | ret = facl (desc, ACE_SETACL, count, entries); | ||
| 363 | else | ||
| 364 | ret = acl (name, ACE_SETACL, count, entries); | ||
| 365 | if (ret < 0 && errno != EINVAL && errno != ENOTSUP) | ||
| 366 | { | ||
| 367 | if (errno == ENOSYS) | ||
| 368 | return chmod_or_fchmod (name, desc, mode); | ||
| 369 | return -1; | ||
| 370 | } | ||
| 371 | if (ret == 0) | ||
| 372 | done_setacl = 1; | ||
| 373 | } | ||
| 374 | # endif | ||
| 375 | |||
| 376 | if (!done_setacl) | ||
| 377 | { | ||
| 378 | aclent_t entries[3]; | ||
| 379 | int ret; | ||
| 380 | |||
| 381 | entries[0].a_type = USER_OBJ; | ||
| 382 | entries[0].a_id = 0; /* irrelevant */ | ||
| 383 | entries[0].a_perm = (mode >> 6) & 7; | ||
| 384 | entries[1].a_type = GROUP_OBJ; | ||
| 385 | entries[1].a_id = 0; /* irrelevant */ | ||
| 386 | entries[1].a_perm = (mode >> 3) & 7; | ||
| 387 | entries[2].a_type = OTHER_OBJ; | ||
| 388 | entries[2].a_id = 0; | ||
| 389 | entries[2].a_perm = mode & 7; | ||
| 390 | |||
| 391 | if (desc != -1) | ||
| 392 | ret = facl (desc, SETACL, | ||
| 393 | sizeof (entries) / sizeof (aclent_t), entries); | ||
| 394 | else | ||
| 395 | ret = acl (name, SETACL, | ||
| 396 | sizeof (entries) / sizeof (aclent_t), entries); | ||
| 397 | if (ret < 0) | ||
| 398 | { | ||
| 399 | if (errno == ENOSYS || errno == EOPNOTSUPP) | ||
| 400 | return chmod_or_fchmod (name, desc, mode); | ||
| 401 | return -1; | ||
| 402 | } | ||
| 403 | } | ||
| 404 | |||
| 405 | if (!MODE_INSIDE_ACL || (mode & (S_ISUID | S_ISGID | S_ISVTX))) | ||
| 406 | { | ||
| 407 | /* We did not call chmod so far, so the special bits have not yet | ||
| 408 | been set. */ | ||
| 409 | return chmod_or_fchmod (name, desc, mode); | ||
| 410 | } | ||
| 411 | return 0; | ||
| 412 | |||
| 413 | # elif HAVE_GETACL /* HP-UX */ | ||
| 414 | |||
| 415 | struct stat statbuf; | ||
| 416 | int ret; | ||
| 417 | |||
| 418 | if (desc != -1) | ||
| 419 | ret = fstat (desc, &statbuf); | ||
| 420 | else | ||
| 421 | ret = stat (name, &statbuf); | ||
| 422 | if (ret < 0) | ||
| 423 | return -1; | ||
| 424 | |||
| 425 | { | ||
| 426 | struct acl_entry entries[3]; | ||
| 427 | |||
| 428 | entries[0].uid = statbuf.st_uid; | ||
| 429 | entries[0].gid = ACL_NSGROUP; | ||
| 430 | entries[0].mode = (mode >> 6) & 7; | ||
| 431 | entries[1].uid = ACL_NSUSER; | ||
| 432 | entries[1].gid = statbuf.st_gid; | ||
| 433 | entries[1].mode = (mode >> 3) & 7; | ||
| 434 | entries[2].uid = ACL_NSUSER; | ||
| 435 | entries[2].gid = ACL_NSGROUP; | ||
| 436 | entries[2].mode = mode & 7; | ||
| 437 | |||
| 438 | if (desc != -1) | ||
| 439 | ret = fsetacl (desc, sizeof (entries) / sizeof (struct acl_entry), entries); | ||
| 440 | else | ||
| 441 | ret = setacl (name, sizeof (entries) / sizeof (struct acl_entry), entries); | ||
| 442 | } | ||
| 443 | if (ret < 0) | ||
| 444 | { | ||
| 445 | if (!(errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP)) | ||
| 446 | return -1; | ||
| 447 | |||
| 448 | # if HAVE_ACLV_H /* HP-UX >= 11.11 */ | ||
| 449 | { | ||
| 450 | struct acl entries[4]; | ||
| 451 | |||
| 452 | entries[0].a_type = USER_OBJ; | ||
| 453 | entries[0].a_id = 0; /* irrelevant */ | ||
| 454 | entries[0].a_perm = (mode >> 6) & 7; | ||
| 455 | entries[1].a_type = GROUP_OBJ; | ||
| 456 | entries[1].a_id = 0; /* irrelevant */ | ||
| 457 | entries[1].a_perm = (mode >> 3) & 7; | ||
| 458 | entries[2].a_type = CLASS_OBJ; | ||
| 459 | entries[2].a_id = 0; | ||
| 460 | entries[2].a_perm = (mode >> 3) & 7; | ||
| 461 | entries[3].a_type = OTHER_OBJ; | ||
| 462 | entries[3].a_id = 0; | ||
| 463 | entries[3].a_perm = mode & 7; | ||
| 464 | |||
| 465 | ret = aclsort (sizeof (entries) / sizeof (struct acl), 1, entries); | ||
| 466 | if (ret > 0) | ||
| 467 | abort (); | ||
| 468 | if (ret < 0) | ||
| 469 | { | ||
| 470 | if (0) | ||
| 471 | return chmod_or_fchmod (name, desc, mode); | ||
| 472 | return -1; | ||
| 473 | } | ||
| 474 | |||
| 475 | ret = acl ((char *) name, ACL_SET, | ||
| 476 | sizeof (entries) / sizeof (struct acl), entries); | ||
| 477 | if (ret < 0) | ||
| 478 | { | ||
| 479 | if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL) | ||
| 480 | return chmod_or_fchmod (name, desc, mode); | ||
| 481 | return -1; | ||
| 482 | } | ||
| 483 | } | ||
| 484 | # else | ||
| 485 | return chmod_or_fchmod (name, desc, mode); | ||
| 486 | # endif | ||
| 487 | } | ||
| 488 | |||
| 489 | if (mode & (S_ISUID | S_ISGID | S_ISVTX)) | ||
| 490 | { | ||
| 491 | /* We did not call chmod so far, so the special bits have not yet | ||
| 492 | been set. */ | ||
| 493 | return chmod_or_fchmod (name, desc, mode); | ||
| 494 | } | ||
| 495 | return 0; | ||
| 496 | |||
| 497 | # elif HAVE_ACLX_GET && defined ACL_AIX_WIP /* AIX */ | ||
| 498 | |||
| 499 | acl_type_list_t types; | ||
| 500 | size_t types_size = sizeof (types); | ||
| 501 | acl_type_t type; | ||
| 502 | |||
| 503 | if (aclx_gettypes (name, &types, &types_size) < 0 | ||
| 504 | || types.num_entries == 0) | ||
| 505 | return chmod_or_fchmod (name, desc, mode); | ||
| 506 | |||
| 507 | /* XXX Do we need to clear all types of ACLs for the given file, or is it | ||
| 508 | sufficient to clear the first one? */ | ||
| 509 | type = types.entries[0]; | ||
| 510 | if (type.u64 == ACL_AIXC) | ||
| 511 | { | ||
| 512 | union { struct acl a; char room[128]; } u; | ||
| 513 | int ret; | ||
| 514 | |||
| 515 | u.a.acl_len = (char *) &u.a.acl_ext[0] - (char *) &u.a; /* no entries */ | ||
| 516 | u.a.acl_mode = mode & ~(S_IXACL | 0777); | ||
| 517 | u.a.u_access = (mode >> 6) & 7; | ||
| 518 | u.a.g_access = (mode >> 3) & 7; | ||
| 519 | u.a.o_access = mode & 7; | ||
| 520 | |||
| 521 | if (desc != -1) | ||
| 522 | ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS, | ||
| 523 | type, &u.a, u.a.acl_len, mode); | ||
| 524 | else | ||
| 525 | ret = aclx_put (name, SET_ACL | SET_MODE_S_BITS, | ||
| 526 | type, &u.a, u.a.acl_len, mode); | ||
| 527 | if (!(ret < 0 && errno == ENOSYS)) | ||
| 528 | return ret; | ||
| 529 | } | ||
| 530 | else if (type.u64 == ACL_NFS4) | ||
| 531 | { | ||
| 532 | union { nfs4_acl_int_t a; char room[128]; } u; | ||
| 533 | nfs4_ace_int_t *ace; | ||
| 534 | int ret; | ||
| 535 | |||
| 536 | u.a.aclVersion = NFS4_ACL_INT_STRUCT_VERSION; | ||
| 537 | u.a.aclEntryN = 0; | ||
| 538 | ace = &u.a.aclEntry[0]; | ||
| 539 | { | ||
| 540 | ace->flags = ACE4_ID_SPECIAL; | ||
| 541 | ace->aceWho.special_whoid = ACE4_WHO_OWNER; | ||
| 542 | ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE; | ||
| 543 | ace->aceFlags = 0; | ||
| 544 | ace->aceMask = | ||
| 545 | (mode & 0400 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0) | ||
| 546 | | (mode & 0200 | ||
| 547 | ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA | ||
| 548 | | ACE4_ADD_SUBDIRECTORY | ||
| 549 | : 0) | ||
| 550 | | (mode & 0100 ? ACE4_EXECUTE : 0); | ||
| 551 | ace->aceWhoString[0] = '\0'; | ||
| 552 | ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace; | ||
| 553 | ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4]; | ||
| 554 | u.a.aclEntryN++; | ||
| 555 | } | ||
| 556 | { | ||
| 557 | ace->flags = ACE4_ID_SPECIAL; | ||
| 558 | ace->aceWho.special_whoid = ACE4_WHO_GROUP; | ||
| 559 | ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE; | ||
| 560 | ace->aceFlags = 0; | ||
| 561 | ace->aceMask = | ||
| 562 | (mode & 0040 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0) | ||
| 563 | | (mode & 0020 | ||
| 564 | ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA | ||
| 565 | | ACE4_ADD_SUBDIRECTORY | ||
| 566 | : 0) | ||
| 567 | | (mode & 0010 ? ACE4_EXECUTE : 0); | ||
| 568 | ace->aceWhoString[0] = '\0'; | ||
| 569 | ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace; | ||
| 570 | ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4]; | ||
| 571 | u.a.aclEntryN++; | ||
| 572 | } | ||
| 573 | { | ||
| 574 | ace->flags = ACE4_ID_SPECIAL; | ||
| 575 | ace->aceWho.special_whoid = ACE4_WHO_EVERYONE; | ||
| 576 | ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE; | ||
| 577 | ace->aceFlags = 0; | ||
| 578 | ace->aceMask = | ||
| 579 | (mode & 0004 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0) | ||
| 580 | | (mode & 0002 | ||
| 581 | ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA | ||
| 582 | | ACE4_ADD_SUBDIRECTORY | ||
| 583 | : 0) | ||
| 584 | | (mode & 0001 ? ACE4_EXECUTE : 0); | ||
| 585 | ace->aceWhoString[0] = '\0'; | ||
| 586 | ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace; | ||
| 587 | ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4]; | ||
| 588 | u.a.aclEntryN++; | ||
| 589 | } | ||
| 590 | u.a.aclLength = (char *) ace - (char *) &u.a; | ||
| 591 | |||
| 592 | if (desc != -1) | ||
| 593 | ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS, | ||
| 594 | type, &u.a, u.a.aclLength, mode); | ||
| 595 | else | ||
| 596 | ret = aclx_put (name, SET_ACL | SET_MODE_S_BITS, | ||
| 597 | type, &u.a, u.a.aclLength, mode); | ||
| 598 | if (!(ret < 0 && errno == ENOSYS)) | ||
| 599 | return ret; | ||
| 600 | } | ||
| 601 | |||
| 602 | return chmod_or_fchmod (name, desc, mode); | ||
| 603 | |||
| 604 | # elif HAVE_STATACL /* older AIX */ | ||
| 605 | |||
| 606 | union { struct acl a; char room[128]; } u; | ||
| 607 | int ret; | ||
| 608 | |||
| 609 | u.a.acl_len = (char *) &u.a.acl_ext[0] - (char *) &u.a; /* no entries */ | ||
| 610 | u.a.acl_mode = mode & ~(S_IXACL | 0777); | ||
| 611 | u.a.u_access = (mode >> 6) & 7; | ||
| 612 | u.a.g_access = (mode >> 3) & 7; | ||
| 613 | u.a.o_access = mode & 7; | ||
| 614 | |||
| 615 | if (desc != -1) | ||
| 616 | ret = fchacl (desc, &u.a, u.a.acl_len); | ||
| 617 | else | ||
| 618 | ret = chacl (name, &u.a, u.a.acl_len); | ||
| 619 | |||
| 620 | if (ret < 0 && errno == ENOSYS) | ||
| 621 | return chmod_or_fchmod (name, desc, mode); | ||
| 622 | |||
| 623 | return ret; | ||
| 624 | |||
| 625 | # elif HAVE_ACLSORT /* NonStop Kernel */ | ||
| 626 | |||
| 627 | struct acl entries[4]; | ||
| 628 | int ret; | ||
| 629 | |||
| 630 | entries[0].a_type = USER_OBJ; | ||
| 631 | entries[0].a_id = 0; /* irrelevant */ | ||
| 632 | entries[0].a_perm = (mode >> 6) & 7; | ||
| 633 | entries[1].a_type = GROUP_OBJ; | ||
| 634 | entries[1].a_id = 0; /* irrelevant */ | ||
| 635 | entries[1].a_perm = (mode >> 3) & 7; | ||
| 636 | entries[2].a_type = CLASS_OBJ; | ||
| 637 | entries[2].a_id = 0; | ||
| 638 | entries[2].a_perm = (mode >> 3) & 7; | ||
| 639 | entries[3].a_type = OTHER_OBJ; | ||
| 640 | entries[3].a_id = 0; | ||
| 641 | entries[3].a_perm = mode & 7; | ||
| 642 | |||
| 643 | ret = aclsort (sizeof (entries) / sizeof (struct acl), 1, entries); | ||
| 644 | if (ret > 0) | ||
| 645 | abort (); | ||
| 646 | if (ret < 0) | ||
| 647 | { | ||
| 648 | if (0) | ||
| 649 | return chmod_or_fchmod (name, desc, mode); | ||
| 650 | return -1; | ||
| 651 | } | ||
| 652 | |||
| 653 | ret = acl ((char *) name, ACL_SET, | ||
| 654 | sizeof (entries) / sizeof (struct acl), entries); | ||
| 655 | if (ret < 0) | ||
| 656 | { | ||
| 657 | if (0) | ||
| 658 | return chmod_or_fchmod (name, desc, mode); | ||
| 659 | return -1; | ||
| 660 | } | ||
| 661 | |||
| 662 | if (mode & (S_ISUID | S_ISGID | S_ISVTX)) | ||
| 663 | { | ||
| 664 | /* We did not call chmod so far, so the special bits have not yet | ||
| 665 | been set. */ | ||
| 666 | return chmod_or_fchmod (name, desc, mode); | ||
| 667 | } | ||
| 668 | return 0; | ||
| 669 | |||
| 670 | # else /* Unknown flavor of ACLs */ | ||
| 671 | return chmod_or_fchmod (name, desc, mode); | ||
| 672 | # endif | ||
| 673 | #else /* !USE_ACL */ | ||
| 674 | return chmod_or_fchmod (name, desc, mode); | ||
| 675 | #endif | ||
| 676 | } | ||
diff --git a/lib/readlink.c b/lib/readlink.c index f83a1e0123f..4c496395176 100644 --- a/lib/readlink.c +++ b/lib/readlink.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Stub for readlink(). | 1 | /* Stub for readlink(). |
| 2 | Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2003-2007, 2009-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/readlinkat.c b/lib/readlinkat.c index 504e6ebbc49..c8a60500f18 100644 --- a/lib/readlinkat.c +++ b/lib/readlinkat.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Read a symlink relative to an open directory. | 1 | /* Read a symlink relative to an open directory. |
| 2 | Copyright (C) 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2009-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/root-uid.h b/lib/root-uid.h index c75d88891ed..39e3c995688 100644 --- a/lib/root-uid.h +++ b/lib/root-uid.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* The user ID that always has appropriate privileges in the POSIX sense. | 1 | /* The user ID that always has appropriate privileges in the POSIX sense. |
| 2 | 2 | ||
| 3 | Copyright 2012-2013 Free Software Foundation, Inc. | 3 | Copyright 2012-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/save-cwd.h b/lib/save-cwd.h index bd0cd8d5707..9a1eb3519c8 100644 --- a/lib/save-cwd.h +++ b/lib/save-cwd.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Do not save and restore the current working directory. | 1 | /* Do not save and restore the current working directory. |
| 2 | 2 | ||
| 3 | Copyright 2013 Free Software Foundation, Inc. | 3 | Copyright 2013-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/secure_getenv.c b/lib/secure_getenv.c new file mode 100644 index 00000000000..32819e6d2d2 --- /dev/null +++ b/lib/secure_getenv.c | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | /* Look up an environment variable more securely. | ||
| 2 | |||
| 3 | Copyright 2013-2014 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This program is free software: you can redistribute it and/or modify it | ||
| 6 | under the terms of the GNU General Public License as published | ||
| 7 | by 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 GNU | ||
| 13 | 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 | #include <stdlib.h> | ||
| 21 | |||
| 22 | #if !HAVE___SECURE_GETENV | ||
| 23 | # if HAVE_ISSETUGID | ||
| 24 | # include <unistd.h> | ||
| 25 | # else | ||
| 26 | # undef issetugid | ||
| 27 | # define issetugid() 1 | ||
| 28 | # endif | ||
| 29 | #endif | ||
| 30 | |||
| 31 | char * | ||
| 32 | secure_getenv (char const *name) | ||
| 33 | { | ||
| 34 | #if HAVE___SECURE_GETENV | ||
| 35 | return __secure_getenv (name); | ||
| 36 | #else | ||
| 37 | if (issetugid ()) | ||
| 38 | return 0; | ||
| 39 | return getenv (name); | ||
| 40 | #endif | ||
| 41 | } | ||
diff --git a/lib/sha1.c b/lib/sha1.c index 778389affc5..0ea35b08d47 100644 --- a/lib/sha1.c +++ b/lib/sha1.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* sha1.c - Functions to compute SHA1 message digest of files or | 1 | /* sha1.c - Functions to compute SHA1 message digest of files or |
| 2 | memory blocks according to the NIST specification FIPS-180-1. | 2 | memory blocks according to the NIST specification FIPS-180-1. |
| 3 | 3 | ||
| 4 | Copyright (C) 2000-2001, 2003-2006, 2008-2013 Free Software Foundation, Inc. | 4 | Copyright (C) 2000-2001, 2003-2006, 2008-2014 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | This program is free software; you can redistribute it and/or modify it | 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the | 7 | under the terms of the GNU General Public License as published by the |
| @@ -23,6 +23,9 @@ | |||
| 23 | 23 | ||
| 24 | #include <config.h> | 24 | #include <config.h> |
| 25 | 25 | ||
| 26 | #if HAVE_OPENSSL_SHA1 | ||
| 27 | # define GL_OPENSSL_INLINE _GL_EXTERN_INLINE | ||
| 28 | #endif | ||
| 26 | #include "sha1.h" | 29 | #include "sha1.h" |
| 27 | 30 | ||
| 28 | #include <stdalign.h> | 31 | #include <stdalign.h> |
| @@ -46,6 +49,7 @@ | |||
| 46 | # error "invalid BLOCKSIZE" | 49 | # error "invalid BLOCKSIZE" |
| 47 | #endif | 50 | #endif |
| 48 | 51 | ||
| 52 | #if ! HAVE_OPENSSL_SHA1 | ||
| 49 | /* This array contains the bytes used to pad the buffer to the next | 53 | /* This array contains the bytes used to pad the buffer to the next |
| 50 | 64-byte boundary. (RFC 1321, 3.1: Step 1) */ | 54 | 64-byte boundary. (RFC 1321, 3.1: Step 1) */ |
| 51 | static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; | 55 | static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; |
| @@ -116,6 +120,7 @@ sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf) | |||
| 116 | 120 | ||
| 117 | return sha1_read_ctx (ctx, resbuf); | 121 | return sha1_read_ctx (ctx, resbuf); |
| 118 | } | 122 | } |
| 123 | #endif | ||
| 119 | 124 | ||
| 120 | /* Compute SHA1 message digest for bytes read from STREAM. The | 125 | /* Compute SHA1 message digest for bytes read from STREAM. The |
| 121 | resulting message digest number will be written into the 16 bytes | 126 | resulting message digest number will be written into the 16 bytes |
| @@ -190,6 +195,7 @@ sha1_stream (FILE *stream, void *resblock) | |||
| 190 | return 0; | 195 | return 0; |
| 191 | } | 196 | } |
| 192 | 197 | ||
| 198 | #if ! HAVE_OPENSSL_SHA1 | ||
| 193 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The | 199 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The |
| 194 | result is always in little endian byte order, so that a byte-wise | 200 | result is always in little endian byte order, so that a byte-wise |
| 195 | output yields to the wanted ASCII representation of the message | 201 | output yields to the wanted ASCII representation of the message |
| @@ -424,3 +430,4 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx) | |||
| 424 | e = ctx->E += e; | 430 | e = ctx->E += e; |
| 425 | } | 431 | } |
| 426 | } | 432 | } |
| 433 | #endif | ||
diff --git a/lib/sha1.h b/lib/sha1.h index ddd386f9144..4fd7d66844a 100644 --- a/lib/sha1.h +++ b/lib/sha1.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Declarations of functions and data types used for SHA1 sum | 1 | /* Declarations of functions and data types used for SHA1 sum |
| 2 | library functions. | 2 | library functions. |
| 3 | Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2013 Free Software | 3 | Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2014 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | 5 | ||
| 6 | This program is free software; you can redistribute it and/or modify it | 6 | This program is free software; you can redistribute it and/or modify it |
| @@ -22,12 +22,20 @@ | |||
| 22 | # include <stdio.h> | 22 | # include <stdio.h> |
| 23 | # include <stdint.h> | 23 | # include <stdint.h> |
| 24 | 24 | ||
| 25 | # if HAVE_OPENSSL_SHA1 | ||
| 26 | # include <openssl/sha.h> | ||
| 27 | # endif | ||
| 28 | |||
| 25 | # ifdef __cplusplus | 29 | # ifdef __cplusplus |
| 26 | extern "C" { | 30 | extern "C" { |
| 27 | # endif | 31 | # endif |
| 28 | 32 | ||
| 29 | #define SHA1_DIGEST_SIZE 20 | 33 | #define SHA1_DIGEST_SIZE 20 |
| 30 | 34 | ||
| 35 | # if HAVE_OPENSSL_SHA1 | ||
| 36 | # define GL_OPENSSL_NAME 1 | ||
| 37 | # include "gl_openssl.h" | ||
| 38 | # else | ||
| 31 | /* Structure to save state of computation between the single steps. */ | 39 | /* Structure to save state of computation between the single steps. */ |
| 32 | struct sha1_ctx | 40 | struct sha1_ctx |
| 33 | { | 41 | { |
| @@ -42,7 +50,6 @@ struct sha1_ctx | |||
| 42 | uint32_t buffer[32]; | 50 | uint32_t buffer[32]; |
| 43 | }; | 51 | }; |
| 44 | 52 | ||
| 45 | |||
| 46 | /* Initialize structure containing state of computation. */ | 53 | /* Initialize structure containing state of computation. */ |
| 47 | extern void sha1_init_ctx (struct sha1_ctx *ctx); | 54 | extern void sha1_init_ctx (struct sha1_ctx *ctx); |
| 48 | 55 | ||
| @@ -73,17 +80,19 @@ extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf); | |||
| 73 | extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf); | 80 | extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf); |
| 74 | 81 | ||
| 75 | 82 | ||
| 76 | /* Compute SHA1 message digest for bytes read from STREAM. The | ||
| 77 | resulting message digest number will be written into the 20 bytes | ||
| 78 | beginning at RESBLOCK. */ | ||
| 79 | extern int sha1_stream (FILE *stream, void *resblock); | ||
| 80 | |||
| 81 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The | 83 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The |
| 82 | result is always in little endian byte order, so that a byte-wise | 84 | result is always in little endian byte order, so that a byte-wise |
| 83 | output yields to the wanted ASCII representation of the message | 85 | output yields to the wanted ASCII representation of the message |
| 84 | digest. */ | 86 | digest. */ |
| 85 | extern void *sha1_buffer (const char *buffer, size_t len, void *resblock); | 87 | extern void *sha1_buffer (const char *buffer, size_t len, void *resblock); |
| 86 | 88 | ||
| 89 | # endif | ||
| 90 | /* Compute SHA1 message digest for bytes read from STREAM. The | ||
| 91 | resulting message digest number will be written into the 20 bytes | ||
| 92 | beginning at RESBLOCK. */ | ||
| 93 | extern int sha1_stream (FILE *stream, void *resblock); | ||
| 94 | |||
| 95 | |||
| 87 | # ifdef __cplusplus | 96 | # ifdef __cplusplus |
| 88 | } | 97 | } |
| 89 | # endif | 98 | # endif |
diff --git a/lib/sha256.c b/lib/sha256.c index 4b2cee37fb5..a07e4f9fcde 100644 --- a/lib/sha256.c +++ b/lib/sha256.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* sha256.c - Functions to compute SHA256 and SHA224 message digest of files or | 1 | /* sha256.c - Functions to compute SHA256 and SHA224 message digest of files or |
| 2 | memory blocks according to the NIST specification FIPS-180-2. | 2 | memory blocks according to the NIST specification FIPS-180-2. |
| 3 | 3 | ||
| 4 | Copyright (C) 2005-2006, 2008-2013 Free Software Foundation, Inc. | 4 | Copyright (C) 2005-2006, 2008-2014 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 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 | 7 | it under the terms of the GNU General Public License as published by |
| @@ -22,6 +22,9 @@ | |||
| 22 | 22 | ||
| 23 | #include <config.h> | 23 | #include <config.h> |
| 24 | 24 | ||
| 25 | #if HAVE_OPENSSL_SHA256 | ||
| 26 | # define GL_OPENSSL_INLINE _GL_EXTERN_INLINE | ||
| 27 | #endif | ||
| 25 | #include "sha256.h" | 28 | #include "sha256.h" |
| 26 | 29 | ||
| 27 | #include <stdalign.h> | 30 | #include <stdalign.h> |
| @@ -45,6 +48,7 @@ | |||
| 45 | # error "invalid BLOCKSIZE" | 48 | # error "invalid BLOCKSIZE" |
| 46 | #endif | 49 | #endif |
| 47 | 50 | ||
| 51 | #if ! HAVE_OPENSSL_SHA256 | ||
| 48 | /* This array contains the bytes used to pad the buffer to the next | 52 | /* This array contains the bytes used to pad the buffer to the next |
| 49 | 64-byte boundary. */ | 53 | 64-byte boundary. */ |
| 50 | static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; | 54 | static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; |
| @@ -163,6 +167,7 @@ sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf) | |||
| 163 | sha256_conclude_ctx (ctx); | 167 | sha256_conclude_ctx (ctx); |
| 164 | return sha224_read_ctx (ctx, resbuf); | 168 | return sha224_read_ctx (ctx, resbuf); |
| 165 | } | 169 | } |
| 170 | #endif | ||
| 166 | 171 | ||
| 167 | /* Compute SHA256 message digest for bytes read from STREAM. The | 172 | /* Compute SHA256 message digest for bytes read from STREAM. The |
| 168 | resulting message digest number will be written into the 32 bytes | 173 | resulting message digest number will be written into the 32 bytes |
| @@ -308,6 +313,7 @@ sha224_stream (FILE *stream, void *resblock) | |||
| 308 | return 0; | 313 | return 0; |
| 309 | } | 314 | } |
| 310 | 315 | ||
| 316 | #if ! HAVE_OPENSSL_SHA256 | ||
| 311 | /* Compute SHA512 message digest for LEN bytes beginning at BUFFER. The | 317 | /* Compute SHA512 message digest for LEN bytes beginning at BUFFER. The |
| 312 | result is always in little endian byte order, so that a byte-wise | 318 | result is always in little endian byte order, so that a byte-wise |
| 313 | output yields to the wanted ASCII representation of the message | 319 | output yields to the wanted ASCII representation of the message |
| @@ -567,3 +573,4 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) | |||
| 567 | h = ctx->state[7] += h; | 573 | h = ctx->state[7] += h; |
| 568 | } | 574 | } |
| 569 | } | 575 | } |
| 576 | #endif | ||
diff --git a/lib/sha256.h b/lib/sha256.h index 7e6252285bb..92c0b9553a4 100644 --- a/lib/sha256.h +++ b/lib/sha256.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Declarations of functions and data types used for SHA256 and SHA224 sum | 1 | /* Declarations of functions and data types used for SHA256 and SHA224 sum |
| 2 | library functions. | 2 | library functions. |
| 3 | Copyright (C) 2005-2006, 2008-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2005-2006, 2008-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -21,10 +21,23 @@ | |||
| 21 | # include <stdio.h> | 21 | # include <stdio.h> |
| 22 | # include <stdint.h> | 22 | # include <stdint.h> |
| 23 | 23 | ||
| 24 | # if HAVE_OPENSSL_SHA256 | ||
| 25 | # include <openssl/sha.h> | ||
| 26 | # endif | ||
| 27 | |||
| 24 | # ifdef __cplusplus | 28 | # ifdef __cplusplus |
| 25 | extern "C" { | 29 | extern "C" { |
| 26 | # endif | 30 | # endif |
| 27 | 31 | ||
| 32 | enum { SHA224_DIGEST_SIZE = 224 / 8 }; | ||
| 33 | enum { SHA256_DIGEST_SIZE = 256 / 8 }; | ||
| 34 | |||
| 35 | # if HAVE_OPENSSL_SHA256 | ||
| 36 | # define GL_OPENSSL_NAME 224 | ||
| 37 | # include "gl_openssl.h" | ||
| 38 | # define GL_OPENSSL_NAME 256 | ||
| 39 | # include "gl_openssl.h" | ||
| 40 | # else | ||
| 28 | /* Structure to save state of computation between the single steps. */ | 41 | /* Structure to save state of computation between the single steps. */ |
| 29 | struct sha256_ctx | 42 | struct sha256_ctx |
| 30 | { | 43 | { |
| @@ -35,9 +48,6 @@ struct sha256_ctx | |||
| 35 | uint32_t buffer[32]; | 48 | uint32_t buffer[32]; |
| 36 | }; | 49 | }; |
| 37 | 50 | ||
| 38 | enum { SHA224_DIGEST_SIZE = 224 / 8 }; | ||
| 39 | enum { SHA256_DIGEST_SIZE = 256 / 8 }; | ||
| 40 | |||
| 41 | /* Initialize structure containing state of computation. */ | 51 | /* Initialize structure containing state of computation. */ |
| 42 | extern void sha256_init_ctx (struct sha256_ctx *ctx); | 52 | extern void sha256_init_ctx (struct sha256_ctx *ctx); |
| 43 | extern void sha224_init_ctx (struct sha256_ctx *ctx); | 53 | extern void sha224_init_ctx (struct sha256_ctx *ctx); |
| @@ -71,12 +81,6 @@ extern void *sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf); | |||
| 71 | extern void *sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf); | 81 | extern void *sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf); |
| 72 | 82 | ||
| 73 | 83 | ||
| 74 | /* Compute SHA256 (SHA224) message digest for bytes read from STREAM. The | ||
| 75 | resulting message digest number will be written into the 32 (28) bytes | ||
| 76 | beginning at RESBLOCK. */ | ||
| 77 | extern int sha256_stream (FILE *stream, void *resblock); | ||
| 78 | extern int sha224_stream (FILE *stream, void *resblock); | ||
| 79 | |||
| 80 | /* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER. The | 84 | /* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER. The |
| 81 | result is always in little endian byte order, so that a byte-wise | 85 | result is always in little endian byte order, so that a byte-wise |
| 82 | output yields to the wanted ASCII representation of the message | 86 | output yields to the wanted ASCII representation of the message |
| @@ -84,6 +88,14 @@ extern int sha224_stream (FILE *stream, void *resblock); | |||
| 84 | extern void *sha256_buffer (const char *buffer, size_t len, void *resblock); | 88 | extern void *sha256_buffer (const char *buffer, size_t len, void *resblock); |
| 85 | extern void *sha224_buffer (const char *buffer, size_t len, void *resblock); | 89 | extern void *sha224_buffer (const char *buffer, size_t len, void *resblock); |
| 86 | 90 | ||
| 91 | # endif | ||
| 92 | /* Compute SHA256 (SHA224) message digest for bytes read from STREAM. The | ||
| 93 | resulting message digest number will be written into the 32 (28) bytes | ||
| 94 | beginning at RESBLOCK. */ | ||
| 95 | extern int sha256_stream (FILE *stream, void *resblock); | ||
| 96 | extern int sha224_stream (FILE *stream, void *resblock); | ||
| 97 | |||
| 98 | |||
| 87 | # ifdef __cplusplus | 99 | # ifdef __cplusplus |
| 88 | } | 100 | } |
| 89 | # endif | 101 | # endif |
diff --git a/lib/sha512.c b/lib/sha512.c index 79f11257474..5d3a17250e2 100644 --- a/lib/sha512.c +++ b/lib/sha512.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* sha512.c - Functions to compute SHA512 and SHA384 message digest of files or | 1 | /* sha512.c - Functions to compute SHA512 and SHA384 message digest of files or |
| 2 | memory blocks according to the NIST specification FIPS-180-2. | 2 | memory blocks according to the NIST specification FIPS-180-2. |
| 3 | 3 | ||
| 4 | Copyright (C) 2005-2006, 2008-2013 Free Software Foundation, Inc. | 4 | Copyright (C) 2005-2006, 2008-2014 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 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 | 7 | it under the terms of the GNU General Public License as published by |
| @@ -22,6 +22,9 @@ | |||
| 22 | 22 | ||
| 23 | #include <config.h> | 23 | #include <config.h> |
| 24 | 24 | ||
| 25 | #if HAVE_OPENSSL_SHA512 | ||
| 26 | # define GL_OPENSSL_INLINE _GL_EXTERN_INLINE | ||
| 27 | #endif | ||
| 25 | #include "sha512.h" | 28 | #include "sha512.h" |
| 26 | 29 | ||
| 27 | #include <stdalign.h> | 30 | #include <stdalign.h> |
| @@ -52,6 +55,7 @@ | |||
| 52 | # error "invalid BLOCKSIZE" | 55 | # error "invalid BLOCKSIZE" |
| 53 | #endif | 56 | #endif |
| 54 | 57 | ||
| 58 | #if ! HAVE_OPENSSL_SHA512 | ||
| 55 | /* This array contains the bytes used to pad the buffer to the next | 59 | /* This array contains the bytes used to pad the buffer to the next |
| 56 | 128-byte boundary. */ | 60 | 128-byte boundary. */ |
| 57 | static const unsigned char fillbuf[128] = { 0x80, 0 /* , 0, 0, ... */ }; | 61 | static const unsigned char fillbuf[128] = { 0x80, 0 /* , 0, 0, ... */ }; |
| @@ -171,6 +175,7 @@ sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf) | |||
| 171 | sha512_conclude_ctx (ctx); | 175 | sha512_conclude_ctx (ctx); |
| 172 | return sha384_read_ctx (ctx, resbuf); | 176 | return sha384_read_ctx (ctx, resbuf); |
| 173 | } | 177 | } |
| 178 | #endif | ||
| 174 | 179 | ||
| 175 | /* Compute SHA512 message digest for bytes read from STREAM. The | 180 | /* Compute SHA512 message digest for bytes read from STREAM. The |
| 176 | resulting message digest number will be written into the 64 bytes | 181 | resulting message digest number will be written into the 64 bytes |
| @@ -316,6 +321,7 @@ sha384_stream (FILE *stream, void *resblock) | |||
| 316 | return 0; | 321 | return 0; |
| 317 | } | 322 | } |
| 318 | 323 | ||
| 324 | #if ! HAVE_OPENSSL_SHA512 | ||
| 319 | /* Compute SHA512 message digest for LEN bytes beginning at BUFFER. The | 325 | /* Compute SHA512 message digest for LEN bytes beginning at BUFFER. The |
| 320 | result is always in little endian byte order, so that a byte-wise | 326 | result is always in little endian byte order, so that a byte-wise |
| 321 | output yields to the wanted ASCII representation of the message | 327 | output yields to the wanted ASCII representation of the message |
| @@ -619,3 +625,4 @@ sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx) | |||
| 619 | h = ctx->state[7] = u64plus (ctx->state[7], h); | 625 | h = ctx->state[7] = u64plus (ctx->state[7], h); |
| 620 | } | 626 | } |
| 621 | } | 627 | } |
| 628 | #endif | ||
diff --git a/lib/sha512.h b/lib/sha512.h index 2e78a5f9404..17aeea6c24d 100644 --- a/lib/sha512.h +++ b/lib/sha512.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Declarations of functions and data types used for SHA512 and SHA384 sum | 1 | /* Declarations of functions and data types used for SHA512 and SHA384 sum |
| 2 | library functions. | 2 | library functions. |
| 3 | Copyright (C) 2005-2006, 2008-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2005-2006, 2008-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -19,13 +19,25 @@ | |||
| 19 | # define SHA512_H 1 | 19 | # define SHA512_H 1 |
| 20 | 20 | ||
| 21 | # include <stdio.h> | 21 | # include <stdio.h> |
| 22 | |||
| 23 | # include "u64.h" | 22 | # include "u64.h" |
| 24 | 23 | ||
| 24 | # if HAVE_OPENSSL_SHA512 | ||
| 25 | # include <openssl/sha.h> | ||
| 26 | # endif | ||
| 27 | |||
| 25 | # ifdef __cplusplus | 28 | # ifdef __cplusplus |
| 26 | extern "C" { | 29 | extern "C" { |
| 27 | # endif | 30 | # endif |
| 28 | 31 | ||
| 32 | enum { SHA384_DIGEST_SIZE = 384 / 8 }; | ||
| 33 | enum { SHA512_DIGEST_SIZE = 512 / 8 }; | ||
| 34 | |||
| 35 | # if HAVE_OPENSSL_SHA512 | ||
| 36 | # define GL_OPENSSL_NAME 384 | ||
| 37 | # include "gl_openssl.h" | ||
| 38 | # define GL_OPENSSL_NAME 512 | ||
| 39 | # include "gl_openssl.h" | ||
| 40 | # else | ||
| 29 | /* Structure to save state of computation between the single steps. */ | 41 | /* Structure to save state of computation between the single steps. */ |
| 30 | struct sha512_ctx | 42 | struct sha512_ctx |
| 31 | { | 43 | { |
| @@ -36,9 +48,6 @@ struct sha512_ctx | |||
| 36 | u64 buffer[32]; | 48 | u64 buffer[32]; |
| 37 | }; | 49 | }; |
| 38 | 50 | ||
| 39 | enum { SHA384_DIGEST_SIZE = 384 / 8 }; | ||
| 40 | enum { SHA512_DIGEST_SIZE = 512 / 8 }; | ||
| 41 | |||
| 42 | /* Initialize structure containing state of computation. */ | 51 | /* Initialize structure containing state of computation. */ |
| 43 | extern void sha512_init_ctx (struct sha512_ctx *ctx); | 52 | extern void sha512_init_ctx (struct sha512_ctx *ctx); |
| 44 | extern void sha384_init_ctx (struct sha512_ctx *ctx); | 53 | extern void sha384_init_ctx (struct sha512_ctx *ctx); |
| @@ -75,12 +84,6 @@ extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf); | |||
| 75 | extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf); | 84 | extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf); |
| 76 | 85 | ||
| 77 | 86 | ||
| 78 | /* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The | ||
| 79 | resulting message digest number will be written into the 64 (48) bytes | ||
| 80 | beginning at RESBLOCK. */ | ||
| 81 | extern int sha512_stream (FILE *stream, void *resblock); | ||
| 82 | extern int sha384_stream (FILE *stream, void *resblock); | ||
| 83 | |||
| 84 | /* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER. The | 87 | /* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER. The |
| 85 | result is always in little endian byte order, so that a byte-wise | 88 | result is always in little endian byte order, so that a byte-wise |
| 86 | output yields to the wanted ASCII representation of the message | 89 | output yields to the wanted ASCII representation of the message |
| @@ -88,6 +91,14 @@ extern int sha384_stream (FILE *stream, void *resblock); | |||
| 88 | extern void *sha512_buffer (const char *buffer, size_t len, void *resblock); | 91 | extern void *sha512_buffer (const char *buffer, size_t len, void *resblock); |
| 89 | extern void *sha384_buffer (const char *buffer, size_t len, void *resblock); | 92 | extern void *sha384_buffer (const char *buffer, size_t len, void *resblock); |
| 90 | 93 | ||
| 94 | # endif | ||
| 95 | /* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The | ||
| 96 | resulting message digest number will be written into the 64 (48) bytes | ||
| 97 | beginning at RESBLOCK. */ | ||
| 98 | extern int sha512_stream (FILE *stream, void *resblock); | ||
| 99 | extern int sha384_stream (FILE *stream, void *resblock); | ||
| 100 | |||
| 101 | |||
| 91 | # ifdef __cplusplus | 102 | # ifdef __cplusplus |
| 92 | } | 103 | } |
| 93 | # endif | 104 | # endif |
diff --git a/lib/sig2str.c b/lib/sig2str.c index 8b36e2facf0..119006af5bf 100644 --- a/lib/sig2str.c +++ b/lib/sig2str.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* sig2str.c -- convert between signal names and numbers | 1 | /* sig2str.c -- convert between signal names and numbers |
| 2 | 2 | ||
| 3 | Copyright (C) 2002, 2004, 2006, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2002, 2004, 2006, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -325,21 +325,25 @@ sig2str (int signum, char *signame) | |||
| 325 | { | 325 | { |
| 326 | int rtmin = SIGRTMIN; | 326 | int rtmin = SIGRTMIN; |
| 327 | int rtmax = SIGRTMAX; | 327 | int rtmax = SIGRTMAX; |
| 328 | int base, delta; | ||
| 328 | 329 | ||
| 329 | if (! (rtmin <= signum && signum <= rtmax)) | 330 | if (! (rtmin <= signum && signum <= rtmax)) |
| 330 | return -1; | 331 | return -1; |
| 331 | 332 | ||
| 332 | if (signum <= rtmin + (rtmax - rtmin) / 2) | 333 | if (signum <= rtmin + (rtmax - rtmin) / 2) |
| 333 | { | 334 | { |
| 334 | int delta = signum - rtmin; | 335 | strcpy (signame, "RTMIN"); |
| 335 | sprintf (signame, delta ? "RTMIN+%d" : "RTMIN", delta); | 336 | base = rtmin; |
| 336 | } | 337 | } |
| 337 | else | 338 | else |
| 338 | { | 339 | { |
| 339 | int delta = rtmax - signum; | 340 | strcpy (signame, "RTMAX"); |
| 340 | sprintf (signame, delta ? "RTMAX-%d" : "RTMAX", delta); | 341 | base = rtmax; |
| 341 | } | 342 | } |
| 342 | 343 | ||
| 344 | delta = signum - base; | ||
| 345 | if (delta != 0) | ||
| 346 | sprintf (signame + 5, "%+d", delta); | ||
| 343 | return 0; | 347 | return 0; |
| 344 | } | 348 | } |
| 345 | } | 349 | } |
diff --git a/lib/sig2str.h b/lib/sig2str.h index d16be98c076..fc90b720741 100644 --- a/lib/sig2str.h +++ b/lib/sig2str.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* sig2str.h -- convert between signal names and numbers | 1 | /* sig2str.h -- convert between signal names and numbers |
| 2 | 2 | ||
| 3 | Copyright (C) 2002, 2005, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2002, 2005, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -27,9 +27,17 @@ | |||
| 27 | /* Size of a buffer needed to hold a signal name like "HUP". */ | 27 | /* Size of a buffer needed to hold a signal name like "HUP". */ |
| 28 | # define SIG2STR_MAX (sizeof "SIGRTMAX" + INT_STRLEN_BOUND (int) - 1) | 28 | # define SIG2STR_MAX (sizeof "SIGRTMAX" + INT_STRLEN_BOUND (int) - 1) |
| 29 | 29 | ||
| 30 | #ifdef __cplusplus | ||
| 31 | extern "C" { | ||
| 32 | #endif | ||
| 33 | |||
| 30 | int sig2str (int, char *); | 34 | int sig2str (int, char *); |
| 31 | int str2sig (char const *, int *); | 35 | int str2sig (char const *, int *); |
| 32 | 36 | ||
| 37 | #ifdef __cplusplus | ||
| 38 | } | ||
| 39 | #endif | ||
| 40 | |||
| 33 | #endif | 41 | #endif |
| 34 | 42 | ||
| 35 | /* An upper bound on signal numbers allowed by the system. */ | 43 | /* An upper bound on signal numbers allowed by the system. */ |
diff --git a/lib/signal.in.h b/lib/signal.in.h index 54849504d77..925e16f2b0e 100644 --- a/lib/signal.in.h +++ b/lib/signal.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* A GNU-like <signal.h>. | 1 | /* A GNU-like <signal.h>. |
| 2 | 2 | ||
| 3 | Copyright (C) 2006-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2006-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -195,6 +195,20 @@ typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1]; | |||
| 195 | 195 | ||
| 196 | # endif | 196 | # endif |
| 197 | 197 | ||
| 198 | /* When also using extern inline, suppress the use of static inline in | ||
| 199 | standard headers of problematic Apple configurations, as Libc at | ||
| 200 | least through Libc-825.26 (2013-04-09) mishandles it; see, e.g., | ||
| 201 | <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>. | ||
| 202 | Perhaps Apple will fix this some day. */ | ||
| 203 | #if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \ | ||
| 204 | && (defined __i386__ || defined __x86_64__)) | ||
| 205 | # undef sigaddset | ||
| 206 | # undef sigdelset | ||
| 207 | # undef sigemptyset | ||
| 208 | # undef sigfillset | ||
| 209 | # undef sigismember | ||
| 210 | #endif | ||
| 211 | |||
| 198 | /* Test whether a given signal is contained in a signal set. */ | 212 | /* Test whether a given signal is contained in a signal set. */ |
| 199 | # if @HAVE_POSIX_SIGNALBLOCKING@ | 213 | # if @HAVE_POSIX_SIGNALBLOCKING@ |
| 200 | /* This function is defined as a macro on Mac OS X. */ | 214 | /* This function is defined as a macro on Mac OS X. */ |
diff --git a/lib/stat-time.h b/lib/stat-time.h index 2d3b5cd6514..b3df6eb816d 100644 --- a/lib/stat-time.h +++ b/lib/stat-time.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* stat-related time functions. | 1 | /* stat-related time functions. |
| 2 | 2 | ||
| 3 | Copyright (C) 2005, 2007, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2005, 2007, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -23,6 +23,9 @@ | |||
| 23 | #include <sys/stat.h> | 23 | #include <sys/stat.h> |
| 24 | #include <time.h> | 24 | #include <time.h> |
| 25 | 25 | ||
| 26 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 27 | #error "Please include config.h first." | ||
| 28 | #endif | ||
| 26 | _GL_INLINE_HEADER_BEGIN | 29 | _GL_INLINE_HEADER_BEGIN |
| 27 | #ifndef _GL_STAT_TIME_INLINE | 30 | #ifndef _GL_STAT_TIME_INLINE |
| 28 | # define _GL_STAT_TIME_INLINE _GL_INLINE | 31 | # define _GL_STAT_TIME_INLINE _GL_INLINE |
diff --git a/lib/stat.c b/lib/stat.c index f888130d263..35f4b0b1a51 100644 --- a/lib/stat.c +++ b/lib/stat.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Work around platform bugs in stat. | 1 | /* Work around platform bugs in stat. |
| 2 | Copyright (C) 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2009-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h index c3a67321b0e..dcaab55b577 100644 --- a/lib/stdalign.in.h +++ b/lib/stdalign.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* A substitute for ISO C11 <stdalign.h>. | 1 | /* A substitute for ISO C11 <stdalign.h>. |
| 2 | 2 | ||
| 3 | Copyright 2011-2013 Free Software Foundation, Inc. | 3 | Copyright 2011-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -41,13 +41,28 @@ | |||
| 41 | are 4 unless the option '-malign-double' is used. | 41 | are 4 unless the option '-malign-double' is used. |
| 42 | 42 | ||
| 43 | The result cannot be used as a value for an 'enum' constant, if you | 43 | The result cannot be used as a value for an 'enum' constant, if you |
| 44 | want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. */ | 44 | want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. |
| 45 | |||
| 46 | Include <stddef.h> for offsetof. */ | ||
| 45 | #include <stddef.h> | 47 | #include <stddef.h> |
| 46 | #if defined __cplusplus | 48 | |
| 49 | /* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other | ||
| 50 | standard headers, defines conflicting implementations of _Alignas | ||
| 51 | and _Alignof that are no better than ours; override them. */ | ||
| 52 | #undef _Alignas | ||
| 53 | #undef _Alignof | ||
| 54 | |||
| 55 | #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 | ||
| 56 | # ifdef __cplusplus | ||
| 57 | # if 201103 <= __cplusplus | ||
| 58 | # define _Alignof(type) alignof (type) | ||
| 59 | # else | ||
| 47 | template <class __t> struct __alignof_helper { char __a; __t __b; }; | 60 | template <class __t> struct __alignof_helper { char __a; __t __b; }; |
| 48 | # define _Alignof(type) offsetof (__alignof_helper<type>, __b) | 61 | # define _Alignof(type) offsetof (__alignof_helper<type>, __b) |
| 49 | #else | 62 | # endif |
| 50 | # define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) | 63 | # else |
| 64 | # define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) | ||
| 65 | # endif | ||
| 51 | #endif | 66 | #endif |
| 52 | #define alignof _Alignof | 67 | #define alignof _Alignof |
| 53 | #define __alignof_is_defined 1 | 68 | #define __alignof_is_defined 1 |
| @@ -77,12 +92,17 @@ | |||
| 77 | 92 | ||
| 78 | */ | 93 | */ |
| 79 | 94 | ||
| 80 | #if __GNUC__ || __IBMC__ || __IBMCPP__ || 0x5110 <= __SUNPRO_C | 95 | #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 |
| 81 | # define _Alignas(a) __attribute__ ((__aligned__ (a))) | 96 | # if defined __cplusplus && 201103 <= __cplusplus |
| 82 | #elif 1300 <= _MSC_VER | 97 | # define _Alignas(a) alignas (a) |
| 83 | # define _Alignas(a) __declspec (align (a)) | 98 | # elif (__GNUC__ || __HP_cc || __HP_aCC || __IBMC__ || __IBMCPP__ \ |
| 99 | || __ICC || 0x5110 <= __SUNPRO_C) | ||
| 100 | # define _Alignas(a) __attribute__ ((__aligned__ (a))) | ||
| 101 | # elif 1300 <= _MSC_VER | ||
| 102 | # define _Alignas(a) __declspec (align (a)) | ||
| 103 | # endif | ||
| 84 | #endif | 104 | #endif |
| 85 | #ifdef _Alignas | 105 | #if defined _Alignas || (defined __STDC_VERSION && 201112 <= __STDC_VERSION__) |
| 86 | # define alignas _Alignas | 106 | # define alignas _Alignas |
| 87 | # define __alignas_is_defined 1 | 107 | # define __alignas_is_defined 1 |
| 88 | #endif | 108 | #endif |
diff --git a/lib/stdarg.in.h b/lib/stdarg.in.h index 7484842dbd3..5b37dd3601a 100644 --- a/lib/stdarg.in.h +++ b/lib/stdarg.in.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Substitute for and wrapper around <stdarg.h>. | 1 | /* Substitute for and wrapper around <stdarg.h>. |
| 2 | Copyright (C) 2008-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2008-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/stdbool.in.h b/lib/stdbool.in.h index 7c1577277fa..651e8dffdb3 100644 --- a/lib/stdbool.in.h +++ b/lib/stdbool.in.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc. | 1 | /* Copyright (C) 2001-2003, 2006-2014 Free Software Foundation, Inc. |
| 2 | Written by Bruno Haible <haible@clisp.cons.org>, 2001. | 2 | Written by Bruno Haible <haible@clisp.cons.org>, 2001. |
| 3 | 3 | ||
| 4 | This program is free software; you can redistribute it and/or modify | 4 | This program is free software; you can redistribute it and/or modify |
diff --git a/lib/stddef.in.h b/lib/stddef.in.h index 40f0536aaee..f5c0e056554 100644 --- a/lib/stddef.in.h +++ b/lib/stddef.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues. | 1 | /* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues. |
| 2 | 2 | ||
| 3 | Copyright (C) 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/stdint.in.h b/lib/stdint.in.h index 2db8b2e378b..5deca3969ab 100644 --- a/lib/stdint.in.h +++ b/lib/stdint.in.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* Copyright (C) 2001-2002, 2004-2013 Free Software Foundation, Inc. | 1 | /* Copyright (C) 2001-2002, 2004-2014 Free Software Foundation, Inc. |
| 2 | Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. | 2 | Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. |
| 3 | This file is part of gnulib. | 3 | This file is part of gnulib. |
| 4 | 4 | ||
diff --git a/lib/stdio.in.h b/lib/stdio.in.h index d6af99ca77d..1e1fe84c77d 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* A GNU-like <stdio.h>. | 1 | /* A GNU-like <stdio.h>. |
| 2 | 2 | ||
| 3 | Copyright (C) 2004, 2007-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2004, 2007-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -124,6 +124,15 @@ | |||
| 124 | #define _GL_STDIO_STRINGIZE(token) #token | 124 | #define _GL_STDIO_STRINGIZE(token) #token |
| 125 | #define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token) | 125 | #define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token) |
| 126 | 126 | ||
| 127 | /* When also using extern inline, suppress the use of static inline in | ||
| 128 | standard headers of problematic Apple configurations, as Libc at | ||
| 129 | least through Libc-825.26 (2013-04-09) mishandles it; see, e.g., | ||
| 130 | <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>. | ||
| 131 | Perhaps Apple will fix this some day. */ | ||
| 132 | #if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \ | ||
| 133 | && defined __GNUC__ && defined __STDC__) | ||
| 134 | # undef putc_unlocked | ||
| 135 | #endif | ||
| 127 | 136 | ||
| 128 | #if @GNULIB_DPRINTF@ | 137 | #if @GNULIB_DPRINTF@ |
| 129 | # if @REPLACE_DPRINTF@ | 138 | # if @REPLACE_DPRINTF@ |
| @@ -579,13 +588,23 @@ _GL_CXXALIAS_SYS (fwrite, size_t, | |||
| 579 | <http://sources.redhat.com/bugzilla/show_bug.cgi?id=11959>, | 588 | <http://sources.redhat.com/bugzilla/show_bug.cgi?id=11959>, |
| 580 | which sometimes causes an unwanted diagnostic for fwrite calls. | 589 | which sometimes causes an unwanted diagnostic for fwrite calls. |
| 581 | This affects only function declaration attributes under certain | 590 | This affects only function declaration attributes under certain |
| 582 | versions of gcc, and is not needed for C++. */ | 591 | versions of gcc and clang, and is not needed for C++. */ |
| 583 | # if (0 < __USE_FORTIFY_LEVEL \ | 592 | # if (0 < __USE_FORTIFY_LEVEL \ |
| 584 | && __GLIBC__ == 2 && 4 <= __GLIBC_MINOR__ && __GLIBC_MINOR__ <= 15 \ | 593 | && __GLIBC__ == 2 && 4 <= __GLIBC_MINOR__ && __GLIBC_MINOR__ <= 15 \ |
| 585 | && 3 < __GNUC__ + (4 <= __GNUC_MINOR__) \ | 594 | && 3 < __GNUC__ + (4 <= __GNUC_MINOR__) \ |
| 586 | && !defined __cplusplus) | 595 | && !defined __cplusplus) |
| 587 | # undef fwrite | 596 | # undef fwrite |
| 588 | # define fwrite(a, b, c, d) ({size_t __r = fwrite (a, b, c, d); __r; }) | 597 | # undef fwrite_unlocked |
| 598 | extern size_t __REDIRECT (rpl_fwrite, | ||
| 599 | (const void *__restrict, size_t, size_t, | ||
| 600 | FILE *__restrict), | ||
| 601 | fwrite); | ||
| 602 | extern size_t __REDIRECT (rpl_fwrite_unlocked, | ||
| 603 | (const void *__restrict, size_t, size_t, | ||
| 604 | FILE *__restrict), | ||
| 605 | fwrite_unlocked); | ||
| 606 | # define fwrite rpl_fwrite | ||
| 607 | # define fwrite_unlocked rpl_fwrite_unlocked | ||
| 589 | # endif | 608 | # endif |
| 590 | # endif | 609 | # endif |
| 591 | _GL_CXXALIASWARN (fwrite); | 610 | _GL_CXXALIASWARN (fwrite); |
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index c9552480e5d..46e10dba972 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* A GNU-like <stdlib.h>. | 1 | /* A GNU-like <stdlib.h>. |
| 2 | 2 | ||
| 3 | Copyright (C) 1995, 2001-2004, 2006-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 1995, 2001-2004, 2006-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/strftime.c b/lib/strftime.c index 91d5d85cbcf..c1ec41422bd 100644 --- a/lib/strftime.c +++ b/lib/strftime.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* Copyright (C) 1991-2001, 2003-2007, 2009-2013 Free Software Foundation, Inc. | 1 | /* Copyright (C) 1991-2001, 2003-2007, 2009-2014 Free Software Foundation, Inc. |
| 2 | 2 | ||
| 3 | NOTE: The canonical source of this file is maintained with the GNU C Library. | 3 | NOTE: The canonical source of this file is maintained with the GNU C Library. |
| 4 | Bugs can be reported to bug-glibc@prep.ai.mit.edu. | 4 | Bugs can be reported to bug-glibc@prep.ai.mit.edu. |
diff --git a/lib/strftime.h b/lib/strftime.h index a47e6d1e1f6..be016ea86cf 100644 --- a/lib/strftime.h +++ b/lib/strftime.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* declarations for strftime.c | 1 | /* declarations for strftime.c |
| 2 | 2 | ||
| 3 | Copyright (C) 2002, 2004, 2008-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2002, 2004, 2008-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/string.in.h b/lib/string.in.h index d7a6c9c923e..90621420598 100644 --- a/lib/string.in.h +++ b/lib/string.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* A GNU-like <string.h>. | 1 | /* A GNU-like <string.h>. |
| 2 | 2 | ||
| 3 | Copyright (C) 1995-1996, 2001-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 1995-1996, 2001-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/strtoimax.c b/lib/strtoimax.c index c9bd2ad3b1c..2c33d5857a9 100644 --- a/lib/strtoimax.c +++ b/lib/strtoimax.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Convert string representation of a number into an intmax_t value. | 1 | /* Convert string representation of a number into an intmax_t value. |
| 2 | 2 | ||
| 3 | Copyright (C) 1999, 2001-2004, 2006, 2009-2013 Free Software Foundation, | 3 | Copyright (C) 1999, 2001-2004, 2006, 2009-2014 Free Software Foundation, |
| 4 | Inc. | 4 | Inc. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify |
| @@ -28,48 +28,55 @@ | |||
| 28 | #include "verify.h" | 28 | #include "verify.h" |
| 29 | 29 | ||
| 30 | #ifdef UNSIGNED | 30 | #ifdef UNSIGNED |
| 31 | # ifndef HAVE_DECL_STRTOULL | 31 | # if HAVE_UNSIGNED_LONG_LONG_INT |
| 32 | # ifndef HAVE_DECL_STRTOULL | ||
| 32 | "this configure-time declaration test was not run" | 33 | "this configure-time declaration test was not run" |
| 33 | # endif | 34 | # endif |
| 34 | # if !HAVE_DECL_STRTOULL && HAVE_UNSIGNED_LONG_LONG_INT | 35 | # if !HAVE_DECL_STRTOULL |
| 35 | unsigned long long int strtoull (char const *, char **, int); | 36 | unsigned long long int strtoull (char const *, char **, int); |
| 37 | # endif | ||
| 36 | # endif | 38 | # endif |
| 37 | 39 | ||
| 38 | #else | 40 | #else |
| 39 | 41 | ||
| 40 | # ifndef HAVE_DECL_STRTOLL | 42 | # if HAVE_LONG_LONG_INT |
| 43 | # ifndef HAVE_DECL_STRTOLL | ||
| 41 | "this configure-time declaration test was not run" | 44 | "this configure-time declaration test was not run" |
| 42 | # endif | 45 | # endif |
| 43 | # if !HAVE_DECL_STRTOLL && HAVE_LONG_LONG_INT | 46 | # if !HAVE_DECL_STRTOLL |
| 44 | long long int strtoll (char const *, char **, int); | 47 | long long int strtoll (char const *, char **, int); |
| 48 | # endif | ||
| 45 | # endif | 49 | # endif |
| 46 | #endif | 50 | #endif |
| 47 | 51 | ||
| 48 | #ifdef UNSIGNED | 52 | #ifdef UNSIGNED |
| 49 | # define Have_long_long HAVE_UNSIGNED_LONG_LONG_INT | 53 | # define Have_long_long HAVE_UNSIGNED_LONG_LONG_INT |
| 50 | # define Int uintmax_t | 54 | # define Int uintmax_t |
| 55 | # define Strtoimax strtoumax | ||
| 56 | # define Strtol strtoul | ||
| 57 | # define Strtoll strtoull | ||
| 51 | # define Unsigned unsigned | 58 | # define Unsigned unsigned |
| 52 | # define strtoimax strtoumax | ||
| 53 | # define strtol strtoul | ||
| 54 | # define strtoll strtoull | ||
| 55 | #else | 59 | #else |
| 56 | # define Have_long_long HAVE_LONG_LONG_INT | 60 | # define Have_long_long HAVE_LONG_LONG_INT |
| 57 | # define Int intmax_t | 61 | # define Int intmax_t |
| 62 | # define Strtoimax strtoimax | ||
| 63 | # define Strtol strtol | ||
| 64 | # define Strtoll strtoll | ||
| 58 | # define Unsigned | 65 | # define Unsigned |
| 59 | #endif | 66 | #endif |
| 60 | 67 | ||
| 61 | Int | 68 | Int |
| 62 | strtoimax (char const *ptr, char **endptr, int base) | 69 | Strtoimax (char const *ptr, char **endptr, int base) |
| 63 | { | 70 | { |
| 64 | #if Have_long_long | 71 | #if Have_long_long |
| 65 | verify (sizeof (Int) == sizeof (Unsigned long int) | 72 | verify (sizeof (Int) == sizeof (Unsigned long int) |
| 66 | || sizeof (Int) == sizeof (Unsigned long long int)); | 73 | || sizeof (Int) == sizeof (Unsigned long long int)); |
| 67 | 74 | ||
| 68 | if (sizeof (Int) != sizeof (Unsigned long int)) | 75 | if (sizeof (Int) != sizeof (Unsigned long int)) |
| 69 | return strtoll (ptr, endptr, base); | 76 | return Strtoll (ptr, endptr, base); |
| 70 | #else | 77 | #else |
| 71 | verify (sizeof (Int) == sizeof (Unsigned long int)); | 78 | verify (sizeof (Int) == sizeof (Unsigned long int)); |
| 72 | #endif | 79 | #endif |
| 73 | 80 | ||
| 74 | return strtol (ptr, endptr, base); | 81 | return Strtol (ptr, endptr, base); |
| 75 | } | 82 | } |
diff --git a/lib/strtol.c b/lib/strtol.c index 379eda8c11b..2e015dc5bdd 100644 --- a/lib/strtol.c +++ b/lib/strtol.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Convert string representation of a number into an integer value. | 1 | /* Convert string representation of a number into an integer value. |
| 2 | 2 | ||
| 3 | Copyright (C) 1991-1992, 1994-1999, 2003, 2005-2007, 2009-2013 Free Software | 3 | Copyright (C) 1991-1992, 1994-1999, 2003, 2005-2007, 2009-2014 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | 5 | ||
| 6 | NOTE: The canonical source of this file is maintained with the GNU C | 6 | NOTE: The canonical source of this file is maintained with the GNU C |
diff --git a/lib/strtoll.c b/lib/strtoll.c index bb424002c96..47dfaa0677a 100644 --- a/lib/strtoll.c +++ b/lib/strtoll.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Function to parse a 'long long int' from text. | 1 | /* Function to parse a 'long long int' from text. |
| 2 | Copyright (C) 1995-1997, 1999, 2001, 2009-2013 Free Software Foundation, | 2 | Copyright (C) 1995-1997, 1999, 2001, 2009-2014 Free Software Foundation, |
| 3 | Inc. | 3 | Inc. |
| 4 | This file is part of the GNU C Library. | 4 | This file is part of the GNU C Library. |
| 5 | 5 | ||
diff --git a/lib/strtoul.c b/lib/strtoul.c index a0ca376cdac..4c5ceaff96f 100644 --- a/lib/strtoul.c +++ b/lib/strtoul.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* Copyright (C) 1991, 1997, 2009-2013 Free Software Foundation, Inc. | 1 | /* Copyright (C) 1991, 1997, 2009-2014 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. | 2 | This file is part of the GNU C Library. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 4 | This program is free software: you can redistribute it and/or modify |
diff --git a/lib/strtoull.c b/lib/strtoull.c index 494cc2f2926..30e6e0279e1 100644 --- a/lib/strtoull.c +++ b/lib/strtoull.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Function to parse an 'unsigned long long int' from text. | 1 | /* Function to parse an 'unsigned long long int' from text. |
| 2 | Copyright (C) 1995-1997, 1999, 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 1995-1997, 1999, 2009-2014 Free Software Foundation, Inc. |
| 3 | NOTE: The canonical source of this file is maintained with the GNU C | 3 | NOTE: The canonical source of this file is maintained with the GNU C |
| 4 | Library. Bugs can be reported to bug-glibc@gnu.org. | 4 | Library. Bugs can be reported to bug-glibc@gnu.org. |
| 5 | 5 | ||
diff --git a/lib/symlink.c b/lib/symlink.c index d3c9f21bb78..0e3fae255c2 100644 --- a/lib/symlink.c +++ b/lib/symlink.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Stub for symlink(). | 1 | /* Stub for symlink(). |
| 2 | Copyright (C) 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2009-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h index 521ccef321d..a876b9caa3f 100644 --- a/lib/sys_select.in.h +++ b/lib/sys_select.in.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Substitute for <sys/select.h>. | 1 | /* Substitute for <sys/select.h>. |
| 2 | Copyright (C) 2007-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2007-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
| @@ -21,23 +21,27 @@ | |||
| 21 | 21 | ||
| 22 | /* On OSF/1 and Solaris 2.6, <sys/types.h> and <sys/time.h> | 22 | /* On OSF/1 and Solaris 2.6, <sys/types.h> and <sys/time.h> |
| 23 | both include <sys/select.h>. | 23 | both include <sys/select.h>. |
| 24 | On Cygwin, <sys/time.h> includes <sys/select.h>. | ||
| 24 | Simply delegate to the system's header in this case. */ | 25 | Simply delegate to the system's header in this case. */ |
| 25 | #if (@HAVE_SYS_SELECT_H@ \ | 26 | #if (@HAVE_SYS_SELECT_H@ \ |
| 26 | && ((defined __osf__ && defined _SYS_TYPES_H_ && defined _OSF_SOURCE) \ | 27 | && ((defined __osf__ && defined _SYS_TYPES_H_ \ |
| 28 | && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H \ | ||
| 29 | && defined _OSF_SOURCE) \ | ||
| 27 | || (defined __sun && defined _SYS_TYPES_H \ | 30 | || (defined __sun && defined _SYS_TYPES_H \ |
| 28 | && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \ | 31 | && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \ |
| 29 | || defined __EXTENSIONS__))) \ | 32 | || defined __EXTENSIONS__)))) |
| 30 | && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H) | ||
| 31 | 33 | ||
| 32 | # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H | 34 | # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H |
| 33 | # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@ | 35 | # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@ |
| 34 | 36 | ||
| 35 | #elif (@HAVE_SYS_SELECT_H@ \ | 37 | #elif (@HAVE_SYS_SELECT_H@ \ |
| 36 | && ((defined __osf__ && defined _SYS_TIME_H_ && defined _OSF_SOURCE) \ | 38 | && (defined _CYGWIN_SYS_TIME_H \ |
| 39 | || (defined __osf__ && defined _SYS_TIME_H_ \ | ||
| 40 | && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H \ | ||
| 41 | && defined _OSF_SOURCE) \ | ||
| 37 | || (defined __sun && defined _SYS_TIME_H \ | 42 | || (defined __sun && defined _SYS_TIME_H \ |
| 38 | && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \ | 43 | && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \ |
| 39 | || defined __EXTENSIONS__))) \ | 44 | || defined __EXTENSIONS__)))) |
| 40 | && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H) | ||
| 41 | 45 | ||
| 42 | # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H | 46 | # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H |
| 43 | # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@ | 47 | # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@ |
diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h index acc36947e38..b47a7ff0ae7 100644 --- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Provide a more complete sys/stat header file. | 1 | /* Provide a more complete sys/stat header file. |
| 2 | Copyright (C) 2005-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2005-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/sys_time.in.h b/lib/sys_time.in.h index 656c3f13ad2..30057ad49fd 100644 --- a/lib/sys_time.in.h +++ b/lib/sys_time.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Provide a more complete sys/time.h. | 1 | /* Provide a more complete sys/time.h. |
| 2 | 2 | ||
| 3 | Copyright (C) 2007-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2007-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -24,6 +24,15 @@ | |||
| 24 | #endif | 24 | #endif |
| 25 | @PRAGMA_COLUMNS@ | 25 | @PRAGMA_COLUMNS@ |
| 26 | 26 | ||
| 27 | /* On Cygwin and on many BSDish systems, <sys/time.h> includes itself | ||
| 28 | recursively via <sys/select.h>. | ||
| 29 | Simply delegate to the system's header in this case; it is a no-op. | ||
| 30 | Without this extra ifdef, the C++ gettimeofday declaration below | ||
| 31 | would be a forward declaration in gnulib's nested <sys/time.h>. */ | ||
| 32 | #if defined _CYGWIN_SYS_TIME_H || defined _SYS_TIME_H || defined _SYS_TIME_H_ | ||
| 33 | # @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@ | ||
| 34 | #else | ||
| 35 | |||
| 27 | /* The include_next requires a split double-inclusion guard. */ | 36 | /* The include_next requires a split double-inclusion guard. */ |
| 28 | #if @HAVE_SYS_TIME_H@ | 37 | #if @HAVE_SYS_TIME_H@ |
| 29 | # @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@ | 38 | # @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@ |
| @@ -200,4 +209,5 @@ _GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - " | |||
| 200 | #endif | 209 | #endif |
| 201 | 210 | ||
| 202 | #endif /* _@GUARD_PREFIX@_SYS_TIME_H */ | 211 | #endif /* _@GUARD_PREFIX@_SYS_TIME_H */ |
| 212 | #endif /* _CYGWIN_SYS_TIME_H */ | ||
| 203 | #endif /* _@GUARD_PREFIX@_SYS_TIME_H */ | 213 | #endif /* _@GUARD_PREFIX@_SYS_TIME_H */ |
diff --git a/lib/sys_types.in.h b/lib/sys_types.in.h index d7da35623b1..d3a4be1074a 100644 --- a/lib/sys_types.in.h +++ b/lib/sys_types.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Provide a more complete sys/types.h. | 1 | /* Provide a more complete sys/types.h. |
| 2 | 2 | ||
| 3 | Copyright (C) 2011-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/tempname.c b/lib/tempname.c new file mode 100644 index 00000000000..9b713cb04c9 --- /dev/null +++ b/lib/tempname.c | |||
| @@ -0,0 +1,306 @@ | |||
| 1 | /* tempname.c - generate the name of a temporary file. | ||
| 2 | |||
| 3 | Copyright (C) 1991-2003, 2005-2007, 2009-2014 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 | /* Extracted from glibc sysdeps/posix/tempname.c. See also tmpdir.c. */ | ||
| 19 | |||
| 20 | #if !_LIBC | ||
| 21 | # include <config.h> | ||
| 22 | # include "tempname.h" | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #include <sys/types.h> | ||
| 26 | #include <assert.h> | ||
| 27 | |||
| 28 | #include <errno.h> | ||
| 29 | #ifndef __set_errno | ||
| 30 | # define __set_errno(Val) errno = (Val) | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #include <stdio.h> | ||
| 34 | #ifndef P_tmpdir | ||
| 35 | # define P_tmpdir "/tmp" | ||
| 36 | #endif | ||
| 37 | #ifndef TMP_MAX | ||
| 38 | # define TMP_MAX 238328 | ||
| 39 | #endif | ||
| 40 | #ifndef __GT_FILE | ||
| 41 | # define __GT_FILE 0 | ||
| 42 | # define __GT_DIR 1 | ||
| 43 | # define __GT_NOCREATE 2 | ||
| 44 | #endif | ||
| 45 | #if !_LIBC && (GT_FILE != __GT_FILE || GT_DIR != __GT_DIR \ | ||
| 46 | || GT_NOCREATE != __GT_NOCREATE) | ||
| 47 | # error report this to bug-gnulib@gnu.org | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #include <stddef.h> | ||
| 51 | #include <stdlib.h> | ||
| 52 | #include <string.h> | ||
| 53 | |||
| 54 | #include <fcntl.h> | ||
| 55 | #include <sys/time.h> | ||
| 56 | #include <stdint.h> | ||
| 57 | #include <unistd.h> | ||
| 58 | |||
| 59 | #include <sys/stat.h> | ||
| 60 | |||
| 61 | #if _LIBC | ||
| 62 | # define struct_stat64 struct stat64 | ||
| 63 | #else | ||
| 64 | # define struct_stat64 struct stat | ||
| 65 | # define __gen_tempname gen_tempname | ||
| 66 | # define __getpid getpid | ||
| 67 | # define __gettimeofday gettimeofday | ||
| 68 | # define __mkdir mkdir | ||
| 69 | # define __open open | ||
| 70 | # define __lxstat64(version, file, buf) lstat (file, buf) | ||
| 71 | # define __secure_getenv secure_getenv | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #ifdef _LIBC | ||
| 75 | # include <hp-timing.h> | ||
| 76 | # if HP_TIMING_AVAIL | ||
| 77 | # define RANDOM_BITS(Var) \ | ||
| 78 | if (__builtin_expect (value == UINT64_C (0), 0)) \ | ||
| 79 | { \ | ||
| 80 | /* If this is the first time this function is used initialize \ | ||
| 81 | the variable we accumulate the value in to some somewhat \ | ||
| 82 | random value. If we'd not do this programs at startup time \ | ||
| 83 | might have a reduced set of possible names, at least on slow \ | ||
| 84 | machines. */ \ | ||
| 85 | struct timeval tv; \ | ||
| 86 | __gettimeofday (&tv, NULL); \ | ||
| 87 | value = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; \ | ||
| 88 | } \ | ||
| 89 | HP_TIMING_NOW (Var) | ||
| 90 | # endif | ||
| 91 | #endif | ||
| 92 | |||
| 93 | /* Use the widest available unsigned type if uint64_t is not | ||
| 94 | available. The algorithm below extracts a number less than 62**6 | ||
| 95 | (approximately 2**35.725) from uint64_t, so ancient hosts where | ||
| 96 | uintmax_t is only 32 bits lose about 3.725 bits of randomness, | ||
| 97 | which is better than not having mkstemp at all. */ | ||
| 98 | #if !defined UINT64_MAX && !defined uint64_t | ||
| 99 | # define uint64_t uintmax_t | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #if _LIBC | ||
| 103 | /* Return nonzero if DIR is an existent directory. */ | ||
| 104 | static int | ||
| 105 | direxists (const char *dir) | ||
| 106 | { | ||
| 107 | struct_stat64 buf; | ||
| 108 | return __xstat64 (_STAT_VER, dir, &buf) == 0 && S_ISDIR (buf.st_mode); | ||
| 109 | } | ||
| 110 | |||
| 111 | /* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is | ||
| 112 | non-null and exists, uses it; otherwise uses the first of $TMPDIR, | ||
| 113 | P_tmpdir, /tmp that exists. Copies into TMPL a template suitable | ||
| 114 | for use with mk[s]temp. Will fail (-1) if DIR is non-null and | ||
| 115 | doesn't exist, none of the searched dirs exists, or there's not | ||
| 116 | enough space in TMPL. */ | ||
| 117 | int | ||
| 118 | __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, | ||
| 119 | int try_tmpdir) | ||
| 120 | { | ||
| 121 | const char *d; | ||
| 122 | size_t dlen, plen; | ||
| 123 | |||
| 124 | if (!pfx || !pfx[0]) | ||
| 125 | { | ||
| 126 | pfx = "file"; | ||
| 127 | plen = 4; | ||
| 128 | } | ||
| 129 | else | ||
| 130 | { | ||
| 131 | plen = strlen (pfx); | ||
| 132 | if (plen > 5) | ||
| 133 | plen = 5; | ||
| 134 | } | ||
| 135 | |||
| 136 | if (try_tmpdir) | ||
| 137 | { | ||
| 138 | d = __secure_getenv ("TMPDIR"); | ||
| 139 | if (d != NULL && direxists (d)) | ||
| 140 | dir = d; | ||
| 141 | else if (dir != NULL && direxists (dir)) | ||
| 142 | /* nothing */ ; | ||
| 143 | else | ||
| 144 | dir = NULL; | ||
| 145 | } | ||
| 146 | if (dir == NULL) | ||
| 147 | { | ||
| 148 | if (direxists (P_tmpdir)) | ||
| 149 | dir = P_tmpdir; | ||
| 150 | else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp")) | ||
| 151 | dir = "/tmp"; | ||
| 152 | else | ||
| 153 | { | ||
| 154 | __set_errno (ENOENT); | ||
| 155 | return -1; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | dlen = strlen (dir); | ||
| 160 | while (dlen > 1 && dir[dlen - 1] == '/') | ||
| 161 | dlen--; /* remove trailing slashes */ | ||
| 162 | |||
| 163 | /* check we have room for "${dir}/${pfx}XXXXXX\0" */ | ||
| 164 | if (tmpl_len < dlen + 1 + plen + 6 + 1) | ||
| 165 | { | ||
| 166 | __set_errno (EINVAL); | ||
| 167 | return -1; | ||
| 168 | } | ||
| 169 | |||
| 170 | sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx); | ||
| 171 | return 0; | ||
| 172 | } | ||
| 173 | #endif /* _LIBC */ | ||
| 174 | |||
| 175 | /* These are the characters used in temporary file names. */ | ||
| 176 | static const char letters[] = | ||
| 177 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
| 178 | |||
| 179 | /* Generate a temporary file name based on TMPL. TMPL must match the | ||
| 180 | rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix). | ||
| 181 | The name constructed does not exist at the time of the call to | ||
| 182 | __gen_tempname. TMPL is overwritten with the result. | ||
| 183 | |||
| 184 | KIND may be one of: | ||
| 185 | __GT_NOCREATE: simply verify that the name does not exist | ||
| 186 | at the time of the call. | ||
| 187 | __GT_FILE: create the file using open(O_CREAT|O_EXCL) | ||
| 188 | and return a read-write fd. The file is mode 0600. | ||
| 189 | __GT_DIR: create a directory, which will be mode 0700. | ||
| 190 | |||
| 191 | We use a clever algorithm to get hard-to-predict names. */ | ||
| 192 | int | ||
| 193 | __gen_tempname (char *tmpl, int suffixlen, int flags, int kind) | ||
| 194 | { | ||
| 195 | int len; | ||
| 196 | char *XXXXXX; | ||
| 197 | static uint64_t value; | ||
| 198 | uint64_t random_time_bits; | ||
| 199 | unsigned int count; | ||
| 200 | int fd = -1; | ||
| 201 | int save_errno = errno; | ||
| 202 | struct_stat64 st; | ||
| 203 | |||
| 204 | /* A lower bound on the number of temporary files to attempt to | ||
| 205 | generate. The maximum total number of temporary file names that | ||
| 206 | can exist for a given template is 62**6. It should never be | ||
| 207 | necessary to try all of these combinations. Instead if a reasonable | ||
| 208 | number of names is tried (we define reasonable as 62**3) fail to | ||
| 209 | give the system administrator the chance to remove the problems. */ | ||
| 210 | #define ATTEMPTS_MIN (62 * 62 * 62) | ||
| 211 | |||
| 212 | /* The number of times to attempt to generate a temporary file. To | ||
| 213 | conform to POSIX, this must be no smaller than TMP_MAX. */ | ||
| 214 | #if ATTEMPTS_MIN < TMP_MAX | ||
| 215 | unsigned int attempts = TMP_MAX; | ||
| 216 | #else | ||
| 217 | unsigned int attempts = ATTEMPTS_MIN; | ||
| 218 | #endif | ||
| 219 | |||
| 220 | len = strlen (tmpl); | ||
| 221 | if (len < 6 + suffixlen || memcmp (&tmpl[len - 6 - suffixlen], "XXXXXX", 6)) | ||
| 222 | { | ||
| 223 | __set_errno (EINVAL); | ||
| 224 | return -1; | ||
| 225 | } | ||
| 226 | |||
| 227 | /* This is where the Xs start. */ | ||
| 228 | XXXXXX = &tmpl[len - 6 - suffixlen]; | ||
| 229 | |||
| 230 | /* Get some more or less random data. */ | ||
| 231 | #ifdef RANDOM_BITS | ||
| 232 | RANDOM_BITS (random_time_bits); | ||
| 233 | #else | ||
| 234 | { | ||
| 235 | struct timeval tv; | ||
| 236 | __gettimeofday (&tv, NULL); | ||
| 237 | random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; | ||
| 238 | } | ||
| 239 | #endif | ||
| 240 | value += random_time_bits ^ __getpid (); | ||
| 241 | |||
| 242 | for (count = 0; count < attempts; value += 7777, ++count) | ||
| 243 | { | ||
| 244 | uint64_t v = value; | ||
| 245 | |||
| 246 | /* Fill in the random bits. */ | ||
| 247 | XXXXXX[0] = letters[v % 62]; | ||
| 248 | v /= 62; | ||
| 249 | XXXXXX[1] = letters[v % 62]; | ||
| 250 | v /= 62; | ||
| 251 | XXXXXX[2] = letters[v % 62]; | ||
| 252 | v /= 62; | ||
| 253 | XXXXXX[3] = letters[v % 62]; | ||
| 254 | v /= 62; | ||
| 255 | XXXXXX[4] = letters[v % 62]; | ||
| 256 | v /= 62; | ||
| 257 | XXXXXX[5] = letters[v % 62]; | ||
| 258 | |||
| 259 | switch (kind) | ||
| 260 | { | ||
| 261 | case __GT_FILE: | ||
| 262 | fd = __open (tmpl, | ||
| 263 | (flags & ~O_ACCMODE) | ||
| 264 | | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); | ||
| 265 | break; | ||
| 266 | |||
| 267 | case __GT_DIR: | ||
| 268 | fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR); | ||
| 269 | break; | ||
| 270 | |||
| 271 | case __GT_NOCREATE: | ||
| 272 | /* This case is backward from the other three. __gen_tempname | ||
| 273 | succeeds if __xstat fails because the name does not exist. | ||
| 274 | Note the continue to bypass the common logic at the bottom | ||
| 275 | of the loop. */ | ||
| 276 | if (__lxstat64 (_STAT_VER, tmpl, &st) < 0) | ||
| 277 | { | ||
| 278 | if (errno == ENOENT) | ||
| 279 | { | ||
| 280 | __set_errno (save_errno); | ||
| 281 | return 0; | ||
| 282 | } | ||
| 283 | else | ||
| 284 | /* Give up now. */ | ||
| 285 | return -1; | ||
| 286 | } | ||
| 287 | continue; | ||
| 288 | |||
| 289 | default: | ||
| 290 | assert (! "invalid KIND in __gen_tempname"); | ||
| 291 | abort (); | ||
| 292 | } | ||
| 293 | |||
| 294 | if (fd >= 0) | ||
| 295 | { | ||
| 296 | __set_errno (save_errno); | ||
| 297 | return fd; | ||
| 298 | } | ||
| 299 | else if (errno != EEXIST) | ||
| 300 | return -1; | ||
| 301 | } | ||
| 302 | |||
| 303 | /* We got out of the loop because we ran out of combinations to try. */ | ||
| 304 | __set_errno (EEXIST); | ||
| 305 | return -1; | ||
| 306 | } | ||
diff --git a/lib/tempname.h b/lib/tempname.h new file mode 100644 index 00000000000..44d5f04bbf9 --- /dev/null +++ b/lib/tempname.h | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | /* Create a temporary file or directory. | ||
| 2 | |||
| 3 | Copyright (C) 2006, 2009-2014 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 | /* header written by Eric Blake */ | ||
| 19 | |||
| 20 | #ifndef GL_TEMPNAME_H | ||
| 21 | # define GL_TEMPNAME_H | ||
| 22 | |||
| 23 | # include <stdio.h> | ||
| 24 | |||
| 25 | # ifdef __GT_FILE | ||
| 26 | # define GT_FILE __GT_FILE | ||
| 27 | # define GT_DIR __GT_DIR | ||
| 28 | # define GT_NOCREATE __GT_NOCREATE | ||
| 29 | # else | ||
| 30 | # define GT_FILE 0 | ||
| 31 | # define GT_DIR 1 | ||
| 32 | # define GT_NOCREATE 2 | ||
| 33 | # endif | ||
| 34 | |||
| 35 | /* Generate a temporary file name based on TMPL. TMPL must match the | ||
| 36 | rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix). | ||
| 37 | The name constructed does not exist at the time of the call to | ||
| 38 | gen_tempname. TMPL is overwritten with the result. | ||
| 39 | |||
| 40 | KIND may be one of: | ||
| 41 | GT_NOCREATE: simply verify that the name does not exist | ||
| 42 | at the time of the call. | ||
| 43 | GT_FILE: create a large file using open(O_CREAT|O_EXCL) | ||
| 44 | and return a read-write fd. The file is mode 0600. | ||
| 45 | GT_DIR: create a directory, which will be mode 0700. | ||
| 46 | |||
| 47 | We use a clever algorithm to get hard-to-predict names. */ | ||
| 48 | extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind); | ||
| 49 | |||
| 50 | #endif /* GL_TEMPNAME_H */ | ||
diff --git a/lib/time.in.h b/lib/time.in.h index 8ced7947445..81abdf46e0b 100644 --- a/lib/time.in.h +++ b/lib/time.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* A more-standard <time.h>. | 1 | /* A more-standard <time.h>. |
| 2 | 2 | ||
| 3 | Copyright (C) 2007-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2007-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -48,20 +48,13 @@ | |||
| 48 | 48 | ||
| 49 | /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). | 49 | /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). |
| 50 | Or they define it with the wrong member names or define it in <sys/time.h> | 50 | Or they define it with the wrong member names or define it in <sys/time.h> |
| 51 | (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the | 51 | (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it, |
| 52 | pthreads-win32 library defines it in <pthread.h>. */ | 52 | but the pthreads-win32 library defines it in <pthread.h>. */ |
| 53 | # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ | 53 | # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ |
| 54 | # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ | 54 | # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ |
| 55 | # include <sys/time.h> | 55 | # include <sys/time.h> |
| 56 | # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ | 56 | # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ |
| 57 | # include <pthread.h> | 57 | # include <pthread.h> |
| 58 | /* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */ | ||
| 59 | # undef asctime_r | ||
| 60 | # undef ctime_r | ||
| 61 | # undef gmtime_r | ||
| 62 | # undef localtime_r | ||
| 63 | # undef rand_r | ||
| 64 | # undef strtok_r | ||
| 65 | # else | 58 | # else |
| 66 | 59 | ||
| 67 | # ifdef __cplusplus | 60 | # ifdef __cplusplus |
| @@ -187,6 +180,39 @@ _GL_CXXALIASWARN (gmtime_r); | |||
| 187 | # endif | 180 | # endif |
| 188 | # endif | 181 | # endif |
| 189 | 182 | ||
| 183 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See | ||
| 184 | <http://www.opengroup.org/susv3xsh/localtime.html> and | ||
| 185 | <http://www.opengroup.org/susv3xsh/gmtime.html>. */ | ||
| 186 | # if @GNULIB_GETTIMEOFDAY@ | ||
| 187 | # if @REPLACE_LOCALTIME@ | ||
| 188 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 189 | # undef localtime | ||
| 190 | # define localtime rpl_localtime | ||
| 191 | # endif | ||
| 192 | _GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer) | ||
| 193 | _GL_ARG_NONNULL ((1))); | ||
| 194 | _GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer)); | ||
| 195 | # else | ||
| 196 | _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer)); | ||
| 197 | # endif | ||
| 198 | _GL_CXXALIASWARN (localtime); | ||
| 199 | # endif | ||
| 200 | |||
| 201 | # if @GNULIB_GETTIMEOFDAY@ | ||
| 202 | # if @REPLACE_GMTIME@ | ||
| 203 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 204 | # undef gmtime | ||
| 205 | # define gmtime rpl_gmtime | ||
| 206 | # endif | ||
| 207 | _GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer) | ||
| 208 | _GL_ARG_NONNULL ((1))); | ||
| 209 | _GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer)); | ||
| 210 | # else | ||
| 211 | _GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer)); | ||
| 212 | # endif | ||
| 213 | _GL_CXXALIASWARN (gmtime); | ||
| 214 | # endif | ||
| 215 | |||
| 190 | /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store | 216 | /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store |
| 191 | the resulting broken-down time into TM. See | 217 | the resulting broken-down time into TM. See |
| 192 | <http://www.opengroup.org/susv3xsh/strptime.html>. */ | 218 | <http://www.opengroup.org/susv3xsh/strptime.html>. */ |
diff --git a/lib/time_r.c b/lib/time_r.c index 9866299856c..a848d544fe2 100644 --- a/lib/time_r.c +++ b/lib/time_r.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Reentrant time functions like localtime_r. | 1 | /* Reentrant time functions like localtime_r. |
| 2 | 2 | ||
| 3 | Copyright (C) 2003, 2006-2007, 2010-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2003, 2006-2007, 2010-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
diff --git a/lib/timespec-add.c b/lib/timespec-add.c index 6ce2c73064f..3f734a64e4b 100644 --- a/lib/timespec-add.c +++ b/lib/timespec-add.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Add two struct timespec values. | 1 | /* Add two struct timespec values. |
| 2 | 2 | ||
| 3 | Copyright (C) 2011-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -18,7 +18,7 @@ | |||
| 18 | /* Written by Paul Eggert. */ | 18 | /* Written by Paul Eggert. */ |
| 19 | 19 | ||
| 20 | /* Return the sum of two timespec values A and B. On overflow, return | 20 | /* Return the sum of two timespec values A and B. On overflow, return |
| 21 | an extremal value. This assumes 0 <= tv_nsec <= 999999999. */ | 21 | an extremal value. This assumes 0 <= tv_nsec < TIMESPEC_RESOLUTION. */ |
| 22 | 22 | ||
| 23 | #include <config.h> | 23 | #include <config.h> |
| 24 | #include "timespec.h" | 24 | #include "timespec.h" |
| @@ -28,11 +28,10 @@ | |||
| 28 | struct timespec | 28 | struct timespec |
| 29 | timespec_add (struct timespec a, struct timespec b) | 29 | timespec_add (struct timespec a, struct timespec b) |
| 30 | { | 30 | { |
| 31 | struct timespec r; | ||
| 32 | time_t rs = a.tv_sec; | 31 | time_t rs = a.tv_sec; |
| 33 | time_t bs = b.tv_sec; | 32 | time_t bs = b.tv_sec; |
| 34 | int ns = a.tv_nsec + b.tv_nsec; | 33 | int ns = a.tv_nsec + b.tv_nsec; |
| 35 | int nsd = ns - 1000000000; | 34 | int nsd = ns - TIMESPEC_RESOLUTION; |
| 36 | int rns = ns; | 35 | int rns = ns; |
| 37 | 36 | ||
| 38 | if (0 <= nsd) | 37 | if (0 <= nsd) |
| @@ -59,13 +58,11 @@ timespec_add (struct timespec a, struct timespec b) | |||
| 59 | { | 58 | { |
| 60 | high_overflow: | 59 | high_overflow: |
| 61 | rs = TYPE_MAXIMUM (time_t); | 60 | rs = TYPE_MAXIMUM (time_t); |
| 62 | rns = 999999999; | 61 | rns = TIMESPEC_RESOLUTION - 1; |
| 63 | } | 62 | } |
| 64 | } | 63 | } |
| 65 | else | 64 | else |
| 66 | rs += bs; | 65 | rs += bs; |
| 67 | 66 | ||
| 68 | r.tv_sec = rs; | 67 | return make_timespec (rs, rns); |
| 69 | r.tv_nsec = rns; | ||
| 70 | return r; | ||
| 71 | } | 68 | } |
diff --git a/lib/timespec-sub.c b/lib/timespec-sub.c index 97c9f9de88c..ecffdc70359 100644 --- a/lib/timespec-sub.c +++ b/lib/timespec-sub.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Subtract two struct timespec values. | 1 | /* Subtract two struct timespec values. |
| 2 | 2 | ||
| 3 | Copyright (C) 2011-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -18,8 +18,8 @@ | |||
| 18 | /* Written by Paul Eggert. */ | 18 | /* Written by Paul Eggert. */ |
| 19 | 19 | ||
| 20 | /* Return the difference between two timespec values A and B. On | 20 | /* Return the difference between two timespec values A and B. On |
| 21 | overflow, return an extremal value. This assumes 0 <= tv_nsec <= | 21 | overflow, return an extremal value. This assumes 0 <= tv_nsec < |
| 22 | 999999999. */ | 22 | TIMESPEC_RESOLUTION. */ |
| 23 | 23 | ||
| 24 | #include <config.h> | 24 | #include <config.h> |
| 25 | #include "timespec.h" | 25 | #include "timespec.h" |
| @@ -29,7 +29,6 @@ | |||
| 29 | struct timespec | 29 | struct timespec |
| 30 | timespec_sub (struct timespec a, struct timespec b) | 30 | timespec_sub (struct timespec a, struct timespec b) |
| 31 | { | 31 | { |
| 32 | struct timespec r; | ||
| 33 | time_t rs = a.tv_sec; | 32 | time_t rs = a.tv_sec; |
| 34 | time_t bs = b.tv_sec; | 33 | time_t bs = b.tv_sec; |
| 35 | int ns = a.tv_nsec - b.tv_nsec; | 34 | int ns = a.tv_nsec - b.tv_nsec; |
| @@ -37,7 +36,7 @@ timespec_sub (struct timespec a, struct timespec b) | |||
| 37 | 36 | ||
| 38 | if (ns < 0) | 37 | if (ns < 0) |
| 39 | { | 38 | { |
| 40 | rns = ns + 1000000000; | 39 | rns = ns + TIMESPEC_RESOLUTION; |
| 41 | if (rs == TYPE_MINIMUM (time_t)) | 40 | if (rs == TYPE_MINIMUM (time_t)) |
| 42 | { | 41 | { |
| 43 | if (bs <= 0) | 42 | if (bs <= 0) |
| @@ -59,13 +58,11 @@ timespec_sub (struct timespec a, struct timespec b) | |||
| 59 | else | 58 | else |
| 60 | { | 59 | { |
| 61 | rs = TYPE_MAXIMUM (time_t); | 60 | rs = TYPE_MAXIMUM (time_t); |
| 62 | rns = 999999999; | 61 | rns = TIMESPEC_RESOLUTION - 1; |
| 63 | } | 62 | } |
| 64 | } | 63 | } |
| 65 | else | 64 | else |
| 66 | rs -= bs; | 65 | rs -= bs; |
| 67 | 66 | ||
| 68 | r.tv_sec = rs; | 67 | return make_timespec (rs, rns); |
| 69 | r.tv_nsec = rns; | ||
| 70 | return r; | ||
| 71 | } | 68 | } |
diff --git a/lib/timespec.h b/lib/timespec.h index d665e6ccf9a..872cbb76e37 100644 --- a/lib/timespec.h +++ b/lib/timespec.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* timespec -- System time interface | 1 | /* timespec -- System time interface |
| 2 | 2 | ||
| 3 | Copyright (C) 2000, 2002, 2004-2005, 2007, 2009-2013 Free Software | 3 | Copyright (C) 2000, 2002, 2004-2005, 2007, 2009-2014 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | 5 | ||
| 6 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify |
| @@ -21,11 +21,31 @@ | |||
| 21 | 21 | ||
| 22 | # include <time.h> | 22 | # include <time.h> |
| 23 | 23 | ||
| 24 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 25 | #error "Please include config.h first." | ||
| 26 | #endif | ||
| 24 | _GL_INLINE_HEADER_BEGIN | 27 | _GL_INLINE_HEADER_BEGIN |
| 25 | #ifndef _GL_TIMESPEC_INLINE | 28 | #ifndef _GL_TIMESPEC_INLINE |
| 26 | # define _GL_TIMESPEC_INLINE _GL_INLINE | 29 | # define _GL_TIMESPEC_INLINE _GL_INLINE |
| 27 | #endif | 30 | #endif |
| 28 | 31 | ||
| 32 | /* Resolution of timespec time stamps (in units per second), and log | ||
| 33 | base 10 of the resolution. */ | ||
| 34 | |||
| 35 | enum { TIMESPEC_RESOLUTION = 1000000000 }; | ||
| 36 | enum { LOG10_TIMESPEC_RESOLUTION = 9 }; | ||
| 37 | |||
| 38 | /* Return a timespec with seconds S and nanoseconds NS. */ | ||
| 39 | |||
| 40 | _GL_TIMESPEC_INLINE struct timespec | ||
| 41 | make_timespec (time_t s, long int ns) | ||
| 42 | { | ||
| 43 | struct timespec r; | ||
| 44 | r.tv_sec = s; | ||
| 45 | r.tv_nsec = ns; | ||
| 46 | return r; | ||
| 47 | } | ||
| 48 | |||
| 29 | /* Return negative, zero, positive if A < B, A == B, A > B, respectively. | 49 | /* Return negative, zero, positive if A < B, A == B, A > B, respectively. |
| 30 | 50 | ||
| 31 | For each time stamp T, this code assumes that either: | 51 | For each time stamp T, this code assumes that either: |
| @@ -1,6 +1,6 @@ | |||
| 1 | /* uint64_t-like operations that work even on hosts lacking uint64_t | 1 | /* uint64_t-like operations that work even on hosts lacking uint64_t |
| 2 | 2 | ||
| 3 | Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2006, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -19,6 +19,9 @@ | |||
| 19 | 19 | ||
| 20 | #include <stdint.h> | 20 | #include <stdint.h> |
| 21 | 21 | ||
| 22 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 23 | #error "Please include config.h first." | ||
| 24 | #endif | ||
| 22 | _GL_INLINE_HEADER_BEGIN | 25 | _GL_INLINE_HEADER_BEGIN |
| 23 | #ifndef _GL_U64_INLINE | 26 | #ifndef _GL_U64_INLINE |
| 24 | # define _GL_U64_INLINE _GL_INLINE | 27 | # define _GL_U64_INLINE _GL_INLINE |
diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 675c7e6a552..39b128a6da7 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Substitute for and wrapper around <unistd.h>. | 1 | /* Substitute for and wrapper around <unistd.h>. |
| 2 | Copyright (C) 2003-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2003-2014 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This program is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
| @@ -61,8 +61,10 @@ | |||
| 61 | /* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in | 61 | /* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in |
| 62 | <unistd.h>. */ | 62 | <unistd.h>. */ |
| 63 | /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */ | 63 | /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */ |
| 64 | /* OSF Tru64 Unix cannot see gnulib rpl_strtod when system <stdlib.h> is | ||
| 65 | included here. */ | ||
| 64 | /* But avoid namespace pollution on glibc systems. */ | 66 | /* But avoid namespace pollution on glibc systems. */ |
| 65 | #ifndef __GLIBC__ | 67 | #if !defined __GLIBC__ && !defined __osf__ |
| 66 | # define __need_system_stdlib_h | 68 | # define __need_system_stdlib_h |
| 67 | # include <stdlib.h> | 69 | # include <stdlib.h> |
| 68 | # undef __need_system_stdlib_h | 70 | # undef __need_system_stdlib_h |
| @@ -114,6 +116,9 @@ | |||
| 114 | # include <getopt.h> | 116 | # include <getopt.h> |
| 115 | #endif | 117 | #endif |
| 116 | 118 | ||
| 119 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 120 | #error "Please include config.h first." | ||
| 121 | #endif | ||
| 117 | _GL_INLINE_HEADER_BEGIN | 122 | _GL_INLINE_HEADER_BEGIN |
| 118 | #ifndef _GL_UNISTD_INLINE | 123 | #ifndef _GL_UNISTD_INLINE |
| 119 | # define _GL_UNISTD_INLINE _GL_INLINE | 124 | # define _GL_UNISTD_INLINE _GL_INLINE |
| @@ -649,10 +654,19 @@ _GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - " | |||
| 649 | #if @GNULIB_GETDTABLESIZE@ | 654 | #if @GNULIB_GETDTABLESIZE@ |
| 650 | /* Return the maximum number of file descriptors in the current process. | 655 | /* Return the maximum number of file descriptors in the current process. |
| 651 | In POSIX, this is same as sysconf (_SC_OPEN_MAX). */ | 656 | In POSIX, this is same as sysconf (_SC_OPEN_MAX). */ |
| 652 | # if !@HAVE_GETDTABLESIZE@ | 657 | # if @REPLACE_GETDTABLESIZE@ |
| 658 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 659 | # undef getdtablesize | ||
| 660 | # define getdtablesize rpl_getdtablesize | ||
| 661 | # endif | ||
| 662 | _GL_FUNCDECL_RPL (getdtablesize, int, (void)); | ||
| 663 | _GL_CXXALIAS_RPL (getdtablesize, int, (void)); | ||
| 664 | # else | ||
| 665 | # if !@HAVE_GETDTABLESIZE@ | ||
| 653 | _GL_FUNCDECL_SYS (getdtablesize, int, (void)); | 666 | _GL_FUNCDECL_SYS (getdtablesize, int, (void)); |
| 654 | # endif | 667 | # endif |
| 655 | _GL_CXXALIAS_SYS (getdtablesize, int, (void)); | 668 | _GL_CXXALIAS_SYS (getdtablesize, int, (void)); |
| 669 | # endif | ||
| 656 | _GL_CXXALIASWARN (getdtablesize); | 670 | _GL_CXXALIASWARN (getdtablesize); |
| 657 | #elif defined GNULIB_POSIXCHECK | 671 | #elif defined GNULIB_POSIXCHECK |
| 658 | # undef getdtablesize | 672 | # undef getdtablesize |
diff --git a/lib/unsetenv.c b/lib/unsetenv.c index c58c82f4f44..53721fc440b 100644 --- a/lib/unsetenv.c +++ b/lib/unsetenv.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* Copyright (C) 1992, 1995-2002, 2005-2013 Free Software Foundation, Inc. | 1 | /* Copyright (C) 1992, 1995-2002, 2005-2014 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. | 2 | This file is part of the GNU C Library. |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 4 | This program is free software: you can redistribute it and/or modify |
diff --git a/lib/utimens.c b/lib/utimens.c index 87123605ba2..dd3ec668f37 100644 --- a/lib/utimens.c +++ b/lib/utimens.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Set file access and modification times. | 1 | /* Set file access and modification times. |
| 2 | 2 | ||
| 3 | Copyright (C) 2003-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2003-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify it | 5 | This program is free software: you can redistribute it and/or modify it |
| 6 | under the terms of the GNU General Public License as published by the | 6 | under the terms of the GNU General Public License as published by the |
| @@ -90,10 +90,12 @@ validate_timespec (struct timespec timespec[2]) | |||
| 90 | assert (timespec); | 90 | assert (timespec); |
| 91 | if ((timespec[0].tv_nsec != UTIME_NOW | 91 | if ((timespec[0].tv_nsec != UTIME_NOW |
| 92 | && timespec[0].tv_nsec != UTIME_OMIT | 92 | && timespec[0].tv_nsec != UTIME_OMIT |
| 93 | && (timespec[0].tv_nsec < 0 || 1000000000 <= timespec[0].tv_nsec)) | 93 | && ! (0 <= timespec[0].tv_nsec |
| 94 | && timespec[0].tv_nsec < TIMESPEC_RESOLUTION)) | ||
| 94 | || (timespec[1].tv_nsec != UTIME_NOW | 95 | || (timespec[1].tv_nsec != UTIME_NOW |
| 95 | && timespec[1].tv_nsec != UTIME_OMIT | 96 | && timespec[1].tv_nsec != UTIME_OMIT |
| 96 | && (timespec[1].tv_nsec < 0 || 1000000000 <= timespec[1].tv_nsec))) | 97 | && ! (0 <= timespec[1].tv_nsec |
| 98 | && timespec[1].tv_nsec < TIMESPEC_RESOLUTION))) | ||
| 97 | { | 99 | { |
| 98 | errno = EINVAL; | 100 | errno = EINVAL; |
| 99 | return -1; | 101 | return -1; |
| @@ -216,15 +218,19 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2]) | |||
| 216 | if (0 <= utimensat_works_really) | 218 | if (0 <= utimensat_works_really) |
| 217 | { | 219 | { |
| 218 | int result; | 220 | int result; |
| 219 | # if __linux__ | 221 | # if __linux__ || __sun |
| 220 | /* As recently as Linux kernel 2.6.32 (Dec 2009), several file | 222 | /* As recently as Linux kernel 2.6.32 (Dec 2009), several file |
| 221 | systems (xfs, ntfs-3g) have bugs with a single UTIME_OMIT, | 223 | systems (xfs, ntfs-3g) have bugs with a single UTIME_OMIT, |
| 222 | but work if both times are either explicitly specified or | 224 | but work if both times are either explicitly specified or |
| 223 | UTIME_NOW. Work around it with a preparatory [f]stat prior | 225 | UTIME_NOW. Work around it with a preparatory [f]stat prior |
| 224 | to calling futimens/utimensat; fortunately, there is not much | 226 | to calling futimens/utimensat; fortunately, there is not much |
| 225 | timing impact due to the extra syscall even on file systems | 227 | timing impact due to the extra syscall even on file systems |
| 226 | where UTIME_OMIT would have worked. FIXME: Simplify this in | 228 | where UTIME_OMIT would have worked. |
| 227 | 2012, when file system bugs are no longer common. */ | 229 | |
| 230 | The same bug occurs in Solaris 11.1 (Apr 2013). | ||
| 231 | |||
| 232 | FIXME: Simplify this for Linux in 2016 and for Solaris in | ||
| 233 | 2024, when file system bugs are no longer common. */ | ||
| 228 | if (adjustment_needed == 2) | 234 | if (adjustment_needed == 2) |
| 229 | { | 235 | { |
| 230 | if (fd < 0 ? stat (file, &st) : fstat (fd, &st)) | 236 | if (fd < 0 ? stat (file, &st) : fstat (fd, &st)) |
| @@ -236,7 +242,7 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2]) | |||
| 236 | /* Note that st is good, in case utimensat gives ENOSYS. */ | 242 | /* Note that st is good, in case utimensat gives ENOSYS. */ |
| 237 | adjustment_needed++; | 243 | adjustment_needed++; |
| 238 | } | 244 | } |
| 239 | # endif /* __linux__ */ | 245 | # endif |
| 240 | # if HAVE_UTIMENSAT | 246 | # if HAVE_UTIMENSAT |
| 241 | if (fd < 0) | 247 | if (fd < 0) |
| 242 | { | 248 | { |
| @@ -445,15 +451,19 @@ lutimens (char const *file, struct timespec const timespec[2]) | |||
| 445 | if (0 <= lutimensat_works_really) | 451 | if (0 <= lutimensat_works_really) |
| 446 | { | 452 | { |
| 447 | int result; | 453 | int result; |
| 448 | # if __linux__ | 454 | # if __linux__ || __sun |
| 449 | /* As recently as Linux kernel 2.6.32 (Dec 2009), several file | 455 | /* As recently as Linux kernel 2.6.32 (Dec 2009), several file |
| 450 | systems (xfs, ntfs-3g) have bugs with a single UTIME_OMIT, | 456 | systems (xfs, ntfs-3g) have bugs with a single UTIME_OMIT, |
| 451 | but work if both times are either explicitly specified or | 457 | but work if both times are either explicitly specified or |
| 452 | UTIME_NOW. Work around it with a preparatory lstat prior to | 458 | UTIME_NOW. Work around it with a preparatory lstat prior to |
| 453 | calling utimensat; fortunately, there is not much timing | 459 | calling utimensat; fortunately, there is not much timing |
| 454 | impact due to the extra syscall even on file systems where | 460 | impact due to the extra syscall even on file systems where |
| 455 | UTIME_OMIT would have worked. FIXME: Simplify this in 2012, | 461 | UTIME_OMIT would have worked. |
| 456 | when file system bugs are no longer common. */ | 462 | |
| 463 | The same bug occurs in Solaris 11.1 (Apr 2013). | ||
| 464 | |||
| 465 | FIXME: Simplify this for Linux in 2016 and for Solaris in | ||
| 466 | 2024, when file system bugs are no longer common. */ | ||
| 457 | if (adjustment_needed == 2) | 467 | if (adjustment_needed == 2) |
| 458 | { | 468 | { |
| 459 | if (lstat (file, &st)) | 469 | if (lstat (file, &st)) |
| @@ -465,7 +475,7 @@ lutimens (char const *file, struct timespec const timespec[2]) | |||
| 465 | /* Note that st is good, in case utimensat gives ENOSYS. */ | 475 | /* Note that st is good, in case utimensat gives ENOSYS. */ |
| 466 | adjustment_needed++; | 476 | adjustment_needed++; |
| 467 | } | 477 | } |
| 468 | # endif /* __linux__ */ | 478 | # endif |
| 469 | result = utimensat (AT_FDCWD, file, ts, AT_SYMLINK_NOFOLLOW); | 479 | result = utimensat (AT_FDCWD, file, ts, AT_SYMLINK_NOFOLLOW); |
| 470 | # ifdef __linux__ | 480 | # ifdef __linux__ |
| 471 | /* Work around a kernel bug: | 481 | /* Work around a kernel bug: |
diff --git a/lib/utimens.h b/lib/utimens.h index 82a72a7a451..faaf3c7006b 100644 --- a/lib/utimens.h +++ b/lib/utimens.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Set file access and modification times. | 1 | /* Set file access and modification times. |
| 2 | 2 | ||
| 3 | Copyright 2012-2013 Free Software Foundation, Inc. | 3 | Copyright 2012-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify it | 5 | This program is free software: you can redistribute it and/or modify it |
| 6 | under the terms of the GNU General Public License as published by the | 6 | under the terms of the GNU General Public License as published by the |
| @@ -26,6 +26,9 @@ int lutimens (char const *, struct timespec const [2]); | |||
| 26 | # include <fcntl.h> | 26 | # include <fcntl.h> |
| 27 | # include <sys/stat.h> | 27 | # include <sys/stat.h> |
| 28 | 28 | ||
| 29 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
| 30 | #error "Please include config.h first." | ||
| 31 | #endif | ||
| 29 | _GL_INLINE_HEADER_BEGIN | 32 | _GL_INLINE_HEADER_BEGIN |
| 30 | #ifndef _GL_UTIMENS_INLINE | 33 | #ifndef _GL_UTIMENS_INLINE |
| 31 | # define _GL_UTIMENS_INLINE _GL_INLINE | 34 | # define _GL_UTIMENS_INLINE _GL_INLINE |
diff --git a/lib/verify.h b/lib/verify.h index cb8e90b5427..a25e514668a 100644 --- a/lib/verify.h +++ b/lib/verify.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Compile-time assert-like macros. | 1 | /* Compile-time assert-like macros. |
| 2 | 2 | ||
| 3 | Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2005-2006, 2009-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |
| @@ -18,7 +18,7 @@ | |||
| 18 | /* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */ | 18 | /* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */ |
| 19 | 19 | ||
| 20 | #ifndef _GL_VERIFY_H | 20 | #ifndef _GL_VERIFY_H |
| 21 | # define _GL_VERIFY_H | 21 | #define _GL_VERIFY_H |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11. | 24 | /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11. |
| @@ -31,14 +31,24 @@ | |||
| 31 | Use this only with GCC. If we were willing to slow 'configure' | 31 | Use this only with GCC. If we were willing to slow 'configure' |
| 32 | down we could also use it with other compilers, but since this | 32 | down we could also use it with other compilers, but since this |
| 33 | affects only the quality of diagnostics, why bother? */ | 33 | affects only the quality of diagnostics, why bother? */ |
| 34 | # if (4 < __GNUC__ || (__GNUC__ == 4 && 6 <= __GNUC_MINOR__)) && !defined __cplusplus | 34 | #if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \ |
| 35 | # define _GL_HAVE__STATIC_ASSERT 1 | 35 | && (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \ |
| 36 | # endif | 36 | && !defined __cplusplus) |
| 37 | # define _GL_HAVE__STATIC_ASSERT 1 | ||
| 38 | #endif | ||
| 37 | /* The condition (99 < __GNUC__) is temporary, until we know about the | 39 | /* The condition (99 < __GNUC__) is temporary, until we know about the |
| 38 | first G++ release that supports static_assert. */ | 40 | first G++ release that supports static_assert. */ |
| 39 | # if (99 < __GNUC__) && defined __cplusplus | 41 | #if (99 < __GNUC__) && defined __cplusplus |
| 40 | # define _GL_HAVE_STATIC_ASSERT 1 | 42 | # define _GL_HAVE_STATIC_ASSERT 1 |
| 41 | # endif | 43 | #endif |
| 44 | |||
| 45 | /* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other | ||
| 46 | system headers, defines a conflicting _Static_assert that is no | ||
| 47 | better than ours; override it. */ | ||
| 48 | #ifndef _GL_HAVE_STATIC_ASSERT | ||
| 49 | # include <stddef.h> | ||
| 50 | # undef _Static_assert | ||
| 51 | #endif | ||
| 42 | 52 | ||
| 43 | /* Each of these macros verifies that its argument R is nonzero. To | 53 | /* Each of these macros verifies that its argument R is nonzero. To |
| 44 | be portable, R should be an integer constant expression. Unlike | 54 | be portable, R should be an integer constant expression. Unlike |
| @@ -141,50 +151,50 @@ | |||
| 141 | Use a template type to work around the problem. */ | 151 | Use a template type to work around the problem. */ |
| 142 | 152 | ||
| 143 | /* Concatenate two preprocessor tokens. */ | 153 | /* Concatenate two preprocessor tokens. */ |
| 144 | # define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y) | 154 | #define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y) |
| 145 | # define _GL_CONCAT0(x, y) x##y | 155 | #define _GL_CONCAT0(x, y) x##y |
| 146 | 156 | ||
| 147 | /* _GL_COUNTER is an integer, preferably one that changes each time we | 157 | /* _GL_COUNTER is an integer, preferably one that changes each time we |
| 148 | use it. Use __COUNTER__ if it works, falling back on __LINE__ | 158 | use it. Use __COUNTER__ if it works, falling back on __LINE__ |
| 149 | otherwise. __LINE__ isn't perfect, but it's better than a | 159 | otherwise. __LINE__ isn't perfect, but it's better than a |
| 150 | constant. */ | 160 | constant. */ |
| 151 | # if defined __COUNTER__ && __COUNTER__ != __COUNTER__ | 161 | #if defined __COUNTER__ && __COUNTER__ != __COUNTER__ |
| 152 | # define _GL_COUNTER __COUNTER__ | 162 | # define _GL_COUNTER __COUNTER__ |
| 153 | # else | 163 | #else |
| 154 | # define _GL_COUNTER __LINE__ | 164 | # define _GL_COUNTER __LINE__ |
| 155 | # endif | 165 | #endif |
| 156 | 166 | ||
| 157 | /* Generate a symbol with the given prefix, making it unique if | 167 | /* Generate a symbol with the given prefix, making it unique if |
| 158 | possible. */ | 168 | possible. */ |
| 159 | # define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) | 169 | #define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) |
| 160 | 170 | ||
| 161 | /* Verify requirement R at compile-time, as an integer constant expression | 171 | /* Verify requirement R at compile-time, as an integer constant expression |
| 162 | that returns 1. If R is false, fail at compile-time, preferably | 172 | that returns 1. If R is false, fail at compile-time, preferably |
| 163 | with a diagnostic that includes the string-literal DIAGNOSTIC. */ | 173 | with a diagnostic that includes the string-literal DIAGNOSTIC. */ |
| 164 | 174 | ||
| 165 | # define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \ | 175 | #define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \ |
| 166 | (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC))) | 176 | (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC))) |
| 167 | 177 | ||
| 168 | # ifdef __cplusplus | 178 | #ifdef __cplusplus |
| 169 | # if !GNULIB_defined_struct__gl_verify_type | 179 | # if !GNULIB_defined_struct__gl_verify_type |
| 170 | template <int w> | 180 | template <int w> |
| 171 | struct _gl_verify_type { | 181 | struct _gl_verify_type { |
| 172 | unsigned int _gl_verify_error_if_negative: w; | 182 | unsigned int _gl_verify_error_if_negative: w; |
| 173 | }; | 183 | }; |
| 174 | # define GNULIB_defined_struct__gl_verify_type 1 | 184 | # define GNULIB_defined_struct__gl_verify_type 1 |
| 175 | # endif | ||
| 176 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 177 | _gl_verify_type<(R) ? 1 : -1> | ||
| 178 | # elif defined _GL_HAVE__STATIC_ASSERT | ||
| 179 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 180 | struct { \ | ||
| 181 | _Static_assert (R, DIAGNOSTIC); \ | ||
| 182 | int _gl_dummy; \ | ||
| 183 | } | ||
| 184 | # else | ||
| 185 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 186 | struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; } | ||
| 187 | # endif | 185 | # endif |
| 186 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 187 | _gl_verify_type<(R) ? 1 : -1> | ||
| 188 | #elif defined _GL_HAVE__STATIC_ASSERT | ||
| 189 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 190 | struct { \ | ||
| 191 | _Static_assert (R, DIAGNOSTIC); \ | ||
| 192 | int _gl_dummy; \ | ||
| 193 | } | ||
| 194 | #else | ||
| 195 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 196 | struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; } | ||
| 197 | #endif | ||
| 188 | 198 | ||
| 189 | /* Verify requirement R at compile-time, as a declaration without a | 199 | /* Verify requirement R at compile-time, as a declaration without a |
| 190 | trailing ';'. If R is false, fail at compile-time, preferably | 200 | trailing ';'. If R is false, fail at compile-time, preferably |
| @@ -193,23 +203,23 @@ template <int w> | |||
| 193 | Unfortunately, unlike C11, this implementation must appear as an | 203 | Unfortunately, unlike C11, this implementation must appear as an |
| 194 | ordinary declaration, and cannot appear inside struct { ... }. */ | 204 | ordinary declaration, and cannot appear inside struct { ... }. */ |
| 195 | 205 | ||
| 196 | # ifdef _GL_HAVE__STATIC_ASSERT | 206 | #ifdef _GL_HAVE__STATIC_ASSERT |
| 197 | # define _GL_VERIFY _Static_assert | 207 | # define _GL_VERIFY _Static_assert |
| 198 | # else | 208 | #else |
| 199 | # define _GL_VERIFY(R, DIAGNOSTIC) \ | 209 | # define _GL_VERIFY(R, DIAGNOSTIC) \ |
| 200 | extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ | 210 | extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ |
| 201 | [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] | 211 | [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] |
| 202 | # endif | 212 | #endif |
| 203 | 213 | ||
| 204 | /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ | 214 | /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ |
| 205 | # ifdef _GL_STATIC_ASSERT_H | 215 | #ifdef _GL_STATIC_ASSERT_H |
| 206 | # if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert | 216 | # if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert |
| 207 | # define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) | 217 | # define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) |
| 208 | # endif | ||
| 209 | # if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert | ||
| 210 | # define static_assert _Static_assert /* C11 requires this #define. */ | ||
| 211 | # endif | ||
| 212 | # endif | 218 | # endif |
| 219 | # if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert | ||
| 220 | # define static_assert _Static_assert /* C11 requires this #define. */ | ||
| 221 | # endif | ||
| 222 | #endif | ||
| 213 | 223 | ||
| 214 | /* @assert.h omit start@ */ | 224 | /* @assert.h omit start@ */ |
| 215 | 225 | ||
| @@ -227,18 +237,42 @@ template <int w> | |||
| 227 | 237 | ||
| 228 | verify_true is obsolescent; please use verify_expr instead. */ | 238 | verify_true is obsolescent; please use verify_expr instead. */ |
| 229 | 239 | ||
| 230 | # define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")") | 240 | #define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")") |
| 231 | 241 | ||
| 232 | /* Verify requirement R at compile-time. Return the value of the | 242 | /* Verify requirement R at compile-time. Return the value of the |
| 233 | expression E. */ | 243 | expression E. */ |
| 234 | 244 | ||
| 235 | # define verify_expr(R, E) \ | 245 | #define verify_expr(R, E) \ |
| 236 | (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) | 246 | (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) |
| 237 | 247 | ||
| 238 | /* Verify requirement R at compile-time, as a declaration without a | 248 | /* Verify requirement R at compile-time, as a declaration without a |
| 239 | trailing ';'. */ | 249 | trailing ';'. */ |
| 240 | 250 | ||
| 241 | # define verify(R) _GL_VERIFY (R, "verify (" #R ")") | 251 | #define verify(R) _GL_VERIFY (R, "verify (" #R ")") |
| 252 | |||
| 253 | #ifndef __has_builtin | ||
| 254 | # define __has_builtin(x) 0 | ||
| 255 | #endif | ||
| 256 | |||
| 257 | /* Assume that R always holds. This lets the compiler optimize | ||
| 258 | accordingly. R should not have side-effects; it may or may not be | ||
| 259 | evaluated. Behavior is undefined if R is false. */ | ||
| 260 | |||
| 261 | #if (__has_builtin (__builtin_unreachable) \ | ||
| 262 | || 4 < __GNUC__ + (5 <= __GNUC_MINOR__)) | ||
| 263 | # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) | ||
| 264 | #elif 1200 <= _MSC_VER | ||
| 265 | # define assume(R) __assume (R) | ||
| 266 | #elif (defined lint \ | ||
| 267 | && (__has_builtin (__builtin_trap) \ | ||
| 268 | || 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)))) | ||
| 269 | /* Doing it this way helps various packages when configured with | ||
| 270 | --enable-gcc-warnings, which compiles with -Dlint. It's nicer | ||
| 271 | when 'assume' silences warnings even with older GCCs. */ | ||
| 272 | # define assume(R) ((R) ? (void) 0 : __builtin_trap ()) | ||
| 273 | #else | ||
| 274 | # define assume(R) ((void) (0 && (R))) | ||
| 275 | #endif | ||
| 242 | 276 | ||
| 243 | /* @assert.h omit end@ */ | 277 | /* @assert.h omit end@ */ |
| 244 | 278 | ||
diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h index a971c78ad35..f3329228ec0 100644 --- a/lib/xalloc-oversized.h +++ b/lib/xalloc-oversized.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* xalloc-oversized.h -- memory allocation size checking | 1 | /* xalloc-oversized.h -- memory allocation size checking |
| 2 | 2 | ||
| 3 | Copyright (C) 1990-2000, 2003-2004, 2006-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 1990-2000, 2003-2004, 2006-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published by |