aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPhilipp Stephani2020-12-24 16:48:40 +0100
committerPhilipp Stephani2020-12-24 16:48:40 +0100
commit29064d02c31b08ae41d41a93fd1439718373b196 (patch)
tree6c976729d7c6f296b36965f235d2a58e8142393e /lib
parent26b8b30ff42568ff3e3f8599a20328a1efe93d2a (diff)
downloademacs-29064d02c31b08ae41d41a93fd1439718373b196.tar.gz
emacs-29064d02c31b08ae41d41a93fd1439718373b196.zip
Update Gnulib.
All changes in this commit are autogenerated by running admin/merge-gnulib.
Diffstat (limited to 'lib')
-rw-r--r--lib/attribute.h23
-rw-r--r--lib/c++defs.h8
-rw-r--r--lib/canonicalize-lgpl.c381
-rw-r--r--lib/careadlinkat.c22
-rw-r--r--lib/cdefs.h4
-rw-r--r--lib/fcntl.c4
-rw-r--r--lib/fcntl.in.h37
-rw-r--r--lib/filemode.c14
-rw-r--r--lib/fpending.c7
-rw-r--r--lib/free.c33
-rw-r--r--lib/gnulib.mk.in93
-rw-r--r--lib/idx.h113
-rw-r--r--lib/intprops.h50
-rw-r--r--lib/malloc/scratch_buffer.h135
-rw-r--r--lib/malloc/scratch_buffer_grow.c56
-rw-r--r--lib/malloc/scratch_buffer_grow_preserve.c67
-rw-r--r--lib/malloc/scratch_buffer_set_array_size.c64
-rw-r--r--lib/rawmemchr.c136
-rw-r--r--lib/rawmemchr.valgrind28
-rw-r--r--lib/readlink.c48
-rw-r--r--lib/readlinkat.c47
-rw-r--r--lib/regex_internal.c19
-rw-r--r--lib/regex_internal.h8
-rw-r--r--lib/scratch_buffer.h29
-rw-r--r--lib/signal.in.h6
-rw-r--r--lib/stdint.in.h5
-rw-r--r--lib/stdio-impl.h2
-rw-r--r--lib/stdio.in.h183
-rw-r--r--lib/stdlib.in.h169
-rw-r--r--lib/string.in.h36
-rw-r--r--lib/sys_select.in.h9
-rw-r--r--lib/sys_stat.in.h32
-rw-r--r--lib/tempname.c49
-rw-r--r--lib/time.in.h23
-rw-r--r--lib/time_rz.c16
-rw-r--r--lib/unistd.in.h386
-rw-r--r--lib/xalloc-oversized.h2
37 files changed, 1835 insertions, 509 deletions
diff --git a/lib/attribute.h b/lib/attribute.h
index 2836b99dad0..5afcb8e81f2 100644
--- a/lib/attribute.h
+++ b/lib/attribute.h
@@ -80,7 +80,7 @@
80/* Attributes for variadic functions. */ 80/* Attributes for variadic functions. */
81 81
82/* The variadic function expects a trailing NULL argument. 82/* The variadic function expects a trailing NULL argument.
83 ATTRIBUTE_SENTINEL () - The last argument is NULL. 83 ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
84 ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */ 84 ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
85/* Applies to: functions. */ 85/* Applies to: functions. */
86#define ATTRIBUTE_SENTINEL(pos) _GL_ATTRIBUTE_SENTINEL (pos) 86#define ATTRIBUTE_SENTINEL(pos) _GL_ATTRIBUTE_SENTINEL (pos)
@@ -170,18 +170,21 @@
170/* Applies to: function. */ 170/* Applies to: function. */
171#define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE 171#define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE
172 172
173/* The function does not affect observable state, and always returns a value. 173/* It is OK for a compiler to omit duplicate calls with the same arguments.
174 Compilers can omit duplicate calls with the same arguments if 174 This attribute is safe for a function that neither depends on
175 observable state is not changed between calls. (This attribute is 175 nor affects observable state, and always returns exactly once -
176 looser than ATTRIBUTE_CONST.) */ 176 e.g., does not loop forever, and does not call longjmp.
177 (This attribute is stricter than ATTRIBUTE_PURE.) */
177/* Applies to: functions. */ 178/* Applies to: functions. */
178#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE 179#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
179 180
180/* The function neither depends on nor affects observable state, 181/* It is OK for a compiler to omit duplicate calls with the same
181 and always returns a value. Compilers can omit duplicate calls with 182 arguments if observable state is not changed between calls.
182 the same arguments. (This attribute is stricter than ATTRIBUTE_PURE.) */ 183 This attribute is safe for a function that does not affect
184 observable state, and always returns exactly once.
185 (This attribute is looser than ATTRIBUTE_CONST.) */
183/* Applies to: functions. */ 186/* Applies to: functions. */
184#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST 187#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE
185 188
186/* The function is rarely executed. */ 189/* The function is rarely executed. */
187/* Applies to: functions. */ 190/* Applies to: functions. */
diff --git a/lib/c++defs.h b/lib/c++defs.h
index 6a9bf295eb5..01ef8140cad 100644
--- a/lib/c++defs.h
+++ b/lib/c++defs.h
@@ -181,6 +181,14 @@
181 _GL_EXTERN_C int _gl_cxxalias_dummy 181 _GL_EXTERN_C int _gl_cxxalias_dummy
182#endif 182#endif
183 183
184/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters);
185 is like _GL_CXXALIAS_MDA (func, rettype, parameters);
186 except that the C function func may have a slightly different declaration.
187 A cast is used to silence the "invalid conversion" error that would
188 otherwise occur. */
189#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \
190 _GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters)
191
184/* _GL_CXXALIAS_SYS (func, rettype, parameters); 192/* _GL_CXXALIAS_SYS (func, rettype, parameters);
185 declares a C++ alias called GNULIB_NAMESPACE::func 193 declares a C++ alias called GNULIB_NAMESPACE::func
186 that redirects to the system provided function func, if GNULIB_NAMESPACE 194 that redirects to the system provided function func, if GNULIB_NAMESPACE
diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
index 0b89d2a1842..584fce1cfa4 100644
--- a/lib/canonicalize-lgpl.c
+++ b/lib/canonicalize-lgpl.c
@@ -2,18 +2,19 @@
2 Copyright (C) 1996-2020 Free Software Foundation, Inc. 2 Copyright (C) 1996-2020 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 4
5 This program is free software: you can redistribute it and/or modify 5 The GNU C Library is free software; you can redistribute it and/or
6 it under the terms of the GNU General Public License as published by 6 modify it under the terms of the GNU General Public
7 the Free Software Foundation; either version 3 of the License, or 7 License as published by the Free Software Foundation; either
8 (at your option) any later version. 8 version 3 of the License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 GNU General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ 16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
17 18
18#ifndef _LIBC 19#ifndef _LIBC
19/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc 20/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
@@ -21,36 +22,36 @@
21# define _GL_ARG_NONNULL(params) 22# define _GL_ARG_NONNULL(params)
22 23
23# define _GL_USE_STDLIB_ALLOC 1 24# define _GL_USE_STDLIB_ALLOC 1
24# include <config.h> 25# include <libc-config.h>
25#endif 26#endif
26 27
27#if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC
28
29/* Specification. */ 28/* Specification. */
30#include <stdlib.h> 29#include <stdlib.h>
31 30
32#include <alloca.h>
33#include <string.h>
34#include <unistd.h>
35#include <limits.h>
36#if HAVE_SYS_PARAM_H || defined _LIBC
37# include <sys/param.h>
38#endif
39#include <sys/stat.h>
40#include <errno.h> 31#include <errno.h>
32#include <limits.h>
33#include <stdbool.h>
41#include <stddef.h> 34#include <stddef.h>
35#include <string.h>
36#include <sys/stat.h>
37#include <unistd.h>
38
39#include <scratch_buffer.h>
42 40
43#ifdef _LIBC 41#ifdef _LIBC
42# include <eloop-threshold.h>
44# include <shlib-compat.h> 43# include <shlib-compat.h>
44typedef ptrdiff_t idx_t;
45# define IDX_MAX PTRDIFF_MAX
46# define FILE_SYSTEM_PREFIX_LEN(name) 0
47# define IS_ABSOLUTE_FILE_NAME(name) ISSLASH(*(name))
48# define ISSLASH(c) ((c) == '/')
49# define freea(p) ((void) (p))
45#else 50#else
46# define SHLIB_COMPAT(lib, introduced, obsoleted) 0
47# define versioned_symbol(lib, local, symbol, version) extern int dummy
48# define compat_symbol(lib, local, symbol, version)
49# define weak_alias(local, symbol)
50# define __canonicalize_file_name canonicalize_file_name 51# define __canonicalize_file_name canonicalize_file_name
51# define __realpath realpath 52# define __realpath realpath
53# include "idx.h"
52# include "pathmax.h" 54# include "pathmax.h"
53# include "malloca.h"
54# include "filename.h" 55# include "filename.h"
55# if defined _WIN32 && !defined __CYGWIN__ 56# if defined _WIN32 && !defined __CYGWIN__
56# define __getcwd _getcwd 57# define __getcwd _getcwd
@@ -72,8 +73,10 @@
72# else 73# else
73# define __getcwd(buf, max) getwd (buf) 74# define __getcwd(buf, max) getwd (buf)
74# endif 75# endif
76# define __mempcpy mempcpy
77# define __pathconf pathconf
78# define __rawmemchr rawmemchr
75# define __readlink readlink 79# define __readlink readlink
76# define __set_errno(e) errno = (e)
77# ifndef MAXSYMLINKS 80# ifndef MAXSYMLINKS
78# ifdef SYMLOOP_MAX 81# ifdef SYMLOOP_MAX
79# define MAXSYMLINKS SYMLOOP_MAX 82# define MAXSYMLINKS SYMLOOP_MAX
@@ -81,48 +84,51 @@
81# define MAXSYMLINKS 20 84# define MAXSYMLINKS 20
82# endif 85# endif
83# endif 86# endif
87# define __eloop_threshold() MAXSYMLINKS
84#endif 88#endif
85 89
86#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT 90#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
87# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 91# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
88#endif 92#endif
89 93
90/* Define this independently so that stdint.h is not a prerequisite. */
91#ifndef SIZE_MAX
92# define SIZE_MAX ((size_t) -1)
93#endif
94
95#if !FUNC_REALPATH_WORKS || defined _LIBC 94#if !FUNC_REALPATH_WORKS || defined _LIBC
96 95
97static void 96static idx_t
98alloc_failed (void) 97get_path_max (void)
99{ 98{
100#if defined _WIN32 && ! defined __CYGWIN__ 99# ifdef PATH_MAX
101 /* Avoid errno problem without using the malloc or realloc modules; see: 100 long int path_max = PATH_MAX;
102 https://lists.gnu.org/r/bug-gnulib/2016-08/msg00025.html */ 101# else
103 errno = ENOMEM; 102 /* The caller invoked realpath with a null RESOLVED, even though
104#endif 103 PATH_MAX is not defined as a constant. The glibc manual says
104 programs should not do this, and POSIX says the behavior is undefined.
105 Historically, glibc here used the result of pathconf, or 1024 if that
106 failed; stay consistent with this (dubious) historical practice. */
107 int err = errno;
108 long int path_max = __pathconf ("/", _PC_PATH_MAX);
109 __set_errno (err);
110# endif
111 return path_max < 0 ? 1024 : path_max <= IDX_MAX ? path_max : IDX_MAX;
105} 112}
106 113
107/* Return the canonical absolute name of file NAME. A canonical name 114/* Return the canonical absolute name of file NAME. A canonical name
108 does not contain any ".", ".." components nor any repeated path 115 does not contain any ".", ".." components nor any repeated file name
109 separators ('/') or symlinks. All path components must exist. If 116 separators ('/') or symlinks. All file name components must exist. If
110 RESOLVED is null, the result is malloc'd; otherwise, if the 117 RESOLVED is null, the result is malloc'd; otherwise, if the
111 canonical name is PATH_MAX chars or more, returns null with 'errno' 118 canonical name is PATH_MAX chars or more, returns null with 'errno'
112 set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, 119 set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
113 returns the name in RESOLVED. If the name cannot be resolved and 120 returns the name in RESOLVED. If the name cannot be resolved and
114 RESOLVED is non-NULL, it contains the path of the first component 121 RESOLVED is non-NULL, it contains the name of the first component
115 that cannot be resolved. If the path can be resolved, RESOLVED 122 that cannot be resolved. If the name can be resolved, RESOLVED
116 holds the same value as the value returned. */ 123 holds the same value as the value returned. */
117 124
118char * 125char *
119__realpath (const char *name, char *resolved) 126__realpath (const char *name, char *resolved)
120{ 127{
121 char *rpath, *dest, *extra_buf = NULL; 128 char *dest;
122 const char *start, *end, *rpath_limit; 129 char const *start;
123 long int path_max; 130 char const *end;
124 int num_links = 0; 131 int num_links = 0;
125 size_t prefix_len;
126 132
127 if (name == NULL) 133 if (name == NULL)
128 { 134 {
@@ -142,205 +148,151 @@ __realpath (const char *name, char *resolved)
142 return NULL; 148 return NULL;
143 } 149 }
144 150
145#ifdef PATH_MAX 151 struct scratch_buffer extra_buffer, link_buffer;
146 path_max = PATH_MAX; 152 struct scratch_buffer rname_buffer;
147#else 153 struct scratch_buffer *rname_buf = &rname_buffer;
148 path_max = pathconf (name, _PC_PATH_MAX); 154 scratch_buffer_init (&extra_buffer);
149 if (path_max <= 0) 155 scratch_buffer_init (&link_buffer);
150 path_max = 8192; 156 scratch_buffer_init (rname_buf);
151#endif 157 char *rname_on_stack = rname_buf->data;
152 158 char *rname = rname_on_stack;
153 if (resolved == NULL) 159 bool end_in_extra_buffer = false;
154 { 160 bool failed = true;
155 rpath = malloc (path_max);
156 if (rpath == NULL)
157 {
158 alloc_failed ();
159 return NULL;
160 }
161 }
162 else
163 rpath = resolved;
164 rpath_limit = rpath + path_max;
165 161
166 /* This is always zero for Posix hosts, but can be 2 for MS-Windows 162 /* This is always zero for Posix hosts, but can be 2 for MS-Windows
167 and MS-DOS X:/foo/bar file names. */ 163 and MS-DOS X:/foo/bar file names. */
168 prefix_len = FILE_SYSTEM_PREFIX_LEN (name); 164 idx_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
169 165
170 if (!IS_ABSOLUTE_FILE_NAME (name)) 166 if (!IS_ABSOLUTE_FILE_NAME (name))
171 { 167 {
172 if (!__getcwd (rpath, path_max)) 168 while (!__getcwd (rname, rname_buf->length))
173 { 169 {
174 rpath[0] = '\0'; 170 if (errno != ERANGE)
175 goto error; 171 {
172 dest = rname;
173 goto error;
174 }
175 if (!scratch_buffer_grow (rname_buf))
176 goto error_nomem;
177 rname = rname_buf->data;
176 } 178 }
177 dest = strchr (rpath, '\0'); 179 dest = __rawmemchr (rname, '\0');
178 start = name; 180 start = name;
179 prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath); 181 prefix_len = FILE_SYSTEM_PREFIX_LEN (rname);
180 } 182 }
181 else 183 else
182 { 184 {
183 dest = rpath; 185 dest = __mempcpy (rname, name, prefix_len);
184 if (prefix_len)
185 {
186 memcpy (rpath, name, prefix_len);
187 dest += prefix_len;
188 }
189 *dest++ = '/'; 186 *dest++ = '/';
190 if (DOUBLE_SLASH_IS_DISTINCT_ROOT) 187 if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
191 { 188 {
192 if (ISSLASH (name[1]) && !ISSLASH (name[2]) && !prefix_len) 189 if (prefix_len == 0 /* implies ISSLASH (name[0]) */
190 && ISSLASH (name[1]) && !ISSLASH (name[2]))
193 *dest++ = '/'; 191 *dest++ = '/';
194 *dest = '\0'; 192 *dest = '\0';
195 } 193 }
196 start = name + prefix_len; 194 start = name + prefix_len;
197 } 195 }
198 196
199 for (end = start; *start; start = end) 197 for ( ; *start; start = end)
200 { 198 {
201#ifdef _LIBC 199 /* Skip sequence of multiple file name separators. */
202 struct stat64 st;
203#else
204 struct stat st;
205#endif
206
207 /* Skip sequence of multiple path-separators. */
208 while (ISSLASH (*start)) 200 while (ISSLASH (*start))
209 ++start; 201 ++start;
210 202
211 /* Find end of path component. */ 203 /* Find end of component. */
212 for (end = start; *end && !ISSLASH (*end); ++end) 204 for (end = start; *end && !ISSLASH (*end); ++end)
213 /* Nothing. */; 205 /* Nothing. */;
214 206
215 if (end - start == 0) 207 /* Length of this file name component; it can be zero if a file
216 break; 208 name ends in '/'. */
217 else if (end - start == 1 && start[0] == '.') 209 idx_t startlen = end - start;
210
211 if (startlen == 1 && start[0] == '.')
218 /* nothing */; 212 /* nothing */;
219 else if (end - start == 2 && start[0] == '.' && start[1] == '.') 213 else if (startlen == 2 && start[0] == '.' && start[1] == '.')
220 { 214 {
221 /* Back up to previous component, ignore if at root already. */ 215 /* Back up to previous component, ignore if at root already. */
222 if (dest > rpath + prefix_len + 1) 216 if (dest > rname + prefix_len + 1)
223 for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest) 217 for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest)
224 continue; 218 continue;
225 if (DOUBLE_SLASH_IS_DISTINCT_ROOT 219 if (DOUBLE_SLASH_IS_DISTINCT_ROOT
226 && dest == rpath + 1 && !prefix_len 220 && dest == rname + 1 && !prefix_len
227 && ISSLASH (*dest) && !ISSLASH (dest[1])) 221 && ISSLASH (*dest) && !ISSLASH (dest[1]))
228 dest++; 222 dest++;
229 } 223 }
230 else 224 else
231 { 225 {
232 size_t new_size;
233
234 if (!ISSLASH (dest[-1])) 226 if (!ISSLASH (dest[-1]))
235 *dest++ = '/'; 227 *dest++ = '/';
236 228
237 if (dest + (end - start) >= rpath_limit) 229 while (rname + rname_buf->length - dest <= startlen)
238 { 230 {
239 ptrdiff_t dest_offset = dest - rpath; 231 idx_t dest_offset = dest - rname;
240 char *new_rpath; 232 if (!scratch_buffer_grow_preserve (rname_buf))
241 233 goto error_nomem;
242 if (resolved) 234 rname = rname_buf->data;
243 { 235 dest = rname + dest_offset;
244 __set_errno (ENAMETOOLONG);
245 if (dest > rpath + prefix_len + 1)
246 dest--;
247 *dest = '\0';
248 goto error;
249 }
250 new_size = rpath_limit - rpath;
251 if (end - start + 1 > path_max)
252 new_size += end - start + 1;
253 else
254 new_size += path_max;
255 new_rpath = (char *) realloc (rpath, new_size);
256 if (new_rpath == NULL)
257 {
258 alloc_failed ();
259 goto error;
260 }
261 rpath = new_rpath;
262 rpath_limit = rpath + new_size;
263
264 dest = rpath + dest_offset;
265 } 236 }
266 237
267#ifdef _LIBC 238 dest = __mempcpy (dest, start, startlen);
268 dest = __mempcpy (dest, start, end - start);
269#else
270 memcpy (dest, start, end - start);
271 dest += end - start;
272#endif
273 *dest = '\0'; 239 *dest = '\0';
274 240
275 /* FIXME: if lstat fails with errno == EOVERFLOW, 241 /* If STARTLEN == 0, RNAME ends in '/'; use stat rather than
276 the entry exists. */ 242 readlink, because readlink might fail with EINVAL without
277#ifdef _LIBC 243 checking whether RNAME sans '/' is valid. */
278 if (__lxstat64 (_STAT_VER, rpath, &st) < 0) 244 struct stat st;
279#else 245 char *buf = NULL;
280 if (lstat (rpath, &st) < 0) 246 ssize_t n;
281#endif 247 if (startlen != 0)
282 goto error;
283
284 if (S_ISLNK (st.st_mode))
285 { 248 {
286 char *buf; 249 while (true)
287 size_t len;
288 ssize_t n;
289
290 if (++num_links > MAXSYMLINKS)
291 {
292 __set_errno (ELOOP);
293 goto error;
294 }
295
296 buf = malloca (path_max);
297 if (!buf)
298 { 250 {
299 __set_errno (ENOMEM); 251 buf = link_buffer.data;
300 goto error; 252 idx_t bufsize = link_buffer.length;
253 n = __readlink (rname, buf, bufsize - 1);
254 if (n < bufsize - 1)
255 break;
256 if (!scratch_buffer_grow (&link_buffer))
257 goto error_nomem;
301 } 258 }
302
303 n = __readlink (rpath, buf, path_max - 1);
304 if (n < 0) 259 if (n < 0)
260 buf = NULL;
261 }
262 if (buf)
263 {
264 if (++num_links > __eloop_threshold ())
305 { 265 {
306 int saved_errno = errno; 266 __set_errno (ELOOP);
307 freea (buf);
308 __set_errno (saved_errno);
309 goto error; 267 goto error;
310 } 268 }
311 buf[n] = '\0';
312 269
313 if (!extra_buf) 270 buf[n] = '\0';
314 {
315 extra_buf = malloca (path_max);
316 if (!extra_buf)
317 {
318 freea (buf);
319 __set_errno (ENOMEM);
320 goto error;
321 }
322 }
323 271
324 len = strlen (end); 272 char *extra_buf = extra_buffer.data;
325 /* Check that n + len + 1 doesn't overflow and is <= path_max. */ 273 idx_t end_idx;
326 if (n >= SIZE_MAX - len || n + len >= path_max) 274 if (end_in_extra_buffer)
275 end_idx = end - extra_buf;
276 idx_t len = strlen (end);
277 while (extra_buffer.length <= len + n)
327 { 278 {
328 freea (buf); 279 if (!scratch_buffer_grow_preserve (&extra_buffer))
329 __set_errno (ENAMETOOLONG); 280 goto error_nomem;
330 goto error; 281 extra_buf = extra_buffer.data;
331 } 282 }
283 if (end_in_extra_buffer)
284 end = extra_buf + end_idx;
332 285
333 /* Careful here, end may be a pointer into extra_buf... */ 286 /* Careful here, end may be a pointer into extra_buf... */
334 memmove (&extra_buf[n], end, len + 1); 287 memmove (&extra_buf[n], end, len + 1);
335 name = end = memcpy (extra_buf, buf, n); 288 name = end = memcpy (extra_buf, buf, n);
289 end_in_extra_buffer = true;
336 290
337 if (IS_ABSOLUTE_FILE_NAME (buf)) 291 if (IS_ABSOLUTE_FILE_NAME (buf))
338 { 292 {
339 size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf); 293 idx_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);
340 294
341 if (pfxlen) 295 dest = __mempcpy (rname, buf, pfxlen);
342 memcpy (rpath, buf, pfxlen);
343 dest = rpath + pfxlen;
344 *dest++ = '/'; /* It's an absolute symlink */ 296 *dest++ = '/'; /* It's an absolute symlink */
345 if (DOUBLE_SLASH_IS_DISTINCT_ROOT) 297 if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
346 { 298 {
@@ -355,44 +307,55 @@ __realpath (const char *name, char *resolved)
355 { 307 {
356 /* Back up to previous component, ignore if at root 308 /* Back up to previous component, ignore if at root
357 already: */ 309 already: */
358 if (dest > rpath + prefix_len + 1) 310 if (dest > rname + prefix_len + 1)
359 for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest) 311 for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest)
360 continue; 312 continue;
361 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 313 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1
362 && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len) 314 && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)
363 dest++; 315 dest++;
364 } 316 }
365 } 317 }
366 else if (!S_ISDIR (st.st_mode) && *end != '\0') 318 else if (! (startlen == 0
367 { 319 ? stat (rname, &st) == 0 || errno == EOVERFLOW
368 __set_errno (ENOTDIR); 320 : errno == EINVAL))
369 goto error; 321 goto error;
370 }
371 } 322 }
372 } 323 }
373 if (dest > rpath + prefix_len + 1 && ISSLASH (dest[-1])) 324 if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1]))
374 --dest; 325 --dest;
375 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && !prefix_len 326 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && !prefix_len
376 && ISSLASH (*dest) && !ISSLASH (dest[1])) 327 && ISSLASH (*dest) && !ISSLASH (dest[1]))
377 dest++; 328 dest++;
378 *dest = '\0'; 329 failed = false;
379
380 if (extra_buf)
381 freea (extra_buf);
382
383 return rpath;
384 330
385error: 331error:
386 { 332 *dest++ = '\0';
387 int saved_errno = errno; 333 if (resolved != NULL && dest - rname <= get_path_max ())
388 if (extra_buf) 334 rname = strcpy (resolved, rname);
389 freea (extra_buf); 335
390 if (resolved == NULL) 336error_nomem:
391 free (rpath); 337 scratch_buffer_free (&extra_buffer);
392 __set_errno (saved_errno); 338 scratch_buffer_free (&link_buffer);
393 } 339 if (failed || rname == resolved)
394 return NULL; 340 scratch_buffer_free (rname_buf);
341
342 if (failed)
343 return NULL;
344
345 if (rname == resolved)
346 return rname;
347 idx_t rname_size = dest - rname;
348 if (rname == rname_on_stack)
349 {
350 rname = malloc (rname_size);
351 if (rname == NULL)
352 return NULL;
353 return memcpy (rname, rname_on_stack, rname_size);
354 }
355 char *result = realloc (rname, rname_size);
356 return result != NULL ? result : rname;
395} 357}
358libc_hidden_def (__realpath)
396versioned_symbol (libc, __realpath, realpath, GLIBC_2_3); 359versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
397#endif /* !FUNC_REALPATH_WORKS || defined _LIBC */ 360#endif /* !FUNC_REALPATH_WORKS || defined _LIBC */
398 361
@@ -420,11 +383,3 @@ __canonicalize_file_name (const char *name)
420 return __realpath (name, NULL); 383 return __realpath (name, NULL);
421} 384}
422weak_alias (__canonicalize_file_name, canonicalize_file_name) 385weak_alias (__canonicalize_file_name, canonicalize_file_name)
423
424#else
425
426/* This declaration is solely to ensure that after preprocessing
427 this file is never empty. */
428typedef int dummy;
429
430#endif
diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c
index e43aa42d5c4..26fe84df55e 100644
--- a/lib/careadlinkat.c
+++ b/lib/careadlinkat.c
@@ -51,8 +51,13 @@ enum { STACK_BUF_SIZE = 1024 };
51 to pacify GCC is known; even an explicit #pragma does not pacify GCC. 51 to pacify GCC is known; even an explicit #pragma does not pacify GCC.
52 When the GCC bug is fixed this workaround should be limited to the 52 When the GCC bug is fixed this workaround should be limited to the
53 broken GCC versions. */ 53 broken GCC versions. */
54#if (defined GCC_LINT || defined lint) && _GL_GNUC_PREREQ (10, 1) 54#if _GL_GNUC_PREREQ (10, 1)
55# if defined GCC_LINT || defined lint
55__attribute__ ((__noinline__)) 56__attribute__ ((__noinline__))
57# elif __OPTIMIZE__ && !__NO_INLINE__
58# warning "GCC might issue a bogus -Wreturn-local-addr warning here."
59# warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."
60# endif
56#endif 61#endif
57static char * 62static char *
58readlink_stk (int fd, char const *filename, 63readlink_stk (int fd, char const *filename,
@@ -85,18 +90,13 @@ readlink_stk (int fd, char const *filename,
85 size_t link_size; 90 size_t link_size;
86 if (link_length < 0) 91 if (link_length < 0)
87 { 92 {
88 /* On AIX 5L v5.3 and HP-UX 11i v2 04/09, readlink returns -1 93 if (buf != buffer)
89 with errno == ERANGE if the buffer is too small. */
90 int readlinkat_errno = errno;
91 if (readlinkat_errno != ERANGE)
92 { 94 {
93 if (buf != buffer) 95 int readlinkat_errno = errno;
94 { 96 alloc->free (buf);
95 alloc->free (buf); 97 errno = readlinkat_errno;
96 errno = readlinkat_errno;
97 }
98 return NULL;
99 } 98 }
99 return NULL;
100 } 100 }
101 101
102 link_size = link_length; 102 link_size = link_length;
diff --git a/lib/cdefs.h b/lib/cdefs.h
index ff7c628a264..1a2805d7259 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -75,11 +75,11 @@
75 75
76/* GCC can always grok prototypes. For C++ programs we add throw() 76/* GCC can always grok prototypes. For C++ programs we add throw()
77 to help it optimize the function calls. But this works only with 77 to help it optimize the function calls. But this works only with
78 gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions 78 gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions
79 as non-throwing using a function attribute since programs can use 79 as non-throwing using a function attribute since programs can use
80 the -fexceptions options for C code as well. */ 80 the -fexceptions options for C code as well. */
81# if !defined __cplusplus \ 81# if !defined __cplusplus \
82 && (__GNUC_PREREQ (3, 3) || __glibc_clang_has_attribute (__nothrow__)) 82 && (__GNUC_PREREQ (3, 4) || __glibc_clang_has_attribute (__nothrow__))
83# define __THROW __attribute__ ((__nothrow__ __LEAF)) 83# define __THROW __attribute__ ((__nothrow__ __LEAF))
84# define __THROWNL __attribute__ ((__nothrow__)) 84# define __THROWNL __attribute__ ((__nothrow__))
85# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct 85# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
diff --git a/lib/fcntl.c b/lib/fcntl.c
index 8cd1531527d..59bb3ca91ea 100644
--- a/lib/fcntl.c
+++ b/lib/fcntl.c
@@ -491,7 +491,9 @@ rpl_fcntl_DUPFD_CLOEXEC (int fd, int target)
491#if !HAVE_FCNTL 491#if !HAVE_FCNTL
492 result = dupfd (fd, target, O_CLOEXEC); 492 result = dupfd (fd, target, O_CLOEXEC);
493#else /* HAVE_FCNTL */ 493#else /* HAVE_FCNTL */
494# if defined __HAIKU__ 494# if defined __NetBSD__ || defined __HAIKU__
495 /* On NetBSD 9.0, the system fcntl (fd, F_DUPFD_CLOEXEC, target)
496 has only the same effect as fcntl (fd, F_DUPFD, target). */
495 /* On Haiku, the system fcntl (fd, F_DUPFD_CLOEXEC, target) sets 497 /* On Haiku, the system fcntl (fd, F_DUPFD_CLOEXEC, target) sets
496 the FD_CLOEXEC flag on fd, not on target. Therefore avoid the 498 the FD_CLOEXEC flag on fd, not on target. Therefore avoid the
497 system fcntl in this case. */ 499 system fcntl in this case. */
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h
index 6f16bc66921..11c9aae9bcc 100644
--- a/lib/fcntl.in.h
+++ b/lib/fcntl.in.h
@@ -112,9 +112,21 @@ _GL_CXXALIASWARN (creat);
112/* Assume creat is always declared. */ 112/* Assume creat is always declared. */
113_GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - " 113_GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - "
114 "use gnulib module creat for portability"); 114 "use gnulib module creat for portability");
115#elif defined _WIN32 && !defined __CYGWIN__ 115#else
116# undef creat 116/* On native Windows, map 'creat' to '_creat', so that -loldnames is not
117# define creat _creat 117 required. In C++ with GNULIB_NAMESPACE, avoid differences between
118 platforms by defining GNULIB_NAMESPACE::creat always. */
119# if defined _WIN32 && !defined __CYGWIN__
120# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
121# undef creat
122# define creat _creat
123# endif
124/* Need to cast, because in mingw the last argument is 'int mode'. */
125_GL_CXXALIAS_MDA_CAST (creat, int, (const char *filename, mode_t mode));
126# else
127_GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
128# endif
129_GL_CXXALIASWARN (creat);
118#endif 130#endif
119 131
120#if @GNULIB_FCNTL@ 132#if @GNULIB_FCNTL@
@@ -174,9 +186,22 @@ _GL_CXXALIASWARN (open);
174/* Assume open is always declared. */ 186/* Assume open is always declared. */
175_GL_WARN_ON_USE (open, "open is not always POSIX compliant - " 187_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
176 "use gnulib module open for portability"); 188 "use gnulib module open for portability");
177#elif defined _WIN32 && !defined __CYGWIN__ 189#else
178# undef open 190/* On native Windows, map 'open' to '_open', so that -loldnames is not
179# define open _open 191 required. In C++ with GNULIB_NAMESPACE, avoid differences between
192 platforms by defining GNULIB_NAMESPACE::open always. */
193# if defined _WIN32 && !defined __CYGWIN__
194# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
195# undef open
196# define open _open
197# endif
198_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
199# else
200_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
201# endif
202# if !defined __hpux
203_GL_CXXALIASWARN (open);
204# endif
180#endif 205#endif
181 206
182#if @GNULIB_OPENAT@ 207#if @GNULIB_OPENAT@
diff --git a/lib/filemode.c b/lib/filemode.c
index e1b069093f8..15e3551368b 100644
--- a/lib/filemode.c
+++ b/lib/filemode.c
@@ -20,17 +20,6 @@
20 20
21#include "filemode.h" 21#include "filemode.h"
22 22
23/* The following is for Cray DMF (Data Migration Facility), which is a
24 HSM file system. A migrated file has a 'st_dm_mode' that is
25 different from the normal 'st_mode', so any tests for migrated
26 files should use the former. */
27#if HAVE_ST_DM_MODE
28# define IS_MIGRATED_FILE(statp) \
29 (S_ISOFD (statp->st_dm_mode) || S_ISOFL (statp->st_dm_mode))
30#else
31# define IS_MIGRATED_FILE(statp) 0
32#endif
33
34#if ! HAVE_DECL_STRMODE 23#if ! HAVE_DECL_STRMODE
35 24
36/* Return a character indicating the type of file described by 25/* Return a character indicating the type of file described by
@@ -126,7 +115,6 @@ strmode (mode_t mode, char *str)
126 for files whose type cannot be determined solely from st_mode: 115 for files whose type cannot be determined solely from st_mode:
127 116
128 'F' semaphore 117 'F' semaphore
129 'M' migrated file (Cray DMF)
130 'Q' message queue 118 'Q' message queue
131 'S' shared memory object 119 'S' shared memory object
132 'T' typed memory object 120 'T' typed memory object
@@ -169,8 +157,6 @@ filemodestring (struct stat const *statp, char *str)
169 157
170 if (S_TYPEISSEM (statp)) 158 if (S_TYPEISSEM (statp))
171 str[0] = 'F'; 159 str[0] = 'F';
172 else if (IS_MIGRATED_FILE (statp))
173 str[0] = 'M';
174 else if (S_TYPEISMQ (statp)) 160 else if (S_TYPEISMQ (statp))
175 str[0] = 'Q'; 161 str[0] = 'Q';
176 else if (S_TYPEISSHM (statp)) 162 else if (S_TYPEISSHM (statp))
diff --git a/lib/fpending.c b/lib/fpending.c
index 802ebcba654..836a3a988bf 100644
--- a/lib/fpending.c
+++ b/lib/fpending.c
@@ -25,7 +25,8 @@
25#include "stdio-impl.h" 25#include "stdio-impl.h"
26 26
27/* This file is not used on systems that already have the __fpending function, 27/* This file is not used on systems that already have the __fpending function,
28 namely glibc >= 2.2, Solaris >= 7, Android API >= 23. */ 28 namely glibc >= 2.2, Solaris >= 7, UnixWare >= 7.1.4.MP4, Cygwin >= 1.7.34,
29 Android API >= 23. */
29 30
30/* Return the number of pending (aka buffered, unflushed) 31/* Return the number of pending (aka buffered, unflushed)
31 bytes on the stream, FP, that is open for writing. */ 32 bytes on the stream, FP, that is open for writing. */
@@ -39,13 +40,13 @@ __fpending (FILE *fp)
39 /* GNU libc, BeOS, Haiku, Linux libc5 */ 40 /* GNU libc, BeOS, Haiku, Linux libc5 */
40 return fp->_IO_write_ptr - fp->_IO_write_base; 41 return fp->_IO_write_ptr - fp->_IO_write_base;
41#elif defined __sferror || defined __DragonFly__ || defined __ANDROID__ 42#elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
42 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */ 43 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin < 1.7.34, Minix 3, Android */
43 return fp->_p - fp->_bf._base; 44 return fp->_p - fp->_bf._base;
44#elif defined __EMX__ /* emx+gcc */ 45#elif defined __EMX__ /* emx+gcc */
45 return fp->_ptr - fp->_buffer; 46 return fp->_ptr - fp->_buffer;
46#elif defined __minix /* Minix */ 47#elif defined __minix /* Minix */
47 return fp_->_ptr - fp_->_buf; 48 return fp_->_ptr - fp_->_buf;
48#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, MSVC, NonStop Kernel, OpenVMS */ 49#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */
49 return (fp_->_ptr ? fp_->_ptr - fp_->_base : 0); 50 return (fp_->_ptr ? fp_->_ptr - fp_->_base : 0);
50#elif defined __UCLIBC__ /* uClibc */ 51#elif defined __UCLIBC__ /* uClibc */
51 return (fp->__modeflags & __FLAG_WRITING ? fp->__bufpos - fp->__bufstart : 0); 52 return (fp->__modeflags & __FLAG_WRITING ? fp->__bufpos - fp->__bufstart : 0);
diff --git a/lib/free.c b/lib/free.c
new file mode 100644
index 00000000000..2f689a7ea32
--- /dev/null
+++ b/lib/free.c
@@ -0,0 +1,33 @@
1/* Make free() preserve errno.
2
3 Copyright (C) 2003, 2006, 2009-2020 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 <https://www.gnu.org/licenses/>. */
17
18/* written by Paul Eggert */
19
20#include <config.h>
21
22#include <stdlib.h>
23
24#include <errno.h>
25
26void
27rpl_free (void *p)
28#undef free
29{
30 int err = errno;
31 free (p);
32 errno = err;
33}
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 9953198fb31..df533fa6740 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -257,6 +257,7 @@ GL_GENERATE_STDINT_H = @GL_GENERATE_STDINT_H@
257GMALLOC_OBJ = @GMALLOC_OBJ@ 257GMALLOC_OBJ = @GMALLOC_OBJ@
258GMP_H = @GMP_H@ 258GMP_H = @GMP_H@
259GNULIB_ACCESS = @GNULIB_ACCESS@ 259GNULIB_ACCESS = @GNULIB_ACCESS@
260GNULIB_ALIGNED_ALLOC = @GNULIB_ALIGNED_ALLOC@
260GNULIB_ALPHASORT = @GNULIB_ALPHASORT@ 261GNULIB_ALPHASORT = @GNULIB_ALPHASORT@
261GNULIB_ATOLL = @GNULIB_ATOLL@ 262GNULIB_ATOLL = @GNULIB_ATOLL@
262GNULIB_CALLOC_POSIX = @GNULIB_CALLOC_POSIX@ 263GNULIB_CALLOC_POSIX = @GNULIB_CALLOC_POSIX@
@@ -297,6 +298,7 @@ GNULIB_FPURGE = @GNULIB_FPURGE@
297GNULIB_FPUTC = @GNULIB_FPUTC@ 298GNULIB_FPUTC = @GNULIB_FPUTC@
298GNULIB_FPUTS = @GNULIB_FPUTS@ 299GNULIB_FPUTS = @GNULIB_FPUTS@
299GNULIB_FREAD = @GNULIB_FREAD@ 300GNULIB_FREAD = @GNULIB_FREAD@
301GNULIB_FREE_POSIX = @GNULIB_FREE_POSIX@
300GNULIB_FREOPEN = @GNULIB_FREOPEN@ 302GNULIB_FREOPEN = @GNULIB_FREOPEN@
301GNULIB_FSCANF = @GNULIB_FSCANF@ 303GNULIB_FSCANF = @GNULIB_FSCANF@
302GNULIB_FSEEK = @GNULIB_FSEEK@ 304GNULIB_FSEEK = @GNULIB_FSEEK@
@@ -388,6 +390,7 @@ GNULIB_PERROR = @GNULIB_PERROR@
388GNULIB_PIPE = @GNULIB_PIPE@ 390GNULIB_PIPE = @GNULIB_PIPE@
389GNULIB_PIPE2 = @GNULIB_PIPE2@ 391GNULIB_PIPE2 = @GNULIB_PIPE2@
390GNULIB_POPEN = @GNULIB_POPEN@ 392GNULIB_POPEN = @GNULIB_POPEN@
393GNULIB_POSIX_MEMALIGN = @GNULIB_POSIX_MEMALIGN@
391GNULIB_POSIX_OPENPT = @GNULIB_POSIX_OPENPT@ 394GNULIB_POSIX_OPENPT = @GNULIB_POSIX_OPENPT@
392GNULIB_PREAD = @GNULIB_PREAD@ 395GNULIB_PREAD = @GNULIB_PREAD@
393GNULIB_PRINTF = @GNULIB_PRINTF@ 396GNULIB_PRINTF = @GNULIB_PRINTF@
@@ -506,6 +509,7 @@ GTK_OBJ = @GTK_OBJ@
506GZIP_PROG = @GZIP_PROG@ 509GZIP_PROG = @GZIP_PROG@
507HARFBUZZ_CFLAGS = @HARFBUZZ_CFLAGS@ 510HARFBUZZ_CFLAGS = @HARFBUZZ_CFLAGS@
508HARFBUZZ_LIBS = @HARFBUZZ_LIBS@ 511HARFBUZZ_LIBS = @HARFBUZZ_LIBS@
512HAVE_ALIGNED_ALLOC = @HAVE_ALIGNED_ALLOC@
509HAVE_ALLOCA_H = @HAVE_ALLOCA_H@ 513HAVE_ALLOCA_H = @HAVE_ALLOCA_H@
510HAVE_ALPHASORT = @HAVE_ALPHASORT@ 514HAVE_ALPHASORT = @HAVE_ALPHASORT@
511HAVE_ATOLL = @HAVE_ATOLL@ 515HAVE_ATOLL = @HAVE_ATOLL@
@@ -515,13 +519,18 @@ HAVE_CHOWN = @HAVE_CHOWN@
515HAVE_CLOSEDIR = @HAVE_CLOSEDIR@ 519HAVE_CLOSEDIR = @HAVE_CLOSEDIR@
516HAVE_COPY_FILE_RANGE = @HAVE_COPY_FILE_RANGE@ 520HAVE_COPY_FILE_RANGE = @HAVE_COPY_FILE_RANGE@
517HAVE_DECL_DIRFD = @HAVE_DECL_DIRFD@ 521HAVE_DECL_DIRFD = @HAVE_DECL_DIRFD@
522HAVE_DECL_ECVT = @HAVE_DECL_ECVT@
518HAVE_DECL_ENVIRON = @HAVE_DECL_ENVIRON@ 523HAVE_DECL_ENVIRON = @HAVE_DECL_ENVIRON@
524HAVE_DECL_EXECVPE = @HAVE_DECL_EXECVPE@
519HAVE_DECL_FCHDIR = @HAVE_DECL_FCHDIR@ 525HAVE_DECL_FCHDIR = @HAVE_DECL_FCHDIR@
526HAVE_DECL_FCLOSEALL = @HAVE_DECL_FCLOSEALL@
527HAVE_DECL_FCVT = @HAVE_DECL_FCVT@
520HAVE_DECL_FDATASYNC = @HAVE_DECL_FDATASYNC@ 528HAVE_DECL_FDATASYNC = @HAVE_DECL_FDATASYNC@
521HAVE_DECL_FDOPENDIR = @HAVE_DECL_FDOPENDIR@ 529HAVE_DECL_FDOPENDIR = @HAVE_DECL_FDOPENDIR@
522HAVE_DECL_FPURGE = @HAVE_DECL_FPURGE@ 530HAVE_DECL_FPURGE = @HAVE_DECL_FPURGE@
523HAVE_DECL_FSEEKO = @HAVE_DECL_FSEEKO@ 531HAVE_DECL_FSEEKO = @HAVE_DECL_FSEEKO@
524HAVE_DECL_FTELLO = @HAVE_DECL_FTELLO@ 532HAVE_DECL_FTELLO = @HAVE_DECL_FTELLO@
533HAVE_DECL_GCVT = @HAVE_DECL_GCVT@
525HAVE_DECL_GETDELIM = @HAVE_DECL_GETDELIM@ 534HAVE_DECL_GETDELIM = @HAVE_DECL_GETDELIM@
526HAVE_DECL_GETDOMAINNAME = @HAVE_DECL_GETDOMAINNAME@ 535HAVE_DECL_GETDOMAINNAME = @HAVE_DECL_GETDOMAINNAME@
527HAVE_DECL_GETLINE = @HAVE_DECL_GETLINE@ 536HAVE_DECL_GETLINE = @HAVE_DECL_GETLINE@
@@ -621,6 +630,7 @@ HAVE_PDUMPER = @HAVE_PDUMPER@
621HAVE_PIPE = @HAVE_PIPE@ 630HAVE_PIPE = @HAVE_PIPE@
622HAVE_PIPE2 = @HAVE_PIPE2@ 631HAVE_PIPE2 = @HAVE_PIPE2@
623HAVE_POPEN = @HAVE_POPEN@ 632HAVE_POPEN = @HAVE_POPEN@
633HAVE_POSIX_MEMALIGN = @HAVE_POSIX_MEMALIGN@
624HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@ 634HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@
625HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@ 635HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@
626HAVE_PREAD = @HAVE_PREAD@ 636HAVE_PREAD = @HAVE_PREAD@
@@ -863,6 +873,7 @@ PTRDIFF_T_SUFFIX = @PTRDIFF_T_SUFFIX@
863RALLOC_OBJ = @RALLOC_OBJ@ 873RALLOC_OBJ = @RALLOC_OBJ@
864RANLIB = @RANLIB@ 874RANLIB = @RANLIB@
865REPLACE_ACCESS = @REPLACE_ACCESS@ 875REPLACE_ACCESS = @REPLACE_ACCESS@
876REPLACE_ALIGNED_ALLOC = @REPLACE_ALIGNED_ALLOC@
866REPLACE_CALLOC = @REPLACE_CALLOC@ 877REPLACE_CALLOC = @REPLACE_CALLOC@
867REPLACE_CANONICALIZE_FILE_NAME = @REPLACE_CANONICALIZE_FILE_NAME@ 878REPLACE_CANONICALIZE_FILE_NAME = @REPLACE_CANONICALIZE_FILE_NAME@
868REPLACE_CHOWN = @REPLACE_CHOWN@ 879REPLACE_CHOWN = @REPLACE_CHOWN@
@@ -885,6 +896,7 @@ REPLACE_FFLUSH = @REPLACE_FFLUSH@
885REPLACE_FOPEN = @REPLACE_FOPEN@ 896REPLACE_FOPEN = @REPLACE_FOPEN@
886REPLACE_FPRINTF = @REPLACE_FPRINTF@ 897REPLACE_FPRINTF = @REPLACE_FPRINTF@
887REPLACE_FPURGE = @REPLACE_FPURGE@ 898REPLACE_FPURGE = @REPLACE_FPURGE@
899REPLACE_FREE = @REPLACE_FREE@
888REPLACE_FREOPEN = @REPLACE_FREOPEN@ 900REPLACE_FREOPEN = @REPLACE_FREOPEN@
889REPLACE_FSEEK = @REPLACE_FSEEK@ 901REPLACE_FSEEK = @REPLACE_FSEEK@
890REPLACE_FSEEKO = @REPLACE_FSEEKO@ 902REPLACE_FSEEKO = @REPLACE_FSEEKO@
@@ -932,6 +944,7 @@ REPLACE_OPENAT = @REPLACE_OPENAT@
932REPLACE_OPENDIR = @REPLACE_OPENDIR@ 944REPLACE_OPENDIR = @REPLACE_OPENDIR@
933REPLACE_PERROR = @REPLACE_PERROR@ 945REPLACE_PERROR = @REPLACE_PERROR@
934REPLACE_POPEN = @REPLACE_POPEN@ 946REPLACE_POPEN = @REPLACE_POPEN@
947REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@
935REPLACE_PREAD = @REPLACE_PREAD@ 948REPLACE_PREAD = @REPLACE_PREAD@
936REPLACE_PRINTF = @REPLACE_PRINTF@ 949REPLACE_PRINTF = @REPLACE_PRINTF@
937REPLACE_PSELECT = @REPLACE_PSELECT@ 950REPLACE_PSELECT = @REPLACE_PSELECT@
@@ -1101,12 +1114,15 @@ gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1 = @gl_GNULIB_ENABLED_a9786850
1101gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36 = @gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36@ 1114gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36 = @gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36@
1102gl_GNULIB_ENABLED_cloexec = @gl_GNULIB_ENABLED_cloexec@ 1115gl_GNULIB_ENABLED_cloexec = @gl_GNULIB_ENABLED_cloexec@
1103gl_GNULIB_ENABLED_dirfd = @gl_GNULIB_ENABLED_dirfd@ 1116gl_GNULIB_ENABLED_dirfd = @gl_GNULIB_ENABLED_dirfd@
1117gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955 = @gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955@
1104gl_GNULIB_ENABLED_euidaccess = @gl_GNULIB_ENABLED_euidaccess@ 1118gl_GNULIB_ENABLED_euidaccess = @gl_GNULIB_ENABLED_euidaccess@
1105gl_GNULIB_ENABLED_getdtablesize = @gl_GNULIB_ENABLED_getdtablesize@ 1119gl_GNULIB_ENABLED_getdtablesize = @gl_GNULIB_ENABLED_getdtablesize@
1106gl_GNULIB_ENABLED_getgroups = @gl_GNULIB_ENABLED_getgroups@ 1120gl_GNULIB_ENABLED_getgroups = @gl_GNULIB_ENABLED_getgroups@
1121gl_GNULIB_ENABLED_idx = @gl_GNULIB_ENABLED_idx@
1107gl_GNULIB_ENABLED_lchmod = @gl_GNULIB_ENABLED_lchmod@ 1122gl_GNULIB_ENABLED_lchmod = @gl_GNULIB_ENABLED_lchmod@
1108gl_GNULIB_ENABLED_malloca = @gl_GNULIB_ENABLED_malloca@
1109gl_GNULIB_ENABLED_open = @gl_GNULIB_ENABLED_open@ 1123gl_GNULIB_ENABLED_open = @gl_GNULIB_ENABLED_open@
1124gl_GNULIB_ENABLED_rawmemchr = @gl_GNULIB_ENABLED_rawmemchr@
1125gl_GNULIB_ENABLED_scratch_buffer = @gl_GNULIB_ENABLED_scratch_buffer@
1110gl_GNULIB_ENABLED_strtoll = @gl_GNULIB_ENABLED_strtoll@ 1126gl_GNULIB_ENABLED_strtoll = @gl_GNULIB_ENABLED_strtoll@
1111gl_GNULIB_ENABLED_utimens = @gl_GNULIB_ENABLED_utimens@ 1127gl_GNULIB_ENABLED_utimens = @gl_GNULIB_ENABLED_utimens@
1112gl_LIBOBJS = @gl_LIBOBJS@ 1128gl_LIBOBJS = @gl_LIBOBJS@
@@ -1731,6 +1747,19 @@ EXTRA_libgnu_a_SOURCES += fpending.c
1731endif 1747endif
1732## end gnulib module fpending 1748## end gnulib module fpending
1733 1749
1750## begin gnulib module free-posix
1751ifeq (,$(OMIT_GNULIB_MODULE_free-posix))
1752
1753ifneq (,$(gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955))
1754
1755endif
1756EXTRA_DIST += free.c
1757
1758EXTRA_libgnu_a_SOURCES += free.c
1759
1760endif
1761## end gnulib module free-posix
1762
1734## begin gnulib module fstatat 1763## begin gnulib module fstatat
1735ifeq (,$(OMIT_GNULIB_MODULE_fstatat)) 1764ifeq (,$(OMIT_GNULIB_MODULE_fstatat))
1736 1765
@@ -1912,6 +1941,16 @@ EXTRA_libgnu_a_SOURCES += group-member.c
1912endif 1941endif
1913## end gnulib module group-member 1942## end gnulib module group-member
1914 1943
1944## begin gnulib module idx
1945ifeq (,$(OMIT_GNULIB_MODULE_idx))
1946
1947ifneq (,$(gl_GNULIB_ENABLED_idx))
1948libgnu_a_SOURCES += idx.h
1949
1950endif
1951endif
1952## end gnulib module idx
1953
1915## begin gnulib module ieee754-h 1954## begin gnulib module ieee754-h
1916ifeq (,$(OMIT_GNULIB_MODULE_ieee754-h)) 1955ifeq (,$(OMIT_GNULIB_MODULE_ieee754-h))
1917 1956
@@ -2094,18 +2133,6 @@ EXTRA_libgnu_a_SOURCES += lstat.c
2094endif 2133endif
2095## end gnulib module lstat 2134## end gnulib module lstat
2096 2135
2097## begin gnulib module malloca
2098ifeq (,$(OMIT_GNULIB_MODULE_malloca))
2099
2100ifneq (,$(gl_GNULIB_ENABLED_malloca))
2101libgnu_a_SOURCES += malloca.c
2102
2103endif
2104EXTRA_DIST += malloca.h
2105
2106endif
2107## end gnulib module malloca
2108
2109## begin gnulib module memmem-simple 2136## begin gnulib module memmem-simple
2110ifeq (,$(OMIT_GNULIB_MODULE_memmem-simple)) 2137ifeq (,$(OMIT_GNULIB_MODULE_memmem-simple))
2111 2138
@@ -2263,6 +2290,19 @@ libgnu_a_SOURCES += qcopy-acl.c
2263endif 2290endif
2264## end gnulib module qcopy-acl 2291## end gnulib module qcopy-acl
2265 2292
2293## begin gnulib module rawmemchr
2294ifeq (,$(OMIT_GNULIB_MODULE_rawmemchr))
2295
2296ifneq (,$(gl_GNULIB_ENABLED_rawmemchr))
2297
2298endif
2299EXTRA_DIST += rawmemchr.c rawmemchr.valgrind
2300
2301EXTRA_libgnu_a_SOURCES += rawmemchr.c
2302
2303endif
2304## end gnulib module rawmemchr
2305
2266## begin gnulib module readlink 2306## begin gnulib module readlink
2267ifeq (,$(OMIT_GNULIB_MODULE_readlink)) 2307ifeq (,$(OMIT_GNULIB_MODULE_readlink))
2268 2308
@@ -2307,6 +2347,18 @@ EXTRA_DIST += root-uid.h
2307endif 2347endif
2308## end gnulib module root-uid 2348## end gnulib module root-uid
2309 2349
2350## begin gnulib module scratch_buffer
2351ifeq (,$(OMIT_GNULIB_MODULE_scratch_buffer))
2352
2353ifneq (,$(gl_GNULIB_ENABLED_scratch_buffer))
2354libgnu_a_SOURCES += malloc/scratch_buffer_grow.c malloc/scratch_buffer_grow_preserve.c malloc/scratch_buffer_set_array_size.c
2355
2356endif
2357EXTRA_DIST += malloc/scratch_buffer.h scratch_buffer.h
2358
2359endif
2360## end gnulib module scratch_buffer
2361
2310## begin gnulib module sig2str 2362## begin gnulib module sig2str
2311ifeq (,$(OMIT_GNULIB_MODULE_sig2str)) 2363ifeq (,$(OMIT_GNULIB_MODULE_sig2str))
2312 2364
@@ -2618,7 +2670,8 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
2618 -e 's/@''GNULIB_VSNPRINTF''@/$(GNULIB_VSNPRINTF)/g' \ 2670 -e 's/@''GNULIB_VSNPRINTF''@/$(GNULIB_VSNPRINTF)/g' \
2619 -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \ 2671 -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \
2620 < $(srcdir)/stdio.in.h | \ 2672 < $(srcdir)/stdio.in.h | \
2621 sed -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \ 2673 sed -e 's|@''HAVE_DECL_FCLOSEALL''@|$(HAVE_DECL_FCLOSEALL)|g' \
2674 -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \
2622 -e 's|@''HAVE_DECL_FSEEKO''@|$(HAVE_DECL_FSEEKO)|g' \ 2675 -e 's|@''HAVE_DECL_FSEEKO''@|$(HAVE_DECL_FSEEKO)|g' \
2623 -e 's|@''HAVE_DECL_FTELLO''@|$(HAVE_DECL_FTELLO)|g' \ 2676 -e 's|@''HAVE_DECL_FTELLO''@|$(HAVE_DECL_FTELLO)|g' \
2624 -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \ 2677 -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
@@ -2696,9 +2749,11 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
2696 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2749 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
2697 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ 2750 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
2698 -e 's/@''GNULIB__EXIT''@/$(GNULIB__EXIT)/g' \ 2751 -e 's/@''GNULIB__EXIT''@/$(GNULIB__EXIT)/g' \
2752 -e 's/@''GNULIB_ALIGNED_ALLOC''@/$(GNULIB_ALIGNED_ALLOC)/g' \
2699 -e 's/@''GNULIB_ATOLL''@/$(GNULIB_ATOLL)/g' \ 2753 -e 's/@''GNULIB_ATOLL''@/$(GNULIB_ATOLL)/g' \
2700 -e 's/@''GNULIB_CALLOC_POSIX''@/$(GNULIB_CALLOC_POSIX)/g' \ 2754 -e 's/@''GNULIB_CALLOC_POSIX''@/$(GNULIB_CALLOC_POSIX)/g' \
2701 -e 's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GNULIB_CANONICALIZE_FILE_NAME)/g' \ 2755 -e 's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GNULIB_CANONICALIZE_FILE_NAME)/g' \
2756 -e 's/@''GNULIB_FREE_POSIX''@/$(GNULIB_FREE_POSIX)/g' \
2702 -e 's/@''GNULIB_GETLOADAVG''@/$(GNULIB_GETLOADAVG)/g' \ 2757 -e 's/@''GNULIB_GETLOADAVG''@/$(GNULIB_GETLOADAVG)/g' \
2703 -e 's/@''GNULIB_GETSUBOPT''@/$(GNULIB_GETSUBOPT)/g' \ 2758 -e 's/@''GNULIB_GETSUBOPT''@/$(GNULIB_GETSUBOPT)/g' \
2704 -e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \ 2759 -e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \
@@ -2709,6 +2764,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
2709 -e 's/@''GNULIB_MKOSTEMPS''@/$(GNULIB_MKOSTEMPS)/g' \ 2764 -e 's/@''GNULIB_MKOSTEMPS''@/$(GNULIB_MKOSTEMPS)/g' \
2710 -e 's/@''GNULIB_MKSTEMP''@/$(GNULIB_MKSTEMP)/g' \ 2765 -e 's/@''GNULIB_MKSTEMP''@/$(GNULIB_MKSTEMP)/g' \
2711 -e 's/@''GNULIB_MKSTEMPS''@/$(GNULIB_MKSTEMPS)/g' \ 2766 -e 's/@''GNULIB_MKSTEMPS''@/$(GNULIB_MKSTEMPS)/g' \
2767 -e 's/@''GNULIB_POSIX_MEMALIGN''@/$(GNULIB_POSIX_MEMALIGN)/g' \
2712 -e 's/@''GNULIB_POSIX_OPENPT''@/$(GNULIB_POSIX_OPENPT)/g' \ 2768 -e 's/@''GNULIB_POSIX_OPENPT''@/$(GNULIB_POSIX_OPENPT)/g' \
2713 -e 's/@''GNULIB_PTSNAME''@/$(GNULIB_PTSNAME)/g' \ 2769 -e 's/@''GNULIB_PTSNAME''@/$(GNULIB_PTSNAME)/g' \
2714 -e 's/@''GNULIB_PTSNAME_R''@/$(GNULIB_PTSNAME_R)/g' \ 2770 -e 's/@''GNULIB_PTSNAME_R''@/$(GNULIB_PTSNAME_R)/g' \
@@ -2732,8 +2788,12 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
2732 -e 's/@''GNULIB_WCTOMB''@/$(GNULIB_WCTOMB)/g' \ 2788 -e 's/@''GNULIB_WCTOMB''@/$(GNULIB_WCTOMB)/g' \
2733 < $(srcdir)/stdlib.in.h | \ 2789 < $(srcdir)/stdlib.in.h | \
2734 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \ 2790 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
2791 -e 's|@''HAVE_ALIGNED_ALLOC''@|$(HAVE_ALIGNED_ALLOC)|g' \
2735 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ 2792 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
2736 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ 2793 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
2794 -e 's|@''HAVE_DECL_ECVT''@|$(HAVE_DECL_ECVT)|g' \
2795 -e 's|@''HAVE_DECL_FCVT''@|$(HAVE_DECL_FCVT)|g' \
2796 -e 's|@''HAVE_DECL_GCVT''@|$(HAVE_DECL_GCVT)|g' \
2737 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ 2797 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
2738 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ 2798 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
2739 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ 2799 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
@@ -2745,6 +2805,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
2745 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \ 2805 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
2746 -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \ 2806 -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \
2747 -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \ 2807 -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \
2808 -e 's|@''HAVE_POSIX_MEMALIGN''@|$(HAVE_POSIX_MEMALIGN)|g' \
2748 -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \ 2809 -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \
2749 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ 2810 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
2750 -e 's|@''HAVE_PTSNAME_R''@|$(HAVE_PTSNAME_R)|g' \ 2811 -e 's|@''HAVE_PTSNAME_R''@|$(HAVE_PTSNAME_R)|g' \
@@ -2767,12 +2828,15 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
2767 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ 2828 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
2768 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \ 2829 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
2769 -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \ 2830 -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \
2831 -e 's|@''REPLACE_ALIGNED_ALLOC''@|$(REPLACE_ALIGNED_ALLOC)|g' \
2770 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \ 2832 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
2771 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ 2833 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
2834 -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
2772 -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \ 2835 -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \
2773 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ 2836 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
2774 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \ 2837 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
2775 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ 2838 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
2839 -e 's|@''REPLACE_POSIX_MEMALIGN''@|$(REPLACE_POSIX_MEMALIGN)|g' \
2776 -e 's|@''REPLACE_PTSNAME''@|$(REPLACE_PTSNAME)|g' \ 2840 -e 's|@''REPLACE_PTSNAME''@|$(REPLACE_PTSNAME)|g' \
2777 -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \ 2841 -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \
2778 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ 2842 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
@@ -3412,6 +3476,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
3412 -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \ 3476 -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \
3413 -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \ 3477 -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
3414 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ 3478 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
3479 -e 's|@''HAVE_DECL_EXECVPE''@|$(HAVE_DECL_EXECVPE)|g' \
3415 -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \ 3480 -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \
3416 -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \ 3481 -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \
3417 -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \ 3482 -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \
diff --git a/lib/idx.h b/lib/idx.h
new file mode 100644
index 00000000000..6a7739fa9c7
--- /dev/null
+++ b/lib/idx.h
@@ -0,0 +1,113 @@
1/* A type for indices and sizes.
2
3 Copyright (C) 2020 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 <https://www.gnu.org/licenses/>. */
17
18#ifndef _IDX_H
19#define _IDX_H
20
21/* Get ptrdiff_t. */
22#include <stddef.h>
23
24/* Get PTRDIFF_MAX. */
25#include <stdint.h>
26
27/* The type 'idx_t' holds an (array) index or an (object) size.
28 Its implementation promotes to a signed integer type,
29 which can hold the values
30 0..2^63-1 (on 64-bit platforms) or
31 0..2^31-1 (on 32-bit platforms).
32
33 Why a signed integer type?
34
35 * Security: Signed types can be checked for overflow via
36 '-fsanitize=undefined', but unsigned types cannot.
37
38 * Comparisons without surprises: ISO C99 § 6.3.1.8 specifies a few
39 surprising results for comparisons, such as
40
41 (int) -3 < (unsigned long) 7 => false
42 (int) -3 < (unsigned int) 7 => false
43 and on 32-bit machines:
44 (long) -3 < (unsigned int) 7 => false
45
46 This is surprising because the natural comparison order is by
47 value in the realm of infinite-precision signed integers (ℤ).
48
49 The best way to get rid of such surprises is to use signed types
50 for numerical integer values, and use unsigned types only for
51 bit masks and enums.
52
53 Why not use 'size_t' directly?
54
55 * Because 'size_t' is an unsigned type, and a signed type is better.
56 See above.
57
58 Why not use 'ptrdiff_t' directly?
59
60 * Maintainability: When reading and modifying code, it helps to know that
61 a certain variable cannot have negative values. For example, when you
62 have a loop
63
64 int n = ...;
65 for (int i = 0; i < n; i++) ...
66
67 or
68
69 ptrdiff_t n = ...;
70 for (ptrdiff_t i = 0; i < n; i++) ...
71
72 you have to ask yourself "what if n < 0?". Whereas in
73
74 idx_t n = ...;
75 for (idx_t i = 0; i < n; i++) ...
76
77 you know that this case cannot happen.
78
79 Similarly, when a programmer writes
80
81 idx_t = ptr2 - ptr1;
82
83 there is an implied assertion that ptr1 and ptr2 point into the same
84 object and that ptr1 <= ptr2.
85
86 * Being future-proof: In the future, range types (integers which are
87 constrained to a certain range of values) may be added to C compilers
88 or to the C standard. Several programming languages (Ada, Haskell,
89 Common Lisp, Pascal) already have range types. Such range types may
90 help producing good code and good warnings. The type 'idx_t' could
91 then be typedef'ed to a range type that is signed after promotion. */
92
93/* In the future, idx_t could be typedef'ed to a signed range type.
94 The clang "extended integer types", supported in Clang 11 or newer
95 <https://clang.llvm.org/docs/LanguageExtensions.html#extended-integer-types>,
96 are a special case of range types. However, these types don't support binary
97 operators with plain integer types (e.g. expressions such as x > 1).
98 Therefore, they don't behave like signed types (and not like unsigned types
99 either). So, we cannot use them here. */
100
101/* Use the signed type 'ptrdiff_t'. */
102/* Note: ISO C does not mandate that 'size_t' and 'ptrdiff_t' have the same
103 size, but it is so on all platforms we have seen since 1990. */
104typedef ptrdiff_t idx_t;
105
106/* IDX_MAX is the maximum value of an idx_t. */
107#define IDX_MAX PTRDIFF_MAX
108
109/* So far no need has been found for an IDX_WIDTH macro.
110 Perhaps there should be another macro IDX_VALUE_BITS that does not
111 count the sign bit and is therefore one less than PTRDIFF_WIDTH. */
112
113#endif /* _IDX_H */
diff --git a/lib/intprops.h b/lib/intprops.h
index b27f2eea056..bc2107c9295 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -226,7 +226,9 @@
226 226
227/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow 227/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow
228 (A, B, P) work when P is non-null. */ 228 (A, B, P) work when P is non-null. */
229#if 5 <= __GNUC__ && !defined __ICC 229/* __builtin_{add,sub}_overflow exists but is not reliable in GCC 5.x and 6.x,
230 see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269>. */
231#if 7 <= __GNUC__ && !defined __ICC
230# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1 232# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1
231#elif defined __has_builtin 233#elif defined __has_builtin
232# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow) 234# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow)
@@ -244,7 +246,17 @@
244 246
245/* True if __builtin_add_overflow_p (A, B, C) works, and similarly for 247/* True if __builtin_add_overflow_p (A, B, C) works, and similarly for
246 __builtin_sub_overflow_p and __builtin_mul_overflow_p. */ 248 __builtin_sub_overflow_p and __builtin_mul_overflow_p. */
247#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__) 249#if defined __clang__ || defined __ICC
250/* Clang 11 lacks __builtin_mul_overflow_p, and even if it did it
251 would presumably run afoul of Clang bug 16404. ICC 2021.1's
252 __builtin_add_overflow_p etc. are not treated as integral constant
253 expressions even when all arguments are. */
254# define _GL_HAS_BUILTIN_OVERFLOW_P 0
255#elif defined __has_builtin
256# define _GL_HAS_BUILTIN_OVERFLOW_P __has_builtin (__builtin_mul_overflow_p)
257#else
258# define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
259#endif
248 260
249/* The _GL*_OVERFLOW macros have the same restrictions as the 261/* The _GL*_OVERFLOW macros have the same restrictions as the
250 *_RANGE_OVERFLOW macros, except that they do not assume that operands 262 *_RANGE_OVERFLOW macros, except that they do not assume that operands
@@ -377,8 +389,9 @@
377 _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW) 389 _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
378#endif 390#endif
379#if _GL_HAS_BUILTIN_MUL_OVERFLOW 391#if _GL_HAS_BUILTIN_MUL_OVERFLOW
380# if (9 < __GNUC__ + (3 <= __GNUC_MINOR__) \ 392# if ((9 < __GNUC__ + (3 <= __GNUC_MINOR__) \
381 || (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) 393 || (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) \
394 && !defined __ICC)
382# define INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r) 395# define INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r)
383# else 396# else
384 /* Work around GCC bug 91450. */ 397 /* Work around GCC bug 91450. */
@@ -585,4 +598,33 @@
585 : (tmin) / (a) < (b)) \ 598 : (tmin) / (a) < (b)) \
586 : (tmax) / (b) < (a))) 599 : (tmax) / (b) < (a)))
587 600
601/* The following macros compute A + B, A - B, and A * B, respectively.
602 If no overflow occurs, they set *R to the result and return 1;
603 otherwise, they return 0 and may modify *R.
604
605 Example usage:
606
607 long int result;
608 if (INT_ADD_OK (a, b, &result))
609 printf ("result is %ld\n", result);
610 else
611 printf ("overflow\n");
612
613 A, B, and *R should be integers; they need not be the same type,
614 and they need not be all signed or all unsigned.
615
616 These macros work correctly on all known practical hosts, and do not rely
617 on undefined behavior due to signed arithmetic overflow.
618
619 These macros are not constant expressions.
620
621 These macros may evaluate their arguments zero or multiple times, so the
622 arguments should not have side effects.
623
624 These macros are tuned for B being a constant. */
625
626#define INT_ADD_OK(a, b, r) ! INT_ADD_WRAPV (a, b, r)
627#define INT_SUBTRACT_OK(a, b, r) ! INT_SUBTRACT_WRAPV (a, b, r)
628#define INT_MULTIPLY_OK(a, b, r) ! INT_MULTIPLY_WRAPV (a, b, r)
629
588#endif /* _GL_INTPROPS_H */ 630#endif /* _GL_INTPROPS_H */
diff --git a/lib/malloc/scratch_buffer.h b/lib/malloc/scratch_buffer.h
new file mode 100644
index 00000000000..b40478637c8
--- /dev/null
+++ b/lib/malloc/scratch_buffer.h
@@ -0,0 +1,135 @@
1/* Variable-sized buffer with on-stack default allocation.
2 Copyright (C) 2015-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C 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 The GNU C 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
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _SCRATCH_BUFFER_H
20#define _SCRATCH_BUFFER_H
21
22/* Scratch buffers with a default stack allocation and fallback to
23 heap allocation. It is expected that this function is used in this
24 way:
25
26 struct scratch_buffer tmpbuf;
27 scratch_buffer_init (&tmpbuf);
28
29 while (!function_that_uses_buffer (tmpbuf.data, tmpbuf.length))
30 if (!scratch_buffer_grow (&tmpbuf))
31 return -1;
32
33 scratch_buffer_free (&tmpbuf);
34 return 0;
35
36 The allocation functions (scratch_buffer_grow,
37 scratch_buffer_grow_preserve, scratch_buffer_set_array_size) make
38 sure that the heap allocation, if any, is freed, so that the code
39 above does not have a memory leak. The buffer still remains in a
40 state that can be deallocated using scratch_buffer_free, so a loop
41 like this is valid as well:
42
43 struct scratch_buffer tmpbuf;
44 scratch_buffer_init (&tmpbuf);
45
46 while (!function_that_uses_buffer (tmpbuf.data, tmpbuf.length))
47 if (!scratch_buffer_grow (&tmpbuf))
48 break;
49
50 scratch_buffer_free (&tmpbuf);
51
52 scratch_buffer_grow and scratch_buffer_grow_preserve are guaranteed
53 to grow the buffer by at least 512 bytes. This means that when
54 using the scratch buffer as a backing store for a non-character
55 array whose element size, in bytes, is 512 or smaller, the scratch
56 buffer only has to grow once to make room for at least one more
57 element.
58*/
59
60#include <stdbool.h>
61#include <stddef.h>
62#include <stdlib.h>
63
64/* Scratch buffer. Must be initialized with scratch_buffer_init
65 before its use. */
66struct scratch_buffer {
67 void *data; /* Pointer to the beginning of the scratch area. */
68 size_t length; /* Allocated space at the data pointer, in bytes. */
69 union { max_align_t __align; char __c[1024]; } __space;
70};
71
72/* Initializes *BUFFER so that BUFFER->data points to BUFFER->__space
73 and BUFFER->length reflects the available space. */
74static inline void
75scratch_buffer_init (struct scratch_buffer *buffer)
76{
77 buffer->data = buffer->__space.__c;
78 buffer->length = sizeof (buffer->__space);
79}
80
81/* Deallocates *BUFFER (if it was heap-allocated). */
82static inline void
83scratch_buffer_free (struct scratch_buffer *buffer)
84{
85 if (buffer->data != buffer->__space.__c)
86 free (buffer->data);
87}
88
89/* Grow *BUFFER by some arbitrary amount. The buffer contents is NOT
90 preserved. Return true on success, false on allocation failure (in
91 which case the old buffer is freed). On success, the new buffer is
92 larger than the previous size. On failure, *BUFFER is deallocated,
93 but remains in a free-able state, and errno is set. */
94bool __libc_scratch_buffer_grow (struct scratch_buffer *buffer);
95libc_hidden_proto (__libc_scratch_buffer_grow)
96
97/* Alias for __libc_scratch_buffer_grow. */
98static __always_inline bool
99scratch_buffer_grow (struct scratch_buffer *buffer)
100{
101 return __glibc_likely (__libc_scratch_buffer_grow (buffer));
102}
103
104/* Like __libc_scratch_buffer_grow, but preserve the old buffer
105 contents on success, as a prefix of the new buffer. */
106bool __libc_scratch_buffer_grow_preserve (struct scratch_buffer *buffer);
107libc_hidden_proto (__libc_scratch_buffer_grow_preserve)
108
109/* Alias for __libc_scratch_buffer_grow_preserve. */
110static __always_inline bool
111scratch_buffer_grow_preserve (struct scratch_buffer *buffer)
112{
113 return __glibc_likely (__libc_scratch_buffer_grow_preserve (buffer));
114}
115
116/* Grow *BUFFER so that it can store at least NELEM elements of SIZE
117 bytes. The buffer contents are NOT preserved. Both NELEM and SIZE
118 can be zero. Return true on success, false on allocation failure
119 (in which case the old buffer is freed, but *BUFFER remains in a
120 free-able state, and errno is set). It is unspecified whether this
121 function can reduce the array size. */
122bool __libc_scratch_buffer_set_array_size (struct scratch_buffer *buffer,
123 size_t nelem, size_t size);
124libc_hidden_proto (__libc_scratch_buffer_set_array_size)
125
126/* Alias for __libc_scratch_set_array_size. */
127static __always_inline bool
128scratch_buffer_set_array_size (struct scratch_buffer *buffer,
129 size_t nelem, size_t size)
130{
131 return __glibc_likely (__libc_scratch_buffer_set_array_size
132 (buffer, nelem, size));
133}
134
135#endif /* _SCRATCH_BUFFER_H */
diff --git a/lib/malloc/scratch_buffer_grow.c b/lib/malloc/scratch_buffer_grow.c
new file mode 100644
index 00000000000..41befe3d65f
--- /dev/null
+++ b/lib/malloc/scratch_buffer_grow.c
@@ -0,0 +1,56 @@
1/* Variable-sized buffer with on-stack default allocation.
2 Copyright (C) 2015-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C 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 The GNU C 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
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LIBC
20# include <libc-config.h>
21#endif
22
23#include <scratch_buffer.h>
24#include <errno.h>
25
26bool
27__libc_scratch_buffer_grow (struct scratch_buffer *buffer)
28{
29 void *new_ptr;
30 size_t new_length = buffer->length * 2;
31
32 /* Discard old buffer. */
33 scratch_buffer_free (buffer);
34
35 /* Check for overflow. */
36 if (__glibc_likely (new_length >= buffer->length))
37 new_ptr = malloc (new_length);
38 else
39 {
40 __set_errno (ENOMEM);
41 new_ptr = NULL;
42 }
43
44 if (__glibc_unlikely (new_ptr == NULL))
45 {
46 /* Buffer must remain valid to free. */
47 scratch_buffer_init (buffer);
48 return false;
49 }
50
51 /* Install new heap-based buffer. */
52 buffer->data = new_ptr;
53 buffer->length = new_length;
54 return true;
55}
56libc_hidden_def (__libc_scratch_buffer_grow)
diff --git a/lib/malloc/scratch_buffer_grow_preserve.c b/lib/malloc/scratch_buffer_grow_preserve.c
new file mode 100644
index 00000000000..aef232938d5
--- /dev/null
+++ b/lib/malloc/scratch_buffer_grow_preserve.c
@@ -0,0 +1,67 @@
1/* Variable-sized buffer with on-stack default allocation.
2 Copyright (C) 2015-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C 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 The GNU C 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
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LIBC
20# include <libc-config.h>
21#endif
22
23#include <scratch_buffer.h>
24#include <errno.h>
25#include <string.h>
26
27bool
28__libc_scratch_buffer_grow_preserve (struct scratch_buffer *buffer)
29{
30 size_t new_length = 2 * buffer->length;
31 void *new_ptr;
32
33 if (buffer->data == buffer->__space.__c)
34 {
35 /* Move buffer to the heap. No overflow is possible because
36 buffer->length describes a small buffer on the stack. */
37 new_ptr = malloc (new_length);
38 if (new_ptr == NULL)
39 return false;
40 memcpy (new_ptr, buffer->__space.__c, buffer->length);
41 }
42 else
43 {
44 /* Buffer was already on the heap. Check for overflow. */
45 if (__glibc_likely (new_length >= buffer->length))
46 new_ptr = realloc (buffer->data, new_length);
47 else
48 {
49 __set_errno (ENOMEM);
50 new_ptr = NULL;
51 }
52
53 if (__glibc_unlikely (new_ptr == NULL))
54 {
55 /* Deallocate, but buffer must remain valid to free. */
56 free (buffer->data);
57 scratch_buffer_init (buffer);
58 return false;
59 }
60 }
61
62 /* Install new heap-based buffer. */
63 buffer->data = new_ptr;
64 buffer->length = new_length;
65 return true;
66}
67libc_hidden_def (__libc_scratch_buffer_grow_preserve)
diff --git a/lib/malloc/scratch_buffer_set_array_size.c b/lib/malloc/scratch_buffer_set_array_size.c
new file mode 100644
index 00000000000..5f5e4c24f5a
--- /dev/null
+++ b/lib/malloc/scratch_buffer_set_array_size.c
@@ -0,0 +1,64 @@
1/* Variable-sized buffer with on-stack default allocation.
2 Copyright (C) 2015-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C 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 The GNU C 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
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LIBC
20# include <libc-config.h>
21#endif
22
23#include <scratch_buffer.h>
24#include <errno.h>
25#include <limits.h>
26
27bool
28__libc_scratch_buffer_set_array_size (struct scratch_buffer *buffer,
29 size_t nelem, size_t size)
30{
31 size_t new_length = nelem * size;
32
33 /* Avoid overflow check if both values are small. */
34 if ((nelem | size) >> (sizeof (size_t) * CHAR_BIT / 2) != 0
35 && nelem != 0 && size != new_length / nelem)
36 {
37 /* Overflow. Discard the old buffer, but it must remain valid
38 to free. */
39 scratch_buffer_free (buffer);
40 scratch_buffer_init (buffer);
41 __set_errno (ENOMEM);
42 return false;
43 }
44
45 if (new_length <= buffer->length)
46 return true;
47
48 /* Discard old buffer. */
49 scratch_buffer_free (buffer);
50
51 char *new_ptr = malloc (new_length);
52 if (new_ptr == NULL)
53 {
54 /* Buffer must remain valid to free. */
55 scratch_buffer_init (buffer);
56 return false;
57 }
58
59 /* Install new heap-based buffer. */
60 buffer->data = new_ptr;
61 buffer->length = new_length;
62 return true;
63}
64libc_hidden_def (__libc_scratch_buffer_set_array_size)
diff --git a/lib/rawmemchr.c b/lib/rawmemchr.c
new file mode 100644
index 00000000000..04bf08415c6
--- /dev/null
+++ b/lib/rawmemchr.c
@@ -0,0 +1,136 @@
1/* Searching in a string.
2 Copyright (C) 2008-2020 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 <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <string.h>
21
22/* Find the first occurrence of C in S. */
23void *
24rawmemchr (const void *s, int c_in)
25{
26 /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
27 long instead of a 64-bit uintmax_t tends to give better
28 performance. On 64-bit hardware, unsigned long is generally 64
29 bits already. Change this typedef to experiment with
30 performance. */
31 typedef unsigned long int longword;
32
33 const unsigned char *char_ptr;
34 const longword *longword_ptr;
35 longword repeated_one;
36 longword repeated_c;
37 unsigned char c;
38
39 c = (unsigned char) c_in;
40
41 /* Handle the first few bytes by reading one byte at a time.
42 Do this until CHAR_PTR is aligned on a longword boundary. */
43 for (char_ptr = (const unsigned char *) s;
44 (size_t) char_ptr % sizeof (longword) != 0;
45 ++char_ptr)
46 if (*char_ptr == c)
47 return (void *) char_ptr;
48
49 longword_ptr = (const longword *) char_ptr;
50
51 /* All these elucidatory comments refer to 4-byte longwords,
52 but the theory applies equally well to any size longwords. */
53
54 /* Compute auxiliary longword values:
55 repeated_one is a value which has a 1 in every byte.
56 repeated_c has c in every byte. */
57 repeated_one = 0x01010101;
58 repeated_c = c | (c << 8);
59 repeated_c |= repeated_c << 16;
60 if (0xffffffffU < (longword) -1)
61 {
62 repeated_one |= repeated_one << 31 << 1;
63 repeated_c |= repeated_c << 31 << 1;
64 if (8 < sizeof (longword))
65 {
66 size_t i;
67
68 for (i = 64; i < sizeof (longword) * 8; i *= 2)
69 {
70 repeated_one |= repeated_one << i;
71 repeated_c |= repeated_c << i;
72 }
73 }
74 }
75
76 /* Instead of the traditional loop which tests each byte, we will
77 test a longword at a time. The tricky part is testing if *any of
78 the four* bytes in the longword in question are equal to NUL or
79 c. We first use an xor with repeated_c. This reduces the task
80 to testing whether *any of the four* bytes in longword1 is zero.
81
82 We compute tmp =
83 ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
84 That is, we perform the following operations:
85 1. Subtract repeated_one.
86 2. & ~longword1.
87 3. & a mask consisting of 0x80 in every byte.
88 Consider what happens in each byte:
89 - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
90 and step 3 transforms it into 0x80. A carry can also be propagated
91 to more significant bytes.
92 - If a byte of longword1 is nonzero, let its lowest 1 bit be at
93 position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
94 the byte ends in a single bit of value 0 and k bits of value 1.
95 After step 2, the result is just k bits of value 1: 2^k - 1. After
96 step 3, the result is 0. And no carry is produced.
97 So, if longword1 has only non-zero bytes, tmp is zero.
98 Whereas if longword1 has a zero byte, call j the position of the least
99 significant zero byte. Then the result has a zero at positions 0, ...,
100 j-1 and a 0x80 at position j. We cannot predict the result at the more
101 significant bytes (positions j+1..3), but it does not matter since we
102 already have a non-zero bit at position 8*j+7.
103
104 The test whether any byte in longword1 is zero is equivalent
105 to testing whether tmp is nonzero.
106
107 This test can read beyond the end of a string, depending on where
108 C_IN is encountered. However, this is considered safe since the
109 initialization phase ensured that the read will be aligned,
110 therefore, the read will not cross page boundaries and will not
111 cause a fault. */
112
113 while (1)
114 {
115 longword longword1 = *longword_ptr ^ repeated_c;
116
117 if ((((longword1 - repeated_one) & ~longword1)
118 & (repeated_one << 7)) != 0)
119 break;
120 longword_ptr++;
121 }
122
123 char_ptr = (const unsigned char *) longword_ptr;
124
125 /* At this point, we know that one of the sizeof (longword) bytes
126 starting at char_ptr is == c. On little-endian machines, we
127 could determine the first such byte without any further memory
128 accesses, just by looking at the tmp result from the last loop
129 iteration. But this does not work on big-endian machines.
130 Choose code that works in both cases. */
131
132 char_ptr = (unsigned char *) longword_ptr;
133 while (*char_ptr != c)
134 char_ptr++;
135 return (void *) char_ptr;
136}
diff --git a/lib/rawmemchr.valgrind b/lib/rawmemchr.valgrind
new file mode 100644
index 00000000000..53c5b317d5f
--- /dev/null
+++ b/lib/rawmemchr.valgrind
@@ -0,0 +1,28 @@
1# Suppress a valgrind message about use of uninitialized memory in rawmemchr().
2
3# Copyright (C) 2008-2020 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 <https://www.gnu.org/licenses/>.
17
18# This use is OK because it provides only a speedup.
19{
20 rawmemchr-value4
21 Memcheck:Value4
22 fun:rawmemchr
23}
24{
25 rawmemchr-value8
26 Memcheck:Value8
27 fun:rawmemchr
28}
diff --git a/lib/readlink.c b/lib/readlink.c
index 4d392ef6995..531913eba3e 100644
--- a/lib/readlink.c
+++ b/lib/readlink.c
@@ -1,4 +1,4 @@
1/* Stub for readlink(). 1/* Read the contents of a symbolic link.
2 Copyright (C) 2003-2007, 2009-2020 Free Software Foundation, Inc. 2 Copyright (C) 2003-2007, 2009-2020 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
@@ -29,7 +29,7 @@
29 such as DJGPP 2.03 and mingw32. */ 29 such as DJGPP 2.03 and mingw32. */
30 30
31ssize_t 31ssize_t
32readlink (const char *name, char *buf _GL_UNUSED, 32readlink (char const *file, char *buf _GL_UNUSED,
33 size_t bufsize _GL_UNUSED) 33 size_t bufsize _GL_UNUSED)
34{ 34{
35 struct stat statbuf; 35 struct stat statbuf;
@@ -37,7 +37,7 @@ readlink (const char *name, char *buf _GL_UNUSED,
37 /* In general we should use lstat() here, not stat(). But on platforms 37 /* In general we should use lstat() here, not stat(). But on platforms
38 without symbolic links, lstat() - if it exists - would be equivalent to 38 without symbolic links, lstat() - if it exists - would be equivalent to
39 stat(), therefore we can use stat(). This saves us a configure check. */ 39 stat(), therefore we can use stat(). This saves us a configure check. */
40 if (stat (name, &statbuf) >= 0) 40 if (stat (file, &statbuf) >= 0)
41 errno = EINVAL; 41 errno = EINVAL;
42 return -1; 42 return -1;
43} 43}
@@ -51,24 +51,54 @@ readlink (const char *name, char *buf _GL_UNUSED,
51 for Solaris 9. */ 51 for Solaris 9. */
52 52
53ssize_t 53ssize_t
54rpl_readlink (const char *name, char *buf, size_t bufsize) 54rpl_readlink (char const *file, char *buf, size_t bufsize)
55{ 55{
56# if READLINK_TRAILING_SLASH_BUG 56# if READLINK_TRAILING_SLASH_BUG
57 size_t len = strlen (name); 57 size_t file_len = strlen (file);
58 if (len && name[len - 1] == '/') 58 if (file_len && file[file_len - 1] == '/')
59 { 59 {
60 /* Even if name without the slash is a symlink to a directory, 60 /* Even if FILE without the slash is a symlink to a directory,
61 both lstat() and stat() must resolve the trailing slash to 61 both lstat() and stat() must resolve the trailing slash to
62 the directory rather than the symlink. We can therefore 62 the directory rather than the symlink. We can therefore
63 safely use stat() to distinguish between EINVAL and 63 safely use stat() to distinguish between EINVAL and
64 ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */ 64 ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */
65 struct stat st; 65 struct stat st;
66 if (stat (name, &st) == 0) 66 if (stat (file, &st) == 0 || errno == EOVERFLOW)
67 errno = EINVAL; 67 errno = EINVAL;
68 return -1; 68 return -1;
69 } 69 }
70# endif /* READLINK_TRAILING_SLASH_BUG */ 70# endif /* READLINK_TRAILING_SLASH_BUG */
71 return readlink (name, buf, bufsize); 71
72 ssize_t r = readlink (file, buf, bufsize);
73
74# if READLINK_TRUNCATE_BUG
75 if (r < 0 && errno == ERANGE)
76 {
77 /* Try again with a bigger buffer. This is just for test cases;
78 real code invariably discards short reads. */
79 char stackbuf[4032];
80 r = readlink (file, stackbuf, sizeof stackbuf);
81 if (r < 0)
82 {
83 if (errno == ERANGE)
84 {
85 /* Clear the buffer, which is good enough for real code.
86 Thankfully, no test cases try short reads of enormous
87 symlinks and what would be the point anyway? */
88 r = bufsize;
89 memset (buf, 0, r);
90 }
91 }
92 else
93 {
94 if (bufsize < r)
95 r = bufsize;
96 memcpy (buf, stackbuf, r);
97 }
98 }
99# endif
100
101 return r;
72} 102}
73 103
74#endif /* HAVE_READLINK */ 104#endif /* HAVE_READLINK */
diff --git a/lib/readlinkat.c b/lib/readlinkat.c
index 68ec65ebfc5..7a41208ebfd 100644
--- a/lib/readlinkat.c
+++ b/lib/readlinkat.c
@@ -28,10 +28,11 @@
28 28
29#if HAVE_READLINKAT 29#if HAVE_READLINKAT
30 30
31# undef fstatat
31# undef readlinkat 32# undef readlinkat
32 33
33ssize_t 34ssize_t
34rpl_readlinkat (int fd, char const *file, char *buf, size_t len) 35rpl_readlinkat (int fd, char const *file, char *buf, size_t bufsize)
35{ 36{
36# if READLINK_TRAILING_SLASH_BUG 37# if READLINK_TRAILING_SLASH_BUG
37 size_t file_len = strlen (file); 38 size_t file_len = strlen (file);
@@ -40,15 +41,45 @@ rpl_readlinkat (int fd, char const *file, char *buf, size_t len)
40 /* Even if FILE without the slash is a symlink to a directory, 41 /* Even if FILE without the slash is a symlink to a directory,
41 both lstat() and stat() must resolve the trailing slash to 42 both lstat() and stat() must resolve the trailing slash to
42 the directory rather than the symlink. We can therefore 43 the directory rather than the symlink. We can therefore
43 safely use stat() to distinguish between EINVAL and 44 safely use fstatat(..., 0) to distinguish between EINVAL and
44 ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */ 45 ENOTDIR/ENOENT, avoiding extra overhead of rpl_fstatat(). */
45 struct stat st; 46 struct stat st;
46 if (stat (file, &st) == 0) 47 if (fstatat (fd, file, &st, 0) == 0 || errno == EOVERFLOW)
47 errno = EINVAL; 48 errno = EINVAL;
48 return -1; 49 return -1;
49 } 50 }
50# endif /* READLINK_TRAILING_SLASH_BUG */ 51# endif /* READLINK_TRAILING_SLASH_BUG */
51 return readlinkat (fd, file, buf, len); 52
53 ssize_t r = readlinkat (fd, file, buf, bufsize);
54
55# if READLINK_TRUNCATE_BUG
56 if (r < 0 && errno == ERANGE)
57 {
58 /* Try again with a bigger buffer. This is just for test cases;
59 real code invariably discards short reads. */
60 char stackbuf[4032];
61 r = readlinkat (fd, file, stackbuf, sizeof stackbuf);
62 if (r < 0)
63 {
64 if (errno == ERANGE)
65 {
66 /* Clear the buffer, which is good enough for real code.
67 Thankfully, no test cases try short reads of enormous
68 symlinks and what would be the point anyway? */
69 r = bufsize;
70 memset (buf, 0, r);
71 }
72 }
73 else
74 {
75 if (bufsize < r)
76 r = bufsize;
77 memcpy (buf, stackbuf, r);
78 }
79 }
80# endif
81
82 return r;
52} 83}
53 84
54#else 85#else
@@ -61,7 +92,7 @@ rpl_readlinkat (int fd, char const *file, char *buf, size_t len)
61 readlinkat worthless since readlink does not guarantee a 92 readlinkat worthless since readlink does not guarantee a
62 NUL-terminated buffer. Assume this was a bug in POSIX. */ 93 NUL-terminated buffer. Assume this was a bug in POSIX. */
63 94
64/* Read the contents of symlink FILE into buffer BUF of size LEN, in the 95/* Read the contents of symlink FILE into buffer BUF of size BUFSIZE, in the
65 directory open on descriptor FD. If possible, do it without changing 96 directory open on descriptor FD. If possible, do it without changing
66 the working directory. Otherwise, resort to using save_cwd/fchdir, 97 the working directory. Otherwise, resort to using save_cwd/fchdir,
67 then readlink/restore_cwd. If either the save_cwd or the restore_cwd 98 then readlink/restore_cwd. If either the save_cwd or the restore_cwd
@@ -69,8 +100,8 @@ rpl_readlinkat (int fd, char const *file, char *buf, size_t len)
69 100
70# define AT_FUNC_NAME readlinkat 101# define AT_FUNC_NAME readlinkat
71# define AT_FUNC_F1 readlink 102# define AT_FUNC_F1 readlink
72# define AT_FUNC_POST_FILE_PARAM_DECLS , char *buf, size_t len 103# define AT_FUNC_POST_FILE_PARAM_DECLS , char *buf, size_t bufsize
73# define AT_FUNC_POST_FILE_ARGS , buf, len 104# define AT_FUNC_POST_FILE_ARGS , buf, bufsize
74# define AT_FUNC_RESULT ssize_t 105# define AT_FUNC_RESULT ssize_t
75# include "at-func.c" 106# include "at-func.c"
76# undef AT_FUNC_NAME 107# undef AT_FUNC_NAME
diff --git a/lib/regex_internal.c b/lib/regex_internal.c
index 2e217291468..bf9439e53fd 100644
--- a/lib/regex_internal.c
+++ b/lib/regex_internal.c
@@ -300,18 +300,20 @@ build_wcs_upper_buffer (re_string_t *pstr)
300 while (byte_idx < end_idx) 300 while (byte_idx < end_idx)
301 { 301 {
302 wchar_t wc; 302 wchar_t wc;
303 unsigned char ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
303 304
304 if (isascii (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]) 305 if (isascii (ch) && mbsinit (&pstr->cur_state))
305 && mbsinit (&pstr->cur_state))
306 { 306 {
307 /* In case of a singlebyte character. */
308 pstr->mbs[byte_idx]
309 = toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]);
310 /* The next step uses the assumption that wchar_t is encoded 307 /* The next step uses the assumption that wchar_t is encoded
311 ASCII-safe: all ASCII values can be converted like this. */ 308 ASCII-safe: all ASCII values can be converted like this. */
312 pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx]; 309 wchar_t wcu = __towupper (ch);
313 ++byte_idx; 310 if (isascii (wcu))
314 continue; 311 {
312 pstr->mbs[byte_idx] = wcu;
313 pstr->wcs[byte_idx] = wcu;
314 byte_idx++;
315 continue;
316 }
315 } 317 }
316 318
317 remain_len = end_idx - byte_idx; 319 remain_len = end_idx - byte_idx;
@@ -348,7 +350,6 @@ build_wcs_upper_buffer (re_string_t *pstr)
348 { 350 {
349 /* It is an invalid character, an incomplete character 351 /* It is an invalid character, an incomplete character
350 at the end of the string, or '\0'. Just use the byte. */ 352 at the end of the string, or '\0'. Just use the byte. */
351 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
352 pstr->mbs[byte_idx] = ch; 353 pstr->mbs[byte_idx] = ch;
353 /* And also cast it to wide char. */ 354 /* And also cast it to wide char. */
354 pstr->wcs[byte_idx++] = (wchar_t) ch; 355 pstr->wcs[byte_idx++] = (wchar_t) ch;
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 0c72e3f7b01..7b50b478114 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -77,6 +77,14 @@
77# define isblank(ch) ((ch) == ' ' || (ch) == '\t') 77# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
78#endif 78#endif
79 79
80/* regex code assumes isascii has its usual numeric meaning,
81 even if the portable character set uses EBCDIC encoding,
82 and even if wint_t is wider than int. */
83#ifndef _LIBC
84# undef isascii
85# define isascii(c) (((c) & ~0x7f) == 0)
86#endif
87
80#ifdef _LIBC 88#ifdef _LIBC
81# ifndef _RE_DEFINE_LOCALE_FUNCTIONS 89# ifndef _RE_DEFINE_LOCALE_FUNCTIONS
82# define _RE_DEFINE_LOCALE_FUNCTIONS 1 90# define _RE_DEFINE_LOCALE_FUNCTIONS 1
diff --git a/lib/scratch_buffer.h b/lib/scratch_buffer.h
new file mode 100644
index 00000000000..0b45f92c105
--- /dev/null
+++ b/lib/scratch_buffer.h
@@ -0,0 +1,29 @@
1/* Variable-sized buffer with on-stack default allocation.
2 Copyright (C) 2017-2020 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 <https://www.gnu.org/licenses/>. */
16
17/* Written by Paul Eggert, 2017. */
18
19#ifndef _GL_SCRATCH_BUFFER_H
20#define _GL_SCRATCH_BUFFER_H
21
22#include <libc-config.h>
23
24#define __libc_scratch_buffer_grow gl_scratch_buffer_grow
25#define __libc_scratch_buffer_grow_preserve gl_scratch_buffer_grow_preserve
26#define __libc_scratch_buffer_set_array_size gl_scratch_buffer_set_array_size
27#include <malloc/scratch_buffer.h>
28
29#endif /* _GL_SCRATCH_BUFFER_H */
diff --git a/lib/signal.in.h b/lib/signal.in.h
index c94b053d6af..70a2d4af6ca 100644
--- a/lib/signal.in.h
+++ b/lib/signal.in.h
@@ -55,13 +55,13 @@
55#ifndef _@GUARD_PREFIX@_SIGNAL_H 55#ifndef _@GUARD_PREFIX@_SIGNAL_H
56#define _@GUARD_PREFIX@_SIGNAL_H 56#define _@GUARD_PREFIX@_SIGNAL_H
57 57
58/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6, Android 58/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6, Android,
59 declare pthread_sigmask in <pthread.h>, not in <signal.h>. 59 OS/2 kLIBC declare pthread_sigmask in <pthread.h>, not in <signal.h>.
60 But avoid namespace pollution on glibc systems.*/ 60 But avoid namespace pollution on glibc systems.*/
61#if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \ 61#if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
62 && ((defined __APPLE__ && defined __MACH__) \ 62 && ((defined __APPLE__ && defined __MACH__) \
63 || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ \ 63 || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ \
64 || defined __sun || defined __ANDROID__) \ 64 || defined __sun || defined __ANDROID__ || defined __KLIBC__) \
65 && ! defined __GLIBC__ 65 && ! defined __GLIBC__
66# include <pthread.h> 66# include <pthread.h>
67#endif 67#endif
diff --git a/lib/stdint.in.h b/lib/stdint.in.h
index 63fa1aa628f..6f2235a750a 100644
--- a/lib/stdint.in.h
+++ b/lib/stdint.in.h
@@ -579,11 +579,6 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
579 <wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes 579 <wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes
580 <stdint.h> and assumes its types are already defined. */ 580 <stdint.h> and assumes its types are already defined. */
581# if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX) 581# if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX)
582 /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
583 included before <wchar.h>. */
584# include <stddef.h>
585# include <stdio.h>
586# include <time.h>
587# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H 582# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
588# include <wchar.h> 583# include <wchar.h>
589# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H 584# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h
index 067b95ebd64..15066aa59f8 100644
--- a/lib/stdio-impl.h
+++ b/lib/stdio-impl.h
@@ -175,7 +175,7 @@
175# define fp_ fp 175# define fp_ fp
176# endif 176# endif
177 177
178# if defined _SCO_DS /* OpenServer */ 178# if defined _SCO_DS || (defined __SCO_VERSION__ || defined __sysv5__) /* OpenServer 5, OpenServer 6, UnixWare 7 */
179# define _cnt __cnt 179# define _cnt __cnt
180# define _ptr __ptr 180# define _ptr __ptr
181# define _base __base 181# define _base __base
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 6d12cd826de..458036b3441 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -70,30 +70,44 @@
70# endif 70# endif
71#endif 71#endif
72 72
73/* _GL_ATTRIBUTE_FORMAT_PRINTF 73/* An __attribute__ __format__ specifier for a function that takes a format
74 indicates to GCC that the function takes a format string and arguments, 74 string and arguments, where the format string directives are the ones
75 where the format string directives are the ones standardized by ISO C99 75 standardized by ISO C99 and POSIX.
76 and POSIX. */ 76 _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD */
77/* __gnu_printf__ is supported in GCC >= 4.4. */
77#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) 78#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
78# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ 79# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __gnu_printf__
79 _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument))
80#else 80#else
81# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ 81# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __printf__
82 _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
83#endif 82#endif
84 83
85/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF, 84/* An __attribute__ __format__ specifier for a function that takes a format
86 except that it indicates to GCC that the supported format string directives 85 string and arguments, where the format string directives are the ones of the
87 are the ones of the system printf(), rather than the ones standardized by 86 system printf(), rather than the ones standardized by ISO C99 and POSIX.
88 ISO C99 and POSIX. */ 87 _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM */
88/* On mingw, Gnulib sets __USE_MINGW_ANSI_STDIO in order to get closer to
89 the standards. The macro GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU indicates
90 whether this change is effective. On older mingw, it is not. */
89#if GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU 91#if GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU
90# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ 92# define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD
91 _GL_ATTRIBUTE_FORMAT_PRINTF (formatstring_parameter, first_argument)
92#else 93#else
93# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ 94# define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM __printf__
94 _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
95#endif 95#endif
96 96
97/* _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD
98 indicates to GCC that the function takes a format string and arguments,
99 where the format string directives are the ones standardized by ISO C99
100 and POSIX. */
101#define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(formatstring_parameter, first_argument) \
102 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, formatstring_parameter, first_argument))
103
104/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD,
105 except that it indicates to GCC that the supported format string directives
106 are the ones of the system printf(), rather than the ones standardized by
107 ISO C99 and POSIX. */
108#define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \
109 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, formatstring_parameter, first_argument))
110
97/* _GL_ATTRIBUTE_FORMAT_SCANF 111/* _GL_ATTRIBUTE_FORMAT_SCANF
98 indicates to GCC that the function takes a format string and arguments, 112 indicates to GCC that the function takes a format string and arguments,
99 where the format string directives are the ones standardized by ISO C99 113 where the format string directives are the ones standardized by ISO C99
@@ -174,13 +188,13 @@
174# define dprintf rpl_dprintf 188# define dprintf rpl_dprintf
175# endif 189# endif
176_GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *restrict format, ...) 190_GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *restrict format, ...)
177 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 191 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
178 _GL_ARG_NONNULL ((2))); 192 _GL_ARG_NONNULL ((2)));
179_GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *restrict format, ...)); 193_GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *restrict format, ...));
180# else 194# else
181# if !@HAVE_DPRINTF@ 195# if !@HAVE_DPRINTF@
182_GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *restrict format, ...) 196_GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *restrict format, ...)
183 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 197 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
184 _GL_ARG_NONNULL ((2))); 198 _GL_ARG_NONNULL ((2)));
185# endif 199# endif
186_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *restrict format, ...)); 200_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *restrict format, ...));
@@ -215,9 +229,27 @@ _GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - "
215 "use gnulib module fclose for portable POSIX compliance"); 229 "use gnulib module fclose for portable POSIX compliance");
216#endif 230#endif
217 231
232/* On native Windows, map 'fcloseall' to '_fcloseall', so that -loldnames is
233 not required. In C++ with GNULIB_NAMESPACE, avoid differences between
234 platforms by defining GNULIB_NAMESPACE::fcloseall on all platforms that have
235 it. */
218#if defined _WIN32 && !defined __CYGWIN__ 236#if defined _WIN32 && !defined __CYGWIN__
219# undef fcloseall 237# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
220# define fcloseall _fcloseall 238# undef fcloseall
239# define fcloseall _fcloseall
240# endif
241_GL_CXXALIAS_MDA (fcloseall, int, (void));
242#else
243# if @HAVE_DECL_FCLOSEALL@
244# if defined __FreeBSD__
245_GL_CXXALIAS_SYS (fcloseall, void, (void));
246# else
247_GL_CXXALIAS_SYS (fcloseall, int, (void));
248# endif
249# endif
250#endif
251#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_FCLOSEALL@
252_GL_CXXALIASWARN (fcloseall);
221#endif 253#endif
222 254
223#if @GNULIB_FDOPEN@ 255#if @GNULIB_FDOPEN@
@@ -244,9 +276,20 @@ _GL_CXXALIASWARN (fdopen);
244/* Assume fdopen is always declared. */ 276/* Assume fdopen is always declared. */
245_GL_WARN_ON_USE (fdopen, "fdopen on native Windows platforms is not POSIX compliant - " 277_GL_WARN_ON_USE (fdopen, "fdopen on native Windows platforms is not POSIX compliant - "
246 "use gnulib module fdopen for portability"); 278 "use gnulib module fdopen for portability");
247#elif defined _WIN32 && !defined __CYGWIN__ 279#else
248# undef fdopen 280/* On native Windows, map 'fdopen' to '_fdopen', so that -loldnames is not
249# define fdopen _fdopen 281 required. In C++ with GNULIB_NAMESPACE, avoid differences between
282 platforms by defining GNULIB_NAMESPACE::fdopen always. */
283# if defined _WIN32 && !defined __CYGWIN__
284# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
285# undef fdopen
286# define fdopen _fdopen
287# endif
288_GL_CXXALIAS_MDA (fdopen, FILE *, (int fd, const char *mode));
289# else
290_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode));
291# endif
292_GL_CXXALIASWARN (fdopen);
250#endif 293#endif
251 294
252#if @GNULIB_FFLUSH@ 295#if @GNULIB_FFLUSH@
@@ -311,10 +354,19 @@ _GL_CXXALIASWARN (fgets);
311# endif 354# endif
312#endif 355#endif
313 356
357/* On native Windows, map 'fileno' to '_fileno', so that -loldnames is not
358 required. In C++ with GNULIB_NAMESPACE, avoid differences between
359 platforms by defining GNULIB_NAMESPACE::fileno always. */
314#if defined _WIN32 && !defined __CYGWIN__ 360#if defined _WIN32 && !defined __CYGWIN__
315# undef fileno 361# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
316# define fileno _fileno 362# undef fileno
363# define fileno _fileno
364# endif
365_GL_CXXALIAS_MDA (fileno, int, (FILE *restrict stream));
366#else
367_GL_CXXALIAS_SYS (fileno, int, (FILE *restrict stream));
317#endif 368#endif
369_GL_CXXALIASWARN (fileno);
318 370
319#if @GNULIB_FOPEN@ 371#if @GNULIB_FOPEN@
320# if @REPLACE_FOPEN@ 372# if @REPLACE_FOPEN@
@@ -351,7 +403,7 @@ _GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX complian
351# if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ 403# if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
352_GL_FUNCDECL_RPL (fprintf, int, 404_GL_FUNCDECL_RPL (fprintf, int,
353 (FILE *restrict fp, const char *restrict format, ...) 405 (FILE *restrict fp, const char *restrict format, ...)
354 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 406 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
355 _GL_ARG_NONNULL ((1, 2))); 407 _GL_ARG_NONNULL ((1, 2)));
356# else 408# else
357_GL_FUNCDECL_RPL (fprintf, int, 409_GL_FUNCDECL_RPL (fprintf, int,
@@ -843,10 +895,19 @@ _GL_WARN_ON_USE (getline, "getline is unportable - "
843_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); 895_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
844#endif 896#endif
845 897
898/* On native Windows, map 'getw' to '_getw', so that -loldnames is not
899 required. In C++ with GNULIB_NAMESPACE, avoid differences between
900 platforms by defining GNULIB_NAMESPACE::getw always. */
846#if defined _WIN32 && !defined __CYGWIN__ 901#if defined _WIN32 && !defined __CYGWIN__
847# undef getw 902# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
848# define getw _getw 903# undef getw
904# define getw _getw
905# endif
906_GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream));
907#else
908_GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream));
849#endif 909#endif
910_GL_CXXALIASWARN (getw);
850 911
851#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ 912#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
852struct obstack; 913struct obstack;
@@ -861,7 +922,7 @@ struct obstack;
861# endif 922# endif
862_GL_FUNCDECL_RPL (obstack_printf, int, 923_GL_FUNCDECL_RPL (obstack_printf, int,
863 (struct obstack *obs, const char *format, ...) 924 (struct obstack *obs, const char *format, ...)
864 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 925 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
865 _GL_ARG_NONNULL ((1, 2))); 926 _GL_ARG_NONNULL ((1, 2)));
866_GL_CXXALIAS_RPL (obstack_printf, int, 927_GL_CXXALIAS_RPL (obstack_printf, int,
867 (struct obstack *obs, const char *format, ...)); 928 (struct obstack *obs, const char *format, ...));
@@ -869,7 +930,7 @@ _GL_CXXALIAS_RPL (obstack_printf, int,
869# if !@HAVE_DECL_OBSTACK_PRINTF@ 930# if !@HAVE_DECL_OBSTACK_PRINTF@
870_GL_FUNCDECL_SYS (obstack_printf, int, 931_GL_FUNCDECL_SYS (obstack_printf, int,
871 (struct obstack *obs, const char *format, ...) 932 (struct obstack *obs, const char *format, ...)
872 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 933 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
873 _GL_ARG_NONNULL ((1, 2))); 934 _GL_ARG_NONNULL ((1, 2)));
874# endif 935# endif
875_GL_CXXALIAS_SYS (obstack_printf, int, 936_GL_CXXALIAS_SYS (obstack_printf, int,
@@ -882,7 +943,7 @@ _GL_CXXALIASWARN (obstack_printf);
882# endif 943# endif
883_GL_FUNCDECL_RPL (obstack_vprintf, int, 944_GL_FUNCDECL_RPL (obstack_vprintf, int,
884 (struct obstack *obs, const char *format, va_list args) 945 (struct obstack *obs, const char *format, va_list args)
885 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 946 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
886 _GL_ARG_NONNULL ((1, 2))); 947 _GL_ARG_NONNULL ((1, 2)));
887_GL_CXXALIAS_RPL (obstack_vprintf, int, 948_GL_CXXALIAS_RPL (obstack_vprintf, int,
888 (struct obstack *obs, const char *format, va_list args)); 949 (struct obstack *obs, const char *format, va_list args));
@@ -890,7 +951,7 @@ _GL_CXXALIAS_RPL (obstack_vprintf, int,
890# if !@HAVE_DECL_OBSTACK_PRINTF@ 951# if !@HAVE_DECL_OBSTACK_PRINTF@
891_GL_FUNCDECL_SYS (obstack_vprintf, int, 952_GL_FUNCDECL_SYS (obstack_vprintf, int,
892 (struct obstack *obs, const char *format, va_list args) 953 (struct obstack *obs, const char *format, va_list args)
893 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 954 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
894 _GL_ARG_NONNULL ((1, 2))); 955 _GL_ARG_NONNULL ((1, 2)));
895# endif 956# endif
896_GL_CXXALIAS_SYS (obstack_vprintf, int, 957_GL_CXXALIAS_SYS (obstack_vprintf, int,
@@ -974,7 +1035,7 @@ _GL_FUNCDECL_RPL_1 (__printf__, int,
974 (const char *restrict format, ...) 1035 (const char *restrict format, ...)
975 __asm__ (@ASM_SYMBOL_PREFIX@ 1036 __asm__ (@ASM_SYMBOL_PREFIX@
976 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) 1037 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
977 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) 1038 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
978 _GL_ARG_NONNULL ((1))); 1039 _GL_ARG_NONNULL ((1)));
979# else 1040# else
980_GL_FUNCDECL_RPL_1 (__printf__, int, 1041_GL_FUNCDECL_RPL_1 (__printf__, int,
@@ -991,7 +1052,7 @@ _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
991# endif 1052# endif
992_GL_FUNCDECL_RPL (printf, int, 1053_GL_FUNCDECL_RPL (printf, int,
993 (const char *restrict format, ...) 1054 (const char *restrict format, ...)
994 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) 1055 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
995 _GL_ARG_NONNULL ((1))); 1056 _GL_ARG_NONNULL ((1)));
996_GL_CXXALIAS_RPL (printf, int, (const char *restrict format, ...)); 1057_GL_CXXALIAS_RPL (printf, int, (const char *restrict format, ...));
997# endif 1058# endif
@@ -1061,10 +1122,19 @@ _GL_CXXALIASWARN (puts);
1061# endif 1122# endif
1062#endif 1123#endif
1063 1124
1125/* On native Windows, map 'putw' to '_putw', so that -loldnames is not
1126 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1127 platforms by defining GNULIB_NAMESPACE::putw always. */
1064#if defined _WIN32 && !defined __CYGWIN__ 1128#if defined _WIN32 && !defined __CYGWIN__
1065# undef putw 1129# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1066# define putw _putw 1130# undef putw
1131# define putw _putw
1132# endif
1133_GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream));
1134#else
1135_GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream));
1067#endif 1136#endif
1137_GL_CXXALIASWARN (putw);
1068 1138
1069#if @GNULIB_REMOVE@ 1139#if @GNULIB_REMOVE@
1070# if @REPLACE_REMOVE@ 1140# if @REPLACE_REMOVE@
@@ -1182,7 +1252,7 @@ _GL_CXXALIASWARN (scanf);
1182_GL_FUNCDECL_RPL (snprintf, int, 1252_GL_FUNCDECL_RPL (snprintf, int,
1183 (char *restrict str, size_t size, 1253 (char *restrict str, size_t size,
1184 const char *restrict format, ...) 1254 const char *restrict format, ...)
1185 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) 1255 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4)
1186 _GL_ARG_NONNULL ((3))); 1256 _GL_ARG_NONNULL ((3)));
1187_GL_CXXALIAS_RPL (snprintf, int, 1257_GL_CXXALIAS_RPL (snprintf, int,
1188 (char *restrict str, size_t size, 1258 (char *restrict str, size_t size,
@@ -1192,7 +1262,7 @@ _GL_CXXALIAS_RPL (snprintf, int,
1192_GL_FUNCDECL_SYS (snprintf, int, 1262_GL_FUNCDECL_SYS (snprintf, int,
1193 (char *restrict str, size_t size, 1263 (char *restrict str, size_t size,
1194 const char *restrict format, ...) 1264 const char *restrict format, ...)
1195 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) 1265 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4)
1196 _GL_ARG_NONNULL ((3))); 1266 _GL_ARG_NONNULL ((3)));
1197# endif 1267# endif
1198_GL_CXXALIAS_SYS (snprintf, int, 1268_GL_CXXALIAS_SYS (snprintf, int,
@@ -1226,7 +1296,7 @@ _GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
1226# endif 1296# endif
1227_GL_FUNCDECL_RPL (sprintf, int, 1297_GL_FUNCDECL_RPL (sprintf, int,
1228 (char *restrict str, const char *restrict format, ...) 1298 (char *restrict str, const char *restrict format, ...)
1229 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 1299 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1230 _GL_ARG_NONNULL ((1, 2))); 1300 _GL_ARG_NONNULL ((1, 2)));
1231_GL_CXXALIAS_RPL (sprintf, int, 1301_GL_CXXALIAS_RPL (sprintf, int,
1232 (char *restrict str, const char *restrict format, ...)); 1302 (char *restrict str, const char *restrict format, ...));
@@ -1245,10 +1315,19 @@ _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
1245 "POSIX compliance"); 1315 "POSIX compliance");
1246#endif 1316#endif
1247 1317
1318/* On native Windows, map 'tempnam' to '_tempnam', so that -loldnames is not
1319 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1320 platforms by defining GNULIB_NAMESPACE::tempnam always. */
1248#if defined _WIN32 && !defined __CYGWIN__ 1321#if defined _WIN32 && !defined __CYGWIN__
1249# undef tempnam 1322# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1250# define tempnam _tempnam 1323# undef tempnam
1324# define tempnam _tempnam
1325# endif
1326_GL_CXXALIAS_MDA (tempnam, char *, (const char *dir, const char *prefix));
1327#else
1328_GL_CXXALIAS_SYS (tempnam, char *, (const char *dir, const char *prefix));
1251#endif 1329#endif
1330_GL_CXXALIASWARN (tempnam);
1252 1331
1253#if @GNULIB_TMPFILE@ 1332#if @GNULIB_TMPFILE@
1254# if @REPLACE_TMPFILE@ 1333# if @REPLACE_TMPFILE@
@@ -1282,7 +1361,7 @@ _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
1282# endif 1361# endif
1283_GL_FUNCDECL_RPL (asprintf, int, 1362_GL_FUNCDECL_RPL (asprintf, int,
1284 (char **result, const char *format, ...) 1363 (char **result, const char *format, ...)
1285 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 1364 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1286 _GL_ARG_NONNULL ((1, 2))); 1365 _GL_ARG_NONNULL ((1, 2)));
1287_GL_CXXALIAS_RPL (asprintf, int, 1366_GL_CXXALIAS_RPL (asprintf, int,
1288 (char **result, const char *format, ...)); 1367 (char **result, const char *format, ...));
@@ -1290,7 +1369,7 @@ _GL_CXXALIAS_RPL (asprintf, int,
1290# if !@HAVE_VASPRINTF@ 1369# if !@HAVE_VASPRINTF@
1291_GL_FUNCDECL_SYS (asprintf, int, 1370_GL_FUNCDECL_SYS (asprintf, int,
1292 (char **result, const char *format, ...) 1371 (char **result, const char *format, ...)
1293 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 1372 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1294 _GL_ARG_NONNULL ((1, 2))); 1373 _GL_ARG_NONNULL ((1, 2)));
1295# endif 1374# endif
1296_GL_CXXALIAS_SYS (asprintf, int, 1375_GL_CXXALIAS_SYS (asprintf, int,
@@ -1303,7 +1382,7 @@ _GL_CXXALIASWARN (asprintf);
1303# endif 1382# endif
1304_GL_FUNCDECL_RPL (vasprintf, int, 1383_GL_FUNCDECL_RPL (vasprintf, int,
1305 (char **result, const char *format, va_list args) 1384 (char **result, const char *format, va_list args)
1306 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1385 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1307 _GL_ARG_NONNULL ((1, 2))); 1386 _GL_ARG_NONNULL ((1, 2)));
1308_GL_CXXALIAS_RPL (vasprintf, int, 1387_GL_CXXALIAS_RPL (vasprintf, int,
1309 (char **result, const char *format, va_list args)); 1388 (char **result, const char *format, va_list args));
@@ -1311,7 +1390,7 @@ _GL_CXXALIAS_RPL (vasprintf, int,
1311# if !@HAVE_VASPRINTF@ 1390# if !@HAVE_VASPRINTF@
1312_GL_FUNCDECL_SYS (vasprintf, int, 1391_GL_FUNCDECL_SYS (vasprintf, int,
1313 (char **result, const char *format, va_list args) 1392 (char **result, const char *format, va_list args)
1314 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1393 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1315 _GL_ARG_NONNULL ((1, 2))); 1394 _GL_ARG_NONNULL ((1, 2)));
1316# endif 1395# endif
1317_GL_CXXALIAS_SYS (vasprintf, int, 1396_GL_CXXALIAS_SYS (vasprintf, int,
@@ -1327,7 +1406,7 @@ _GL_CXXALIASWARN (vasprintf);
1327# endif 1406# endif
1328_GL_FUNCDECL_RPL (vdprintf, int, 1407_GL_FUNCDECL_RPL (vdprintf, int,
1329 (int fd, const char *restrict format, va_list args) 1408 (int fd, const char *restrict format, va_list args)
1330 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1409 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1331 _GL_ARG_NONNULL ((2))); 1410 _GL_ARG_NONNULL ((2)));
1332_GL_CXXALIAS_RPL (vdprintf, int, 1411_GL_CXXALIAS_RPL (vdprintf, int,
1333 (int fd, const char *restrict format, va_list args)); 1412 (int fd, const char *restrict format, va_list args));
@@ -1335,7 +1414,7 @@ _GL_CXXALIAS_RPL (vdprintf, int,
1335# if !@HAVE_VDPRINTF@ 1414# if !@HAVE_VDPRINTF@
1336_GL_FUNCDECL_SYS (vdprintf, int, 1415_GL_FUNCDECL_SYS (vdprintf, int,
1337 (int fd, const char *restrict format, va_list args) 1416 (int fd, const char *restrict format, va_list args)
1338 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1417 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1339 _GL_ARG_NONNULL ((2))); 1418 _GL_ARG_NONNULL ((2)));
1340# endif 1419# endif
1341/* Need to cast, because on Solaris, the third parameter will likely be 1420/* Need to cast, because on Solaris, the third parameter will likely be
@@ -1365,7 +1444,7 @@ _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
1365_GL_FUNCDECL_RPL (vfprintf, int, 1444_GL_FUNCDECL_RPL (vfprintf, int,
1366 (FILE *restrict fp, 1445 (FILE *restrict fp,
1367 const char *restrict format, va_list args) 1446 const char *restrict format, va_list args)
1368 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1447 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1369 _GL_ARG_NONNULL ((1, 2))); 1448 _GL_ARG_NONNULL ((1, 2)));
1370# else 1449# else
1371_GL_FUNCDECL_RPL (vfprintf, int, 1450_GL_FUNCDECL_RPL (vfprintf, int,
@@ -1432,7 +1511,7 @@ _GL_CXXALIASWARN (vfscanf);
1432# define GNULIB_overrides_vprintf 1 1511# define GNULIB_overrides_vprintf 1
1433# if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ 1512# if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
1434_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args) 1513_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args)
1435 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 0) 1514 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 0)
1436 _GL_ARG_NONNULL ((1))); 1515 _GL_ARG_NONNULL ((1)));
1437# else 1516# else
1438_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args) 1517_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args)
@@ -1487,7 +1566,7 @@ _GL_CXXALIASWARN (vscanf);
1487_GL_FUNCDECL_RPL (vsnprintf, int, 1566_GL_FUNCDECL_RPL (vsnprintf, int,
1488 (char *restrict str, size_t size, 1567 (char *restrict str, size_t size,
1489 const char *restrict format, va_list args) 1568 const char *restrict format, va_list args)
1490 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) 1569 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0)
1491 _GL_ARG_NONNULL ((3))); 1570 _GL_ARG_NONNULL ((3)));
1492_GL_CXXALIAS_RPL (vsnprintf, int, 1571_GL_CXXALIAS_RPL (vsnprintf, int,
1493 (char *restrict str, size_t size, 1572 (char *restrict str, size_t size,
@@ -1497,7 +1576,7 @@ _GL_CXXALIAS_RPL (vsnprintf, int,
1497_GL_FUNCDECL_SYS (vsnprintf, int, 1576_GL_FUNCDECL_SYS (vsnprintf, int,
1498 (char *restrict str, size_t size, 1577 (char *restrict str, size_t size,
1499 const char *restrict format, va_list args) 1578 const char *restrict format, va_list args)
1500 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) 1579 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0)
1501 _GL_ARG_NONNULL ((3))); 1580 _GL_ARG_NONNULL ((3)));
1502# endif 1581# endif
1503_GL_CXXALIAS_SYS (vsnprintf, int, 1582_GL_CXXALIAS_SYS (vsnprintf, int,
@@ -1523,7 +1602,7 @@ _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
1523_GL_FUNCDECL_RPL (vsprintf, int, 1602_GL_FUNCDECL_RPL (vsprintf, int,
1524 (char *restrict str, 1603 (char *restrict str,
1525 const char *restrict format, va_list args) 1604 const char *restrict format, va_list args)
1526 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1605 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1527 _GL_ARG_NONNULL ((1, 2))); 1606 _GL_ARG_NONNULL ((1, 2)));
1528_GL_CXXALIAS_RPL (vsprintf, int, 1607_GL_CXXALIAS_RPL (vsprintf, int,
1529 (char *restrict str, 1608 (char *restrict str,
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 47a1309e633..1964443a22f 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -53,8 +53,8 @@
53# include <sys/loadavg.h> 53# include <sys/loadavg.h>
54#endif 54#endif
55 55
56/* Native Windows platforms declare mktemp() in <io.h>. */ 56/* Native Windows platforms declare _mktemp() in <io.h>. */
57#if 0 && (defined _WIN32 && ! defined __CYGWIN__) 57#if defined _WIN32 && !defined __CYGWIN__
58# include <io.h> 58# include <io.h>
59#endif 59#endif
60 60
@@ -149,6 +149,31 @@ _GL_WARN_ON_USE (_Exit, "_Exit is unportable - "
149#endif 149#endif
150 150
151 151
152/* Allocate memory with indefinite extent and specified alignment. */
153#if @GNULIB_ALIGNED_ALLOC@
154# if @REPLACE_ALIGNED_ALLOC@
155# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
156# undef aligned_alloc
157# define aligned_alloc rpl_aligned_alloc
158# endif
159_GL_FUNCDECL_RPL (aligned_alloc, void *, (size_t alignment, size_t size));
160_GL_CXXALIAS_RPL (aligned_alloc, void *, (size_t alignment, size_t size));
161# else
162# if @HAVE_ALIGNED_ALLOC@
163_GL_CXXALIAS_SYS (aligned_alloc, void *, (size_t alignment, size_t size));
164# endif
165# endif
166# if @HAVE_ALIGNED_ALLOC@
167_GL_CXXALIASWARN (aligned_alloc);
168# endif
169#elif defined GNULIB_POSIXCHECK
170# undef aligned_alloc
171# if HAVE_RAW_DECL_ALIGNED_ALLOC
172_GL_WARN_ON_USE (aligned_alloc, "aligned_alloc is not portable - "
173 "use gnulib module aligned_alloc for portability");
174# endif
175#endif
176
152#if @GNULIB_ATOLL@ 177#if @GNULIB_ATOLL@
153/* Parse a signed decimal integer. 178/* Parse a signed decimal integer.
154 Returns the value of the integer. Errors are not detected. */ 179 Returns the value of the integer. Errors are not detected. */
@@ -217,19 +242,86 @@ _GL_WARN_ON_USE (canonicalize_file_name,
217# endif 242# endif
218#endif 243#endif
219 244
245/* On native Windows, map 'ecvt' to '_ecvt', so that -loldnames is not
246 required. In C++ with GNULIB_NAMESPACE, avoid differences between
247 platforms by defining GNULIB_NAMESPACE::ecvt on all platforms that have
248 it. */
220#if defined _WIN32 && !defined __CYGWIN__ 249#if defined _WIN32 && !defined __CYGWIN__
221# undef ecvt 250# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
222# define ecvt _ecvt 251# undef ecvt
252# define ecvt _ecvt
253# endif
254_GL_CXXALIAS_MDA (ecvt, char *,
255 (double number, int ndigits, int *decptp, int *signp));
256#else
257# if @HAVE_DECL_ECVT@
258_GL_CXXALIAS_SYS (ecvt, char *,
259 (double number, int ndigits, int *decptp, int *signp));
260# endif
261#endif
262#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_ECVT@
263_GL_CXXALIASWARN (ecvt);
223#endif 264#endif
224 265
266/* On native Windows, map 'fcvt' to '_fcvt', so that -loldnames is not
267 required. In C++ with GNULIB_NAMESPACE, avoid differences between
268 platforms by defining GNULIB_NAMESPACE::fcvt on all platforms that have
269 it. */
225#if defined _WIN32 && !defined __CYGWIN__ 270#if defined _WIN32 && !defined __CYGWIN__
226# undef fcvt 271# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
227# define fcvt _fcvt 272# undef fcvt
273# define fcvt _fcvt
274# endif
275_GL_CXXALIAS_MDA (fcvt, char *,
276 (double number, int ndigits, int *decptp, int *signp));
277#else
278# if @HAVE_DECL_FCVT@
279_GL_CXXALIAS_SYS (fcvt, char *,
280 (double number, int ndigits, int *decptp, int *signp));
281# endif
282#endif
283#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_FCVT@
284_GL_CXXALIASWARN (fcvt);
285#endif
286
287#if @GNULIB_FREE_POSIX@
288# if @REPLACE_FREE@
289# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
290# undef free
291# define free rpl_free
292# endif
293_GL_FUNCDECL_RPL (free, void, (void *ptr));
294_GL_CXXALIAS_RPL (free, void, (void *ptr));
295# else
296_GL_CXXALIAS_SYS (free, void, (void *ptr));
297# endif
298# if __GLIBC__ >= 2
299_GL_CXXALIASWARN (free);
300# endif
301#elif defined GNULIB_POSIXCHECK
302# undef free
303/* Assume free is always declared. */
304_GL_WARN_ON_USE (free, "free is not future POSIX compliant everywhere - "
305 "use gnulib module free for portability");
228#endif 306#endif
229 307
308/* On native Windows, map 'gcvt' to '_gcvt', so that -loldnames is not
309 required. In C++ with GNULIB_NAMESPACE, avoid differences between
310 platforms by defining GNULIB_NAMESPACE::gcvt on all platforms that have
311 it. */
230#if defined _WIN32 && !defined __CYGWIN__ 312#if defined _WIN32 && !defined __CYGWIN__
231# undef gcvt 313# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
232# define gcvt _gcvt 314# undef gcvt
315# define gcvt _gcvt
316# endif
317_GL_CXXALIAS_MDA (gcvt, char *, (double number, int ndigits, char *buf));
318#else
319# if @HAVE_DECL_GCVT@
320_GL_CXXALIAS_SYS (gcvt, char *, (double number, int ndigits, char *buf));
321# endif
322#endif
323#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_GCVT@
324_GL_CXXALIASWARN (gcvt);
233#endif 325#endif
234 326
235#if @GNULIB_GETLOADAVG@ 327#if @GNULIB_GETLOADAVG@
@@ -483,9 +575,47 @@ _GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - "
483# endif 575# endif
484#endif 576#endif
485 577
578/* On native Windows, map 'mktemp' to '_mktemp', so that -loldnames is not
579 required. In C++ with GNULIB_NAMESPACE, avoid differences between
580 platforms by defining GNULIB_NAMESPACE::mktemp always. */
486#if defined _WIN32 && !defined __CYGWIN__ 581#if defined _WIN32 && !defined __CYGWIN__
487# undef mktemp 582# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
488# define mktemp _mktemp 583# undef mktemp
584# define mktemp _mktemp
585# endif
586_GL_CXXALIAS_MDA (mktemp, char *, (char * /*template*/));
587#else
588_GL_CXXALIAS_SYS (mktemp, char *, (char * /*template*/));
589#endif
590_GL_CXXALIASWARN (mktemp);
591
592/* Allocate memory with indefinite extent and specified alignment. */
593#if @GNULIB_POSIX_MEMALIGN@
594# if @REPLACE_POSIX_MEMALIGN@
595# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
596# undef posix_memalign
597# define posix_memalign rpl_posix_memalign
598# endif
599_GL_FUNCDECL_RPL (posix_memalign, int,
600 (void **memptr, size_t alignment, size_t size)
601 _GL_ARG_NONNULL ((1)));
602_GL_CXXALIAS_RPL (posix_memalign, int,
603 (void **memptr, size_t alignment, size_t size));
604# else
605# if @HAVE_POSIX_MEMALIGN@
606_GL_CXXALIAS_SYS (posix_memalign, int,
607 (void **memptr, size_t alignment, size_t size));
608# endif
609# endif
610# if @HAVE_POSIX_MEMALIGN@
611_GL_CXXALIASWARN (posix_memalign);
612# endif
613#elif defined GNULIB_POSIXCHECK
614# undef posix_memalign
615# if HAVE_RAW_DECL_POSIX_MEMALIGN
616_GL_WARN_ON_USE (posix_memalign, "posix_memalign is not portable - "
617 "use gnulib module posix_memalign for portability");
618# endif
489#endif 619#endif
490 620
491#if @GNULIB_POSIX_OPENPT@ 621#if @GNULIB_POSIX_OPENPT@
@@ -576,9 +706,22 @@ _GL_CXXALIAS_MDA (putenv, int, (char *string));
576_GL_CXXALIAS_SYS (putenv, int, (char *string)); 706_GL_CXXALIAS_SYS (putenv, int, (char *string));
577# endif 707# endif
578_GL_CXXALIASWARN (putenv); 708_GL_CXXALIASWARN (putenv);
579#elif defined _WIN32 && !defined __CYGWIN__ 709#else
580# undef putenv 710/* On native Windows, map 'putenv' to '_putenv', so that -loldnames is not
581# define putenv _putenv 711 required. In C++ with GNULIB_NAMESPACE, avoid differences between
712 platforms by defining GNULIB_NAMESPACE::putenv always. */
713# if defined _WIN32 && !defined __CYGWIN__
714# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
715# undef putenv
716# define putenv _putenv
717# endif
718/* Need to cast, because on mingw, the parameter is either
719 'const char *string' or 'char *string'. */
720_GL_CXXALIAS_MDA_CAST (putenv, int, (char *string));
721# else
722_GL_CXXALIAS_SYS (putenv, int, (char *string));
723# endif
724_GL_CXXALIASWARN (putenv);
582#endif 725#endif
583 726
584#if @GNULIB_QSORT_R@ 727#if @GNULIB_QSORT_R@
diff --git a/lib/string.in.h b/lib/string.in.h
index 9724addef43..f34bfabfb99 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -123,16 +123,28 @@ _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
123#endif 123#endif
124 124
125 125
126/* On native Windows, map 'memccpy' to '_memccpy', so that -loldnames is not
127 required. In C++ with GNULIB_NAMESPACE, avoid differences between
128 platforms by defining GNULIB_NAMESPACE::memccpy always. */
126#if defined _WIN32 && !defined __CYGWIN__ 129#if defined _WIN32 && !defined __CYGWIN__
127# undef memccpy 130# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
128# define memccpy _memccpy 131# undef memccpy
132# define memccpy _memccpy
133# endif
134_GL_CXXALIAS_MDA (memccpy, void *,
135 (void *dest, const void *src, int c, size_t n));
136#else
137_GL_CXXALIAS_SYS (memccpy, void *,
138 (void *dest, const void *src, int c, size_t n));
129#endif 139#endif
140_GL_CXXALIASWARN (memccpy);
130 141
131 142
132/* Return the first instance of C within N bytes of S, or NULL. */ 143/* Return the first instance of C within N bytes of S, or NULL. */
133#if @GNULIB_MEMCHR@ 144#if @GNULIB_MEMCHR@
134# if @REPLACE_MEMCHR@ 145# if @REPLACE_MEMCHR@
135# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 146# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
147# undef memchr
136# define memchr rpl_memchr 148# define memchr rpl_memchr
137# endif 149# endif
138_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) 150_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
@@ -413,9 +425,23 @@ _GL_CXXALIASWARN (strdup);
413_GL_WARN_ON_USE (strdup, "strdup is unportable - " 425_GL_WARN_ON_USE (strdup, "strdup is unportable - "
414 "use gnulib module strdup for portability"); 426 "use gnulib module strdup for portability");
415# endif 427# endif
416#elif defined _WIN32 && !defined __CYGWIN__ 428#else
417# undef strdup 429/* On native Windows, map 'creat' to '_creat', so that -loldnames is not
418# define strdup _strdup 430 required. In C++ with GNULIB_NAMESPACE, avoid differences between
431 platforms by defining GNULIB_NAMESPACE::creat always. */
432# if defined _WIN32 && !defined __CYGWIN__
433# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
434# undef strdup
435# define strdup _strdup
436# endif
437_GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
438# else
439# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
440# undef strdup
441# endif
442_GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
443# endif
444_GL_CXXALIASWARN (strdup);
419#endif 445#endif
420 446
421/* Append no more than N characters from SRC onto DEST. */ 447/* Append no more than N characters from SRC onto DEST. */
diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h
index 72cb9ba7b0f..ac1e93919b7 100644
--- a/lib/sys_select.in.h
+++ b/lib/sys_select.in.h
@@ -103,9 +103,16 @@
103/* Get definition of 'sigset_t'. 103/* Get definition of 'sigset_t'.
104 But avoid namespace pollution on glibc systems and "unknown type 104 But avoid namespace pollution on glibc systems and "unknown type
105 name" problems on Cygwin. 105 name" problems on Cygwin.
106 On OS/2 kLIBC, sigset_t is defined in <sys/select.h>, too. In addition,
107 if <sys/param.h> is included, <types.h> -> <sys/types.h> -> <sys/select.h>
108 are included. Then <signal.h> -> <pthread.h> are included by GNULIB. By the
109 way, <pthread.h> requires PAGE_SIZE defined in <sys/param.h>. However,
110 <sys/param.h> has not been processed, yet. As a result, 'PAGE_SIZE'
111 undeclared error occurs in <pthread.h>.
106 Do this after the include_next (for the sake of OpenBSD 5.0) but before 112 Do this after the include_next (for the sake of OpenBSD 5.0) but before
107 the split double-inclusion guard (for the sake of Solaris). */ 113 the split double-inclusion guard (for the sake of Solaris). */
108#if !((defined __GLIBC__ || defined __CYGWIN__) && !defined __UCLIBC__) 114#if !((defined __GLIBC__ || defined __CYGWIN__ || defined __KLIBC__) \
115 && !defined __UCLIBC__)
109# include <signal.h> 116# include <signal.h>
110#endif 117#endif
111 118
diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h
index 3e0e4b27b7e..3ce2a0dcf15 100644
--- a/lib/sys_stat.in.h
+++ b/lib/sys_stat.in.h
@@ -375,11 +375,11 @@ struct stat
375# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) 375# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
376#endif 376#endif
377 377
378/* S_IXUGO is a common extension to POSIX. */ 378/* Although S_IXUGO and S_IRWXUGO are not specified by POSIX and are
379 not implemented in GNU/Linux, some Gnulib-using apps use the macros. */
379#if !S_IXUGO 380#if !S_IXUGO
380# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH) 381# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
381#endif 382#endif
382
383#ifndef S_IRWXUGO 383#ifndef S_IRWXUGO
384# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) 384# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
385#endif 385#endif
@@ -391,10 +391,20 @@ struct stat
391#endif 391#endif
392 392
393 393
394/* On native Windows, map 'chmod' to '_chmod', so that -loldnames is not
395 required. In C++ with GNULIB_NAMESPACE, avoid differences between
396 platforms by defining GNULIB_NAMESPACE::chmod always. */
394#if defined _WIN32 && !defined __CYGWIN__ 397#if defined _WIN32 && !defined __CYGWIN__
395# undef chmod 398# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
396# define chmod _chmod 399# undef chmod
400# define chmod _chmod
401# endif
402/* Need to cast, because in mingw the last argument is 'int mode'. */
403_GL_CXXALIAS_MDA_CAST (chmod, int, (const char *filename, mode_t mode));
404#else
405_GL_CXXALIAS_SYS (chmod, int, (const char *filename, mode_t mode));
397#endif 406#endif
407_GL_CXXALIASWARN (chmod);
398 408
399 409
400#if @GNULIB_FCHMODAT@ 410#if @GNULIB_FCHMODAT@
@@ -808,10 +818,20 @@ _GL_WARN_ON_USE (stat, "stat is unportable - "
808#endif 818#endif
809 819
810 820
821/* On native Windows, map 'umask' to '_umask', so that -loldnames is not
822 required. In C++ with GNULIB_NAMESPACE, avoid differences between
823 platforms by defining GNULIB_NAMESPACE::umask always. */
811#if defined _WIN32 && !defined __CYGWIN__ 824#if defined _WIN32 && !defined __CYGWIN__
812# undef umask 825# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
813# define umask _umask 826# undef umask
827# define umask _umask
828# endif
829/* Need to cast, because in mingw the last argument is 'int mode'. */
830_GL_CXXALIAS_MDA_CAST (umask, mode_t, (mode_t mask));
831#else
832_GL_CXXALIAS_SYS (umask, mode_t, (mode_t mask));
814#endif 833#endif
834_GL_CXXALIASWARN (umask);
815 835
816 836
817#if @GNULIB_UTIMENSAT@ 837#if @GNULIB_UTIMENSAT@
diff --git a/lib/tempname.c b/lib/tempname.c
index cfb0fc42eca..b9f7cc8703d 100644
--- a/lib/tempname.c
+++ b/lib/tempname.c
@@ -47,9 +47,11 @@
47#include <string.h> 47#include <string.h>
48 48
49#include <fcntl.h> 49#include <fcntl.h>
50#include <stdalign.h>
50#include <stdint.h> 51#include <stdint.h>
51#include <sys/random.h> 52#include <sys/random.h>
52#include <sys/stat.h> 53#include <sys/stat.h>
54#include <time.h>
53 55
54#if _LIBC 56#if _LIBC
55# define struct_stat64 struct stat64 57# define struct_stat64 struct stat64
@@ -60,27 +62,33 @@
60# define __mkdir mkdir 62# define __mkdir mkdir
61# define __open open 63# define __open open
62# define __lxstat64(version, file, buf) lstat (file, buf) 64# define __lxstat64(version, file, buf) lstat (file, buf)
65# define __getrandom getrandom
66# define __clock_gettime64 clock_gettime
67# define __timespec64 timespec
63#endif 68#endif
64 69
65#ifdef _LIBC
66# include <random-bits.h>
67# define RANDOM_BITS(Var) ((Var) = random_bits ())
68typedef uint32_t random_value;
69# define RANDOM_VALUE_MAX UINT32_MAX
70# define BASE_62_DIGITS 5 /* 62**5 < UINT32_MAX */
71# define BASE_62_POWER (62 * 62 * 62 * 62 * 62) /* 2**BASE_62_DIGITS */
72#else
73/* Use getrandom if it works, falling back on a 64-bit linear 70/* Use getrandom if it works, falling back on a 64-bit linear
74 congruential generator that starts with whatever Var's value 71 congruential generator that starts with Var's value
75 happens to be. */ 72 mixed in with a clock's low-order bits if available. */
76# define RANDOM_BITS(Var) \
77 ((void) (getrandom (&(Var), sizeof (Var), 0) == sizeof (Var) \
78 || ((Var) = 2862933555777941757 * (Var) + 3037000493)))
79typedef uint_fast64_t random_value; 73typedef uint_fast64_t random_value;
80# define RANDOM_VALUE_MAX UINT_FAST64_MAX 74#define RANDOM_VALUE_MAX UINT_FAST64_MAX
81# define BASE_62_DIGITS 10 /* 62**10 < UINT_FAST64_MAX */ 75#define BASE_62_DIGITS 10 /* 62**10 < UINT_FAST64_MAX */
82# define BASE_62_POWER (62LL * 62 * 62 * 62 * 62 * 62 * 62 * 62 * 62 * 62) 76#define BASE_62_POWER (62LL * 62 * 62 * 62 * 62 * 62 * 62 * 62 * 62 * 62)
77
78static random_value
79random_bits (random_value var)
80{
81 random_value r;
82 if (__getrandom (&r, sizeof r, 0) == sizeof r)
83 return r;
84#if _LIBC || (defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME)
85 /* Add entropy if getrandom is not supported. */
86 struct __timespec64 tv;
87 __clock_gettime64 (CLOCK_MONOTONIC, &tv);
88 var ^= tv.tv_nsec;
83#endif 89#endif
90 return 2862933555777941757 * var + 3037000493;
91}
84 92
85#if _LIBC 93#if _LIBC
86/* Return nonzero if DIR is an existent directory. */ 94/* Return nonzero if DIR is an existent directory. */
@@ -250,8 +258,11 @@ try_tempname_len (char *tmpl, int suffixlen, void *args,
250 unsigned int attempts = ATTEMPTS_MIN; 258 unsigned int attempts = ATTEMPTS_MIN;
251#endif 259#endif
252 260
253 /* A random variable. */ 261 /* A random variable. The initial value is used only the for fallback path
254 random_value v; 262 on 'random_bits' on 'getrandom' failure. Its initial value tries to use
263 some entropy from the ASLR and ignore possible bits from the stack
264 alignment. */
265 random_value v = ((uintptr_t) &v) / alignof (max_align_t);
255 266
256 /* How many random base-62 digits can currently be extracted from V. */ 267 /* How many random base-62 digits can currently be extracted from V. */
257 int vdigits = 0; 268 int vdigits = 0;
@@ -279,7 +290,7 @@ try_tempname_len (char *tmpl, int suffixlen, void *args,
279 if (vdigits == 0) 290 if (vdigits == 0)
280 { 291 {
281 do 292 do
282 RANDOM_BITS (v); 293 v = random_bits (v);
283 while (unfair_min <= v); 294 while (unfair_min <= v);
284 295
285 vdigits = BASE_62_DIGITS; 296 vdigits = BASE_62_DIGITS;
diff --git a/lib/time.in.h b/lib/time.in.h
index 32e6ec03ef4..1b17c156eba 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -145,9 +145,20 @@ _GL_CXXALIAS_MDA (tzset, void, (void));
145_GL_CXXALIAS_SYS (tzset, void, (void)); 145_GL_CXXALIAS_SYS (tzset, void, (void));
146# endif 146# endif
147_GL_CXXALIASWARN (tzset); 147_GL_CXXALIASWARN (tzset);
148# elif defined _WIN32 && !defined __CYGWIN__ 148# else
149# undef tzset 149/* On native Windows, map 'tzset' to '_tzset', so that -loldnames is not
150# define tzset _tzset 150 required. In C++ with GNULIB_NAMESPACE, avoid differences between
151 platforms by defining GNULIB_NAMESPACE::tzset always. */
152# if defined _WIN32 && !defined __CYGWIN__
153# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
154# undef tzset
155# define tzset _tzset
156# endif
157_GL_CXXALIAS_MDA (tzset, void, (void));
158# else
159_GL_CXXALIAS_SYS (tzset, void, (void));
160# endif
161_GL_CXXALIASWARN (tzset);
151# endif 162# endif
152 163
153/* Return the 'time_t' representation of TP and normalize TP. */ 164/* Return the 'time_t' representation of TP and normalize TP. */
@@ -356,17 +367,17 @@ _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
356# endif 367# endif
357# if defined GNULIB_POSIXCHECK 368# if defined GNULIB_POSIXCHECK
358# undef asctime_r 369# undef asctime_r
359_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " 370_GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - "
360 "better use strftime (or even sprintf) instead"); 371 "better use strftime (or even sprintf) instead");
361# endif 372# endif
362# if defined GNULIB_POSIXCHECK 373# if defined GNULIB_POSIXCHECK
363# undef ctime 374# undef ctime
364_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " 375_GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - "
365 "better use strftime (or even sprintf) instead"); 376 "better use strftime (or even sprintf) instead");
366# endif 377# endif
367# if defined GNULIB_POSIXCHECK 378# if defined GNULIB_POSIXCHECK
368# undef ctime_r 379# undef ctime_r
369_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " 380_GL_WARN_ON_USE (ctime_r, "ctime_r can overrun buffers in some cases - "
370 "better use strftime (or even sprintf) instead"); 381 "better use strftime (or even sprintf) instead");
371# endif 382# endif
372 383
diff --git a/lib/time_rz.c b/lib/time_rz.c
index 95438cf876e..8992c2e37e0 100644
--- a/lib/time_rz.c
+++ b/lib/time_rz.c
@@ -27,19 +27,15 @@
27#include <time.h> 27#include <time.h>
28 28
29#include <errno.h> 29#include <errno.h>
30#include <limits.h>
31#include <stdbool.h> 30#include <stdbool.h>
32#include <stddef.h> 31#include <stddef.h>
33#include <stdlib.h> 32#include <stdlib.h>
34#include <string.h> 33#include <string.h>
35 34
36#include "flexmember.h" 35#include "flexmember.h"
36#include "idx.h"
37#include "time-internal.h" 37#include "time-internal.h"
38 38
39#ifndef SIZE_MAX
40# define SIZE_MAX ((size_t) -1)
41#endif
42
43/* The approximate size to use for small allocation requests. This is 39/* The approximate size to use for small allocation requests. This is
44 the largest "small" request for the GNU C library malloc. */ 40 the largest "small" request for the GNU C library malloc. */
45enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 }; 41enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
@@ -125,14 +121,8 @@ save_abbr (timezone_t tz, struct tm *tm)
125 { 121 {
126 if (! (*zone_copy || (zone_copy == tz->abbrs && tz->tz_is_set))) 122 if (! (*zone_copy || (zone_copy == tz->abbrs && tz->tz_is_set)))
127 { 123 {
128 size_t zone_size = strlen (zone) + 1; 124 idx_t zone_size = strlen (zone) + 1;
129 size_t zone_used = zone_copy - tz->abbrs; 125 if (zone_size < tz->abbrs + ABBR_SIZE_MIN - zone_copy)
130 if (SIZE_MAX - zone_used < zone_size)
131 {
132 errno = ENOMEM;
133 return false;
134 }
135 if (zone_used + zone_size < ABBR_SIZE_MIN)
136 extend_abbrs (zone_copy, zone, zone_size); 126 extend_abbrs (zone_copy, zone, zone_size);
137 else 127 else
138 { 128 {
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 357a35e3881..4033ffeef72 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -93,20 +93,18 @@
93# undef __need_system_stdlib_h 93# undef __need_system_stdlib_h
94#endif 94#endif
95 95
96/* Native Windows platforms declare chdir, getcwd, rmdir in 96/* Native Windows platforms declare _chdir, _getcwd, _rmdir in
97 <io.h> and/or <direct.h>, not in <unistd.h>. 97 <io.h> and/or <direct.h>, not in <unistd.h>.
98 They also declare access(), chmod(), close(), dup(), dup2(), isatty(), 98 They also declare _access(), _chmod(), _close(), _dup(), _dup2(), _isatty(),
99 lseek(), read(), unlink(), write() in <io.h>. */ 99 _lseek(), _read(), _unlink(), _write() in <io.h>. */
100#if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \ 100#if defined _WIN32 && !defined __CYGWIN__
101 || defined GNULIB_POSIXCHECK) \
102 && (defined _WIN32 && ! defined __CYGWIN__))
103# include <io.h> /* mingw32, mingw64 */
104# include <direct.h> /* mingw64, MSVC 9 */
105#elif (@GNULIB_CLOSE@ || @GNULIB_DUP@ || @GNULIB_DUP2@ || @GNULIB_ISATTY@ \
106 || @GNULIB_LSEEK@ || @GNULIB_READ@ || @GNULIB_UNLINK@ || @GNULIB_WRITE@ \
107 || defined GNULIB_POSIXCHECK) \
108 && (defined _WIN32 && ! defined __CYGWIN__)
109# include <io.h> 101# include <io.h>
102# include <direct.h>
103#endif
104
105/* Native Windows platforms declare _execl*, _execv* in <process.h>. */
106#if defined _WIN32 && !defined __CYGWIN__
107# include <process.h>
110#endif 108#endif
111 109
112/* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>. 110/* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
@@ -138,11 +136,8 @@
138 136
139/* MSVC defines off_t in <sys/types.h>. 137/* MSVC defines off_t in <sys/types.h>.
140 May also define off_t to a 64-bit type on native Windows. */ 138 May also define off_t to a 64-bit type on native Windows. */
141/* But avoid namespace pollution on glibc systems. */ 139/* Get off_t, ssize_t, mode_t. */
142#ifndef __GLIBC__ 140#include <sys/types.h>
143/* Get off_t, ssize_t. */
144# include <sys/types.h>
145#endif
146 141
147/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 142/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
148 143
@@ -292,9 +287,20 @@ _GL_WARN_ON_USE (access, "access does not always support X_OK - "
292 "also, this function is a security risk - " 287 "also, this function is a security risk - "
293 "use the gnulib module faccessat instead"); 288 "use the gnulib module faccessat instead");
294# endif 289# endif
295#elif defined _WIN32 && !defined __CYGWIN__ 290#else
296# undef access 291/* On native Windows, map 'access' to '_access', so that -loldnames is not
297# define access _access 292 required. In C++ with GNULIB_NAMESPACE, avoid differences between
293 platforms by defining GNULIB_NAMESPACE::access always. */
294# if defined _WIN32 && !defined __CYGWIN__
295# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
296# undef access
297# define access _access
298# endif
299_GL_CXXALIAS_MDA (access, int, (const char *file, int mode));
300# else
301_GL_CXXALIAS_SYS (access, int, (const char *file, int mode));
302# endif
303_GL_CXXALIASWARN (access);
298#endif 304#endif
299 305
300 306
@@ -315,9 +321,20 @@ _GL_CXXALIASWARN (chdir);
315_GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - " 321_GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - "
316 "use gnulib module chdir for portability"); 322 "use gnulib module chdir for portability");
317# endif 323# endif
318#elif defined _WIN32 && !defined __CYGWIN__ 324#else
319# undef chdir 325/* On native Windows, map 'chdir' to '_chdir', so that -loldnames is not
320# define chdir _chdir 326 required. In C++ with GNULIB_NAMESPACE, avoid differences between
327 platforms by defining GNULIB_NAMESPACE::chdir always. */
328# if defined _WIN32 && !defined __CYGWIN__
329# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
330# undef chdir
331# define chdir _chdir
332# endif
333_GL_CXXALIAS_MDA (chdir, int, (const char *file));
334# else
335_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1)));
336# endif
337_GL_CXXALIASWARN (chdir);
321#endif 338#endif
322 339
323 340
@@ -380,9 +397,20 @@ _GL_CXXALIASWARN (close);
380/* Assume close is always declared. */ 397/* Assume close is always declared. */
381_GL_WARN_ON_USE (close, "close does not portably work on sockets - " 398_GL_WARN_ON_USE (close, "close does not portably work on sockets - "
382 "use gnulib module close for portability"); 399 "use gnulib module close for portability");
383#elif defined _WIN32 && !defined __CYGWIN__ 400#else
384# undef close 401/* On native Windows, map 'close' to '_close', so that -loldnames is not
385# define close _close 402 required. In C++ with GNULIB_NAMESPACE, avoid differences between
403 platforms by defining GNULIB_NAMESPACE::close always. */
404# if defined _WIN32 && !defined __CYGWIN__
405# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
406# undef close
407# define close _close
408# endif
409_GL_CXXALIAS_MDA (close, int, (int fd));
410# else
411_GL_CXXALIAS_SYS (close, int, (int fd));
412# endif
413_GL_CXXALIASWARN (close);
386#endif 414#endif
387 415
388 416
@@ -397,10 +425,11 @@ _GL_CXXALIAS_SYS (copy_file_range, ssize_t, (int ifd, off_t *ipos,
397# endif 425# endif
398_GL_CXXALIASWARN (copy_file_range); 426_GL_CXXALIASWARN (copy_file_range);
399#elif defined GNULIB_POSIXCHECK 427#elif defined GNULIB_POSIXCHECK
400/* Assume copy_file_range is always declared. */ 428# if HAVE_RAW_DECL_COPY_FILE_RANGE
401_GL_WARN_ON_USE (copy_file_range, 429_GL_WARN_ON_USE (copy_file_range,
402 "copy_file_range is unportable - " 430 "copy_file_range is unportable - "
403 "use gnulib module copy_file_range for portability"); 431 "use gnulib module copy_file_range for portability");
432# endif
404#endif 433#endif
405 434
406 435
@@ -427,9 +456,20 @@ _GL_CXXALIASWARN (dup);
427_GL_WARN_ON_USE (dup, "dup is unportable - " 456_GL_WARN_ON_USE (dup, "dup is unportable - "
428 "use gnulib module dup for portability"); 457 "use gnulib module dup for portability");
429# endif 458# endif
430#elif defined _WIN32 && !defined __CYGWIN__ 459#else
431# undef dup 460/* On native Windows, map 'dup' to '_dup', so that -loldnames is not
432# define dup _dup 461 required. In C++ with GNULIB_NAMESPACE, avoid differences between
462 platforms by defining GNULIB_NAMESPACE::dup always. */
463# if defined _WIN32 && !defined __CYGWIN__
464# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
465# undef dup
466# define dup _dup
467# endif
468_GL_CXXALIAS_MDA (dup, int, (int oldfd));
469# else
470_GL_CXXALIAS_SYS (dup, int, (int oldfd));
471# endif
472_GL_CXXALIASWARN (dup);
433#endif 473#endif
434 474
435 475
@@ -461,9 +501,20 @@ _GL_CXXALIASWARN (dup2);
461_GL_WARN_ON_USE (dup2, "dup2 is unportable - " 501_GL_WARN_ON_USE (dup2, "dup2 is unportable - "
462 "use gnulib module dup2 for portability"); 502 "use gnulib module dup2 for portability");
463# endif 503# endif
464#elif defined _WIN32 && !defined __CYGWIN__ 504#else
465# undef dup2 505/* On native Windows, map 'dup2' to '_dup2', so that -loldnames is not
466# define dup2 _dup2 506 required. In C++ with GNULIB_NAMESPACE, avoid differences between
507 platforms by defining GNULIB_NAMESPACE::dup2 always. */
508# if defined _WIN32 && !defined __CYGWIN__
509# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
510# undef dup2
511# define dup2 _dup2
512# endif
513_GL_CXXALIAS_MDA (dup2, int, (int oldfd, int newfd));
514# else
515_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
516# endif
517_GL_CXXALIASWARN (dup2);
467#endif 518#endif
468 519
469 520
@@ -564,40 +615,116 @@ _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
564#endif 615#endif
565 616
566 617
618/* On native Windows, map 'execl' to '_execl', so that -loldnames is not
619 required. In C++ with GNULIB_NAMESPACE, avoid differences between
620 platforms by defining GNULIB_NAMESPACE::execl always. */
567#if defined _WIN32 && !defined __CYGWIN__ 621#if defined _WIN32 && !defined __CYGWIN__
568# undef execl 622# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
569# define execl _execl 623# undef execl
624# define execl _execl
625# endif
626_GL_CXXALIAS_MDA (execl, intptr_t, (const char *program, const char *arg, ...));
627#else
628_GL_CXXALIAS_SYS (execl, int, (const char *program, const char *arg, ...));
570#endif 629#endif
630_GL_CXXALIASWARN (execl);
571 631
632/* On native Windows, map 'execle' to '_execle', so that -loldnames is not
633 required. In C++ with GNULIB_NAMESPACE, avoid differences between
634 platforms by defining GNULIB_NAMESPACE::execle always. */
572#if defined _WIN32 && !defined __CYGWIN__ 635#if defined _WIN32 && !defined __CYGWIN__
573# undef execle 636# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
574# define execle _execle 637# undef execle
638# define execle _execle
639# endif
640_GL_CXXALIAS_MDA (execle, intptr_t, (const char *program, const char *arg, ...));
641#else
642_GL_CXXALIAS_SYS (execle, int, (const char *program, const char *arg, ...));
575#endif 643#endif
644_GL_CXXALIASWARN (execle);
576 645
646/* On native Windows, map 'execlp' to '_execlp', so that -loldnames is not
647 required. In C++ with GNULIB_NAMESPACE, avoid differences between
648 platforms by defining GNULIB_NAMESPACE::execlp always. */
577#if defined _WIN32 && !defined __CYGWIN__ 649#if defined _WIN32 && !defined __CYGWIN__
578# undef execlp 650# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
579# define execlp _execlp 651# undef execlp
652# define execlp _execlp
653# endif
654_GL_CXXALIAS_MDA (execlp, intptr_t, (const char *program, const char *arg, ...));
655#else
656_GL_CXXALIAS_SYS (execlp, int, (const char *program, const char *arg, ...));
580#endif 657#endif
658_GL_CXXALIASWARN (execlp);
581 659
582 660
661/* On native Windows, map 'execv' to '_execv', so that -loldnames is not
662 required. In C++ with GNULIB_NAMESPACE, avoid differences between
663 platforms by defining GNULIB_NAMESPACE::execv always. */
583#if defined _WIN32 && !defined __CYGWIN__ 664#if defined _WIN32 && !defined __CYGWIN__
584# undef execv 665# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
585# define execv _execv 666# undef execv
667# define execv _execv
668# endif
669_GL_CXXALIAS_MDA (execv, intptr_t,
670 (const char *program, const char * const *argv));
671#else
672_GL_CXXALIAS_SYS (execv, int, (const char *program, char * const *argv));
586#endif 673#endif
674_GL_CXXALIASWARN (execv);
587 675
676/* On native Windows, map 'execve' to '_execve', so that -loldnames is not
677 required. In C++ with GNULIB_NAMESPACE, avoid differences between
678 platforms by defining GNULIB_NAMESPACE::execve always. */
588#if defined _WIN32 && !defined __CYGWIN__ 679#if defined _WIN32 && !defined __CYGWIN__
589# undef execve 680# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
590# define execve _execve 681# undef execve
682# define execve _execve
683# endif
684_GL_CXXALIAS_MDA (execve, intptr_t,
685 (const char *program, const char * const *argv,
686 const char * const *env));
687#else
688_GL_CXXALIAS_SYS (execve, int,
689 (const char *program, char * const *argv, char * const *env));
591#endif 690#endif
691_GL_CXXALIASWARN (execve);
592 692
693/* On native Windows, map 'execvp' to '_execvp', so that -loldnames is not
694 required. In C++ with GNULIB_NAMESPACE, avoid differences between
695 platforms by defining GNULIB_NAMESPACE::execvp always. */
593#if defined _WIN32 && !defined __CYGWIN__ 696#if defined _WIN32 && !defined __CYGWIN__
594# undef execvp 697# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
595# define execvp _execvp 698# undef execvp
699# define execvp _execvp
700# endif
701_GL_CXXALIAS_MDA (execvp, intptr_t,
702 (const char *program, const char * const *argv));
703#else
704_GL_CXXALIAS_SYS (execvp, int, (const char *program, char * const *argv));
596#endif 705#endif
706_GL_CXXALIASWARN (execvp);
597 707
708/* On native Windows, map 'execvpe' to '_execvpe', so that -loldnames is not
709 required. In C++ with GNULIB_NAMESPACE, avoid differences between
710 platforms by defining GNULIB_NAMESPACE::execvpe on all platforms that have
711 it. */
598#if defined _WIN32 && !defined __CYGWIN__ 712#if defined _WIN32 && !defined __CYGWIN__
599# undef execvpe 713# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
600# define execvpe _execvpe 714# undef execvpe
715# define execvpe _execvpe
716# endif
717_GL_CXXALIAS_MDA (execvpe, intptr_t,
718 (const char *program, const char * const *argv,
719 const char * const *env));
720#else
721# if @HAVE_DECL_EXECVPE@
722_GL_CXXALIAS_SYS (execvpe, int,
723 (const char *program, char * const *argv, char * const *env));
724# endif
725#endif
726#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_EXECVPE@
727_GL_CXXALIASWARN (execvpe);
601#endif 728#endif
602 729
603 730
@@ -794,9 +921,22 @@ _GL_CXXALIASWARN (getcwd);
794_GL_WARN_ON_USE (getcwd, "getcwd is unportable - " 921_GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
795 "use gnulib module getcwd for portability"); 922 "use gnulib module getcwd for portability");
796# endif 923# endif
797#elif defined _WIN32 && !defined __CYGWIN__ 924#else
798# undef getcwd 925/* On native Windows, map 'getcwd' to '_getcwd', so that -loldnames is not
799# define getcwd _getcwd 926 required. In C++ with GNULIB_NAMESPACE, avoid differences between
927 platforms by defining GNULIB_NAMESPACE::getcwd always. */
928# if defined _WIN32 && !defined __CYGWIN__
929# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
930# undef getcwd
931# define getcwd _getcwd
932# endif
933/* Need to cast, because on mingw, the second parameter is either
934 'int size' or 'size_t size'. */
935_GL_CXXALIAS_MDA_CAST (getcwd, char *, (char *buf, size_t size));
936# else
937_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size));
938# endif
939_GL_CXXALIASWARN (getcwd);
800#endif 940#endif
801 941
802 942
@@ -1131,10 +1271,19 @@ _GL_WARN_ON_USE (getpass, "getpass is unportable - "
1131#endif 1271#endif
1132 1272
1133 1273
1274/* On native Windows, map 'getpid' to '_getpid', so that -loldnames is not
1275 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1276 platforms by defining GNULIB_NAMESPACE::getpid always. */
1134#if defined _WIN32 && !defined __CYGWIN__ 1277#if defined _WIN32 && !defined __CYGWIN__
1135# undef getpid 1278# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1136# define getpid _getpid 1279# undef getpid
1280# define getpid _getpid
1281# endif
1282_GL_CXXALIAS_MDA (getpid, int, (void));
1283#else
1284_GL_CXXALIAS_SYS (getpid, pid_t, (void));
1137#endif 1285#endif
1286_GL_CXXALIASWARN (getpid);
1138 1287
1139 1288
1140#if @GNULIB_GETUSERSHELL@ 1289#if @GNULIB_GETUSERSHELL@
@@ -1225,9 +1374,20 @@ _GL_CXXALIASWARN (isatty);
1225_GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - " 1374_GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - "
1226 "use gnulib module isatty for portability"); 1375 "use gnulib module isatty for portability");
1227# endif 1376# endif
1228#elif defined _WIN32 && !defined __CYGWIN__ 1377#else
1229# undef isatty 1378/* On native Windows, map 'isatty' to '_isatty', so that -loldnames is not
1230# define isatty _isatty 1379 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1380 platforms by defining GNULIB_NAMESPACE::isatty always. */
1381# if defined _WIN32 && !defined __CYGWIN__
1382# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1383# undef isatty
1384# define isatty _isatty
1385# endif
1386_GL_CXXALIAS_MDA (isatty, int, (int fd));
1387# else
1388_GL_CXXALIAS_SYS (isatty, int, (int fd));
1389# endif
1390_GL_CXXALIASWARN (isatty);
1231#endif 1391#endif
1232 1392
1233 1393
@@ -1355,9 +1515,20 @@ _GL_CXXALIASWARN (lseek);
1355_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some " 1515_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
1356 "systems - use gnulib module lseek for portability"); 1516 "systems - use gnulib module lseek for portability");
1357# endif 1517# endif
1358#elif defined _WIN32 && !defined __CYGWIN__ 1518#else
1359# undef lseek 1519/* On native Windows, map 'lseek' to '_lseek', so that -loldnames is not
1360# define lseek _lseek 1520 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1521 platforms by defining GNULIB_NAMESPACE::lseek always. */
1522# if defined _WIN32 && !defined __CYGWIN__
1523# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1524# undef lseek
1525# define lseek _lseek
1526# endif
1527_GL_CXXALIAS_MDA (lseek, long, (int fd, long offset, int whence));
1528# else
1529_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
1530# endif
1531_GL_CXXALIASWARN (lseek);
1361#endif 1532#endif
1362 1533
1363 1534
@@ -1497,15 +1668,27 @@ _GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count));
1497# endif 1668# endif
1498_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, size_t count)); 1669_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, size_t count));
1499# else 1670# else
1500/* Need to cast, because on mingw, the third parameter is 1671_GL_CXXALIAS_SYS (read, ssize_t, (int fd, void *buf, size_t count));
1501 unsigned int count 1672# endif
1502 and the return type is 'int'. */ 1673_GL_CXXALIASWARN (read);
1503_GL_CXXALIAS_SYS_CAST (read, ssize_t, (int fd, void *buf, size_t count)); 1674#else
1675/* On native Windows, map 'read' to '_read', so that -loldnames is not
1676 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1677 platforms by defining GNULIB_NAMESPACE::read always. */
1678# if defined _WIN32 && !defined __CYGWIN__
1679# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1680# undef read
1681# define read _read
1682# endif
1683# ifdef __MINGW32__
1684_GL_CXXALIAS_MDA (read, int, (int fd, void *buf, unsigned int count));
1685# else
1686_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, unsigned int count));
1687# endif
1688# else
1689_GL_CXXALIAS_SYS (read, ssize_t, (int fd, void *buf, size_t count));
1504# endif 1690# endif
1505_GL_CXXALIASWARN (read); 1691_GL_CXXALIASWARN (read);
1506#elif defined _WIN32 && !defined __CYGWIN__
1507# undef read
1508# define read _read
1509#endif 1692#endif
1510 1693
1511 1694
@@ -1604,9 +1787,20 @@ _GL_CXXALIASWARN (rmdir);
1604_GL_WARN_ON_USE (rmdir, "rmdir is unportable - " 1787_GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1605 "use gnulib module rmdir for portability"); 1788 "use gnulib module rmdir for portability");
1606# endif 1789# endif
1607#elif defined _WIN32 && !defined __CYGWIN__ 1790#else
1608# undef rmdir 1791/* On native Windows, map 'rmdir' to '_rmdir', so that -loldnames is not
1609# define rmdir _rmdir 1792 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1793 platforms by defining GNULIB_NAMESPACE::rmdir always. */
1794# if defined _WIN32 && !defined __CYGWIN__
1795# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1796# undef rmdir
1797# define rmdir _rmdir
1798# endif
1799_GL_CXXALIAS_MDA (rmdir, int, (char const *name));
1800# else
1801_GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1802# endif
1803_GL_CXXALIASWARN (rmdir);
1610#endif 1804#endif
1611 1805
1612 1806
@@ -1665,10 +1859,19 @@ _GL_WARN_ON_USE (sleep, "sleep is unportable - "
1665#endif 1859#endif
1666 1860
1667 1861
1862/* On native Windows, map 'swab' to '_swab', so that -loldnames is not
1863 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1864 platforms by defining GNULIB_NAMESPACE::creat always. */
1668#if defined _WIN32 && !defined __CYGWIN__ 1865#if defined _WIN32 && !defined __CYGWIN__
1669# undef swab 1866# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1670# define swab _swab 1867# undef swab
1868# define swab _swab
1869# endif
1870_GL_CXXALIAS_MDA (swab, void, (char *from, char *to, int n));
1871#else
1872_GL_CXXALIAS_SYS (swab, void, (const void *from, void *to, ssize_t n));
1671#endif 1873#endif
1874_GL_CXXALIASWARN (swab);
1672 1875
1673 1876
1674#if @GNULIB_SYMLINK@ 1877#if @GNULIB_SYMLINK@
@@ -1811,9 +2014,20 @@ _GL_CXXALIASWARN (unlink);
1811_GL_WARN_ON_USE (unlink, "unlink is not portable - " 2014_GL_WARN_ON_USE (unlink, "unlink is not portable - "
1812 "use gnulib module unlink for portability"); 2015 "use gnulib module unlink for portability");
1813# endif 2016# endif
1814#elif defined _WIN32 && !defined __CYGWIN__ 2017#else
1815# undef unlink 2018/* On native Windows, map 'unlink' to '_unlink', so that -loldnames is not
1816# define unlink _unlink 2019 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2020 platforms by defining GNULIB_NAMESPACE::unlink always. */
2021# if defined _WIN32 && !defined __CYGWIN__
2022# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2023# undef unlink
2024# define unlink _unlink
2025# endif
2026_GL_CXXALIAS_MDA (unlink, int, (char const *file));
2027# else
2028_GL_CXXALIAS_SYS (unlink, int, (char const *file));
2029# endif
2030_GL_CXXALIASWARN (unlink);
1817#endif 2031#endif
1818 2032
1819 2033
@@ -1892,15 +2106,27 @@ _GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
1892# endif 2106# endif
1893_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, size_t count)); 2107_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, size_t count));
1894# else 2108# else
1895/* Need to cast, because on mingw, the third parameter is 2109_GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
1896 unsigned int count 2110# endif
1897 and the return type is 'int'. */ 2111_GL_CXXALIASWARN (write);
1898_GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count)); 2112#else
2113/* On native Windows, map 'write' to '_write', so that -loldnames is not
2114 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2115 platforms by defining GNULIB_NAMESPACE::write always. */
2116# if defined _WIN32 && !defined __CYGWIN__
2117# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2118# undef write
2119# define write _write
2120# endif
2121# ifdef __MINGW32__
2122_GL_CXXALIAS_MDA (write, int, (int fd, const void *buf, unsigned int count));
2123# else
2124_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, unsigned int count));
2125# endif
2126# else
2127_GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
1899# endif 2128# endif
1900_GL_CXXALIASWARN (write); 2129_GL_CXXALIASWARN (write);
1901#elif defined _WIN32 && !defined __CYGWIN__
1902# undef write
1903# define write _write
1904#endif 2130#endif
1905 2131
1906_GL_INLINE_HEADER_END 2132_GL_INLINE_HEADER_END
diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h
index 13ee23031a0..7cd4a74f04d 100644
--- a/lib/xalloc-oversized.h
+++ b/lib/xalloc-oversized.h
@@ -41,7 +41,7 @@ typedef size_t __xalloc_count_type;
41 positive and N must be nonnegative. This is a macro, not a 41 positive and N must be nonnegative. This is a macro, not a
42 function, so that it works correctly even when SIZE_MAX < N. */ 42 function, so that it works correctly even when SIZE_MAX < N. */
43 43
44#if 7 <= __GNUC__ 44#if 7 <= __GNUC__ && !defined __clang__
45# define xalloc_oversized(n, s) \ 45# define xalloc_oversized(n, s) \
46 __builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1) 46 __builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1)
47#elif 5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__ 47#elif 5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__