aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Colascione2019-06-23 18:19:08 -0700
committerDaniel Colascione2019-06-23 18:19:08 -0700
commitb9ac4f815ebaa1acb0d045fe9583f665efa6f628 (patch)
treef2bfcf685bb9f83a67c5f70fe8e4f65ef16d8690
parentf3b1b5fb5034de026adc41cf2403cff42f4a0b67 (diff)
downloademacs-b9ac4f815ebaa1acb0d045fe9583f665efa6f628.tar.gz
emacs-b9ac4f815ebaa1acb0d045fe9583f665efa6f628.zip
Fix locating pdump by symlink
* admin/merge-gnulib (GNULIB_MODULES): Add canonicalize-lgpl module * build-aux/config.guess, build-aux/gitlog-to-changelog, build-aux/update-copyright, lib/canonicalize-lgpl.c, lib/gnulib.mk.in, lib/malloca.c, lib/malloca.h, lib/pathmax.h, m4/canonicalize.m4, m4/double-slash-root.m4, m4/gnulib-comp.m4, m4/malloca.m4, my/pathmax.4: copy from GNUlib or regenerate from update * src/emacs.c: find dump by canonical path
-rwxr-xr-xadmin/merge-gnulib1
-rwxr-xr-xbuild-aux/config.guess5
-rwxr-xr-xbuild-aux/gitlog-to-changelog42
-rwxr-xr-xbuild-aux/update-copyright35
-rw-r--r--lib/canonicalize-lgpl.c428
-rw-r--r--lib/gnulib.mk.in38
-rw-r--r--lib/malloca.c105
-rw-r--r--lib/malloca.h127
-rw-r--r--lib/pathmax.h83
-rw-r--r--m4/canonicalize.m4133
-rw-r--r--m4/double-slash-root.m438
-rw-r--r--m4/gnulib-comp.m443
-rw-r--r--m4/malloca.m415
-rw-r--r--m4/pathmax.m442
-rw-r--r--src/emacs.c27
15 files changed, 1130 insertions, 32 deletions
diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index c2d9291b843..78e74882f3d 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -29,6 +29,7 @@ GNULIB_MODULES='
29 alloca-opt binary-io byteswap c-ctype c-strcase 29 alloca-opt binary-io byteswap c-ctype c-strcase
30 careadlinkat close-stream copy-file-range 30 careadlinkat close-stream copy-file-range
31 count-leading-zeros count-one-bits count-trailing-zeros 31 count-leading-zeros count-one-bits count-trailing-zeros
32 canonicalize-lgpl
32 crypto/md5-buffer crypto/sha1-buffer crypto/sha256-buffer crypto/sha512-buffer 33 crypto/md5-buffer crypto/sha1-buffer crypto/sha256-buffer crypto/sha512-buffer
33 d-type diffseq dosname dtoastr dtotimespec dup2 34 d-type diffseq dosname dtoastr dtotimespec dup2
34 environ execinfo explicit_bzero faccessat 35 environ execinfo explicit_bzero faccessat
diff --git a/build-aux/config.guess b/build-aux/config.guess
index ae713942d8f..41b8b854c02 100755
--- a/build-aux/config.guess
+++ b/build-aux/config.guess
@@ -2,7 +2,7 @@
2# Attempt to guess a canonical system name. 2# Attempt to guess a canonical system name.
3# Copyright 1992-2019 Free Software Foundation, Inc. 3# Copyright 1992-2019 Free Software Foundation, Inc.
4 4
5timestamp='2019-05-28' 5timestamp='2019-06-10'
6 6
7# This file is free software; you can redistribute it and/or modify it 7# This file is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by 8# under the terms of the GNU General Public License as published by
@@ -262,6 +262,9 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
262 *:SolidBSD:*:*) 262 *:SolidBSD:*:*)
263 echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE" 263 echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE"
264 exit ;; 264 exit ;;
265 *:OS108:*:*)
266 echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE"
267 exit ;;
265 macppc:MirBSD:*:*) 268 macppc:MirBSD:*:*)
266 echo powerpc-unknown-mirbsd"$UNAME_RELEASE" 269 echo powerpc-unknown-mirbsd"$UNAME_RELEASE"
267 exit ;; 270 exit ;;
diff --git a/build-aux/gitlog-to-changelog b/build-aux/gitlog-to-changelog
index deddef24466..3acfa8b4c5b 100755
--- a/build-aux/gitlog-to-changelog
+++ b/build-aux/gitlog-to-changelog
@@ -1,31 +1,46 @@
1eval '(exit $?0)' && eval 'exec perl -wS "$0" "$@"' 1#!/bin/sh
2 & eval 'exec perl -wS "$0" $argv:q' 2#! -*-perl-*-
3 if 0;
4# Convert git log output to ChangeLog format.
5 3
6my $VERSION = '2018-03-07 03:47'; # UTC 4# Convert git log output to ChangeLog format.
7# The definition above must lie within the first 8 lines in order
8# for the Emacs time-stamp write hook (at end) to update it.
9# If you change this file with Emacs, please let the write hook
10# do its job. Otherwise, update this string manually.
11 5
12# Copyright (C) 2008-2019 Free Software Foundation, Inc. 6# Copyright (C) 2008-2019 Free Software Foundation, Inc.
13 7#
14# This program is free software: you can redistribute it and/or modify 8# This program is free software: you can redistribute it and/or modify
15# it under the terms of the GNU General Public License as published by 9# it under the terms of the GNU General Public License as published by
16# the Free Software Foundation, either version 3 of the License, or 10# the Free Software Foundation, either version 3 of the License, or
17# (at your option) any later version. 11# (at your option) any later version.
18 12#
19# This program is distributed in the hope that it will be useful, 13# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details. 16# GNU General Public License for more details.
23 17#
24# You should have received a copy of the GNU General Public License 18# You should have received a copy of the GNU General Public License
25# along with this program. If not, see <https://www.gnu.org/licenses/>. 19# along with this program. If not, see <https://www.gnu.org/licenses/>.
26 20#
27# Written by Jim Meyering 21# Written by Jim Meyering
28 22
23# This is a prologue that allows to run a perl script as an executable
24# on systems that are compliant to a POSIX version before POSIX:2017.
25# On such systems, the usual invocation of an executable through execlp()
26# or execvp() fails with ENOEXEC if it is a script that does not start
27# with a #! line. The script interpreter mentioned in the #! line has
28# to be /bin/sh, because on GuixSD systems that is the only program that
29# has a fixed file name. The second line is essential for perl and is
30# also useful for editing this file in Emacs. The next two lines below
31# are valid code in both sh and perl. When executed by sh, they re-execute
32# the script through the perl program found in $PATH. The '-x' option
33# is essential as well; without it, perl would re-execute the script
34# through /bin/sh. When executed by perl, the next two lines are a no-op.
35eval 'exec perl -wSx "$0" "$@"'
36 if 0;
37
38my $VERSION = '2018-03-07 03:47'; # UTC
39# The definition above must lie within the first 8 lines in order
40# for the Emacs time-stamp write hook (at end) to update it.
41# If you change this file with Emacs, please let the write hook
42# do its job. Otherwise, update this string manually.
43
29use strict; 44use strict;
30use warnings; 45use warnings;
31use Getopt::Long; 46use Getopt::Long;
@@ -492,6 +507,7 @@ sub git_dir_option($)
492# mode: perl 507# mode: perl
493# indent-tabs-mode: nil 508# indent-tabs-mode: nil
494# eval: (add-hook 'before-save-hook 'time-stamp) 509# eval: (add-hook 'before-save-hook 'time-stamp)
510# time-stamp-line-limit: 50
495# time-stamp-start: "my $VERSION = '" 511# time-stamp-start: "my $VERSION = '"
496# time-stamp-format: "%:y-%02m-%02d %02H:%02M" 512# time-stamp-format: "%:y-%02m-%02d %02H:%02M"
497# time-stamp-time-zone: "UTC0" 513# time-stamp-time-zone: "UTC0"
diff --git a/build-aux/update-copyright b/build-aux/update-copyright
index d80549ea8dd..4a9ea7c7a75 100755
--- a/build-aux/update-copyright
+++ b/build-aux/update-copyright
@@ -1,9 +1,7 @@
1eval '(exit $?0)' && eval 'exec perl -wS -0777 -pi "$0" "$@"' 1#!/bin/sh
2 & eval 'exec perl -wS -0777 -pi "$0" $argv:q' 2#! -*-perl-*-
3 if 0;
4# Update an FSF copyright year list to include the current year.
5 3
6my $VERSION = '2018-03-07.03:47'; # UTC 4# Update an FSF copyright year list to include the current year.
7 5
8# Copyright (C) 2009-2019 Free Software Foundation, Inc. 6# Copyright (C) 2009-2019 Free Software Foundation, Inc.
9# 7#
@@ -19,9 +17,12 @@ my $VERSION = '2018-03-07.03:47'; # UTC
19# 17#
20# You should have received a copy of the GNU General Public License 18# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <https://www.gnu.org/licenses/>. 19# along with this program. If not, see <https://www.gnu.org/licenses/>.
22 20#
23# Written by Jim Meyering and Joel E. Denny 21# Written by Jim Meyering and Joel E. Denny
24 22
23# This script updates an FSF copyright year list to include the current year.
24# Usage: update-copyright [FILE...]
25#
25# The arguments to this script should be names of files that contain 26# The arguments to this script should be names of files that contain
26# copyright statements to be updated. The copyright holder's name 27# copyright statements to be updated. The copyright holder's name
27# defaults to "Free Software Foundation, Inc." but may be changed to 28# defaults to "Free Software Foundation, Inc." but may be changed to
@@ -121,6 +122,27 @@ my $VERSION = '2018-03-07.03:47'; # UTC
121# 5. Set UPDATE_COPYRIGHT_HOLDER if the copyright holder is other 122# 5. Set UPDATE_COPYRIGHT_HOLDER if the copyright holder is other
122# than "Free Software Foundation, Inc.". 123# than "Free Software Foundation, Inc.".
123 124
125# This is a prologue that allows to run a perl script as an executable
126# on systems that are compliant to a POSIX version before POSIX:2017.
127# On such systems, the usual invocation of an executable through execlp()
128# or execvp() fails with ENOEXEC if it is a script that does not start
129# with a #! line. The script interpreter mentioned in the #! line has
130# to be /bin/sh, because on GuixSD systems that is the only program that
131# has a fixed file name. The second line is essential for perl and is
132# also useful for editing this file in Emacs. The next two lines below
133# are valid code in both sh and perl. When executed by sh, they re-execute
134# the script through the perl program found in $PATH. The '-x' option
135# is essential as well; without it, perl would re-execute the script
136# through /bin/sh. When executed by perl, the next two lines are a no-op.
137eval 'exec perl -wSx "$0" "$@"'
138 if 0;
139
140my $VERSION = '2018-03-07.03:47'; # UTC
141# The definition above must lie within the first 8 lines in order
142# for the Emacs time-stamp write hook (at end) to update it.
143# If you change this file with Emacs, please let the write hook
144# do its job. Otherwise, update this string manually.
145
124use strict; 146use strict;
125use warnings; 147use warnings;
126 148
@@ -270,6 +292,7 @@ else
270# mode: perl 292# mode: perl
271# indent-tabs-mode: nil 293# indent-tabs-mode: nil
272# eval: (add-hook 'before-save-hook 'time-stamp) 294# eval: (add-hook 'before-save-hook 'time-stamp)
295# time-stamp-line-limit: 200
273# time-stamp-start: "my $VERSION = '" 296# time-stamp-start: "my $VERSION = '"
274# time-stamp-format: "%:y-%02m-%02d.%02H:%02M" 297# time-stamp-format: "%:y-%02m-%02d.%02H:%02M"
275# time-stamp-time-zone: "UTC0" 298# time-stamp-time-zone: "UTC0"
diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
new file mode 100644
index 00000000000..4d1be6dc24b
--- /dev/null
+++ b/lib/canonicalize-lgpl.c
@@ -0,0 +1,428 @@
1/* Return the canonical absolute name of a given file.
2 Copyright (C) 1996-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef _LIBC
19/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
20 optimizes away the name == NULL test below. */
21# define _GL_ARG_NONNULL(params)
22
23# define _GL_USE_STDLIB_ALLOC 1
24# include <config.h>
25#endif
26
27#if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC
28
29/* Specification. */
30#include <stdlib.h>
31
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>
41#include <stddef.h>
42
43#ifdef _LIBC
44# include <shlib-compat.h>
45#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 __realpath realpath
52# include "pathmax.h"
53# include "malloca.h"
54# include "dosname.h"
55# if HAVE_GETCWD
56# if IN_RELOCWRAPPER
57 /* When building the relocatable program wrapper, use the system's getcwd
58 function, not the gnulib override, otherwise we would get a link error.
59 */
60# undef getcwd
61# endif
62# if defined VMS && !defined getcwd
63 /* We want the directory in Unix syntax, not in VMS syntax.
64 The gnulib override of 'getcwd' takes 2 arguments; the original VMS
65 'getcwd' takes 3 arguments. */
66# define __getcwd(buf, max) getcwd (buf, max, 0)
67# else
68# define __getcwd getcwd
69# endif
70# else
71# define __getcwd(buf, max) getwd (buf)
72# endif
73# define __readlink readlink
74# define __set_errno(e) errno = (e)
75# ifndef MAXSYMLINKS
76# ifdef SYMLOOP_MAX
77# define MAXSYMLINKS SYMLOOP_MAX
78# else
79# define MAXSYMLINKS 20
80# endif
81# endif
82#endif
83
84#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
85# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
86#endif
87
88/* Define this independently so that stdint.h is not a prerequisite. */
89#ifndef SIZE_MAX
90# define SIZE_MAX ((size_t) -1)
91#endif
92
93#if !FUNC_REALPATH_WORKS || defined _LIBC
94
95static void
96alloc_failed (void)
97{
98#if defined _WIN32 && ! defined __CYGWIN__
99 /* Avoid errno problem without using the malloc or realloc modules; see:
100 https://lists.gnu.org/r/bug-gnulib/2016-08/msg00025.html */
101 errno = ENOMEM;
102#endif
103}
104
105/* Return the canonical absolute name of file NAME. A canonical name
106 does not contain any ".", ".." components nor any repeated path
107 separators ('/') or symlinks. All path components must exist. If
108 RESOLVED is null, the result is malloc'd; otherwise, if the
109 canonical name is PATH_MAX chars or more, returns null with 'errno'
110 set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
111 returns the name in RESOLVED. If the name cannot be resolved and
112 RESOLVED is non-NULL, it contains the path of the first component
113 that cannot be resolved. If the path can be resolved, RESOLVED
114 holds the same value as the value returned. */
115
116char *
117__realpath (const char *name, char *resolved)
118{
119 char *rpath, *dest, *extra_buf = NULL;
120 const char *start, *end, *rpath_limit;
121 long int path_max;
122 int num_links = 0;
123 size_t prefix_len;
124
125 if (name == NULL)
126 {
127 /* As per Single Unix Specification V2 we must return an error if
128 either parameter is a null pointer. We extend this to allow
129 the RESOLVED parameter to be NULL in case the we are expected to
130 allocate the room for the return value. */
131 __set_errno (EINVAL);
132 return NULL;
133 }
134
135 if (name[0] == '\0')
136 {
137 /* As per Single Unix Specification V2 we must return an error if
138 the name argument points to an empty string. */
139 __set_errno (ENOENT);
140 return NULL;
141 }
142
143#ifdef PATH_MAX
144 path_max = PATH_MAX;
145#else
146 path_max = pathconf (name, _PC_PATH_MAX);
147 if (path_max <= 0)
148 path_max = 8192;
149#endif
150
151 if (resolved == NULL)
152 {
153 rpath = malloc (path_max);
154 if (rpath == NULL)
155 {
156 alloc_failed ();
157 return NULL;
158 }
159 }
160 else
161 rpath = resolved;
162 rpath_limit = rpath + path_max;
163
164 /* This is always zero for Posix hosts, but can be 2 for MS-Windows
165 and MS-DOS X:/foo/bar file names. */
166 prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
167
168 if (!IS_ABSOLUTE_FILE_NAME (name))
169 {
170 if (!__getcwd (rpath, path_max))
171 {
172 rpath[0] = '\0';
173 goto error;
174 }
175 dest = strchr (rpath, '\0');
176 start = name;
177 prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath);
178 }
179 else
180 {
181 dest = rpath;
182 if (prefix_len)
183 {
184 memcpy (rpath, name, prefix_len);
185 dest += prefix_len;
186 }
187 *dest++ = '/';
188 if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
189 {
190 if (ISSLASH (name[1]) && !ISSLASH (name[2]) && !prefix_len)
191 *dest++ = '/';
192 *dest = '\0';
193 }
194 start = name + prefix_len;
195 }
196
197 for (end = start; *start; start = end)
198 {
199#ifdef _LIBC
200 struct stat64 st;
201#else
202 struct stat st;
203#endif
204
205 /* Skip sequence of multiple path-separators. */
206 while (ISSLASH (*start))
207 ++start;
208
209 /* Find end of path component. */
210 for (end = start; *end && !ISSLASH (*end); ++end)
211 /* Nothing. */;
212
213 if (end - start == 0)
214 break;
215 else if (end - start == 1 && start[0] == '.')
216 /* nothing */;
217 else if (end - start == 2 && start[0] == '.' && start[1] == '.')
218 {
219 /* Back up to previous component, ignore if at root already. */
220 if (dest > rpath + prefix_len + 1)
221 for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
222 continue;
223 if (DOUBLE_SLASH_IS_DISTINCT_ROOT
224 && dest == rpath + 1 && !prefix_len
225 && ISSLASH (*dest) && !ISSLASH (dest[1]))
226 dest++;
227 }
228 else
229 {
230 size_t new_size;
231
232 if (!ISSLASH (dest[-1]))
233 *dest++ = '/';
234
235 if (dest + (end - start) >= rpath_limit)
236 {
237 ptrdiff_t dest_offset = dest - rpath;
238 char *new_rpath;
239
240 if (resolved)
241 {
242 __set_errno (ENAMETOOLONG);
243 if (dest > rpath + prefix_len + 1)
244 dest--;
245 *dest = '\0';
246 goto error;
247 }
248 new_size = rpath_limit - rpath;
249 if (end - start + 1 > path_max)
250 new_size += end - start + 1;
251 else
252 new_size += path_max;
253 new_rpath = (char *) realloc (rpath, new_size);
254 if (new_rpath == NULL)
255 {
256 alloc_failed ();
257 goto error;
258 }
259 rpath = new_rpath;
260 rpath_limit = rpath + new_size;
261
262 dest = rpath + dest_offset;
263 }
264
265#ifdef _LIBC
266 dest = __mempcpy (dest, start, end - start);
267#else
268 memcpy (dest, start, end - start);
269 dest += end - start;
270#endif
271 *dest = '\0';
272
273 /* FIXME: if lstat fails with errno == EOVERFLOW,
274 the entry exists. */
275#ifdef _LIBC
276 if (__lxstat64 (_STAT_VER, rpath, &st) < 0)
277#else
278 if (lstat (rpath, &st) < 0)
279#endif
280 goto error;
281
282 if (S_ISLNK (st.st_mode))
283 {
284 char *buf;
285 size_t len;
286 ssize_t n;
287
288 if (++num_links > MAXSYMLINKS)
289 {
290 __set_errno (ELOOP);
291 goto error;
292 }
293
294 buf = malloca (path_max);
295 if (!buf)
296 {
297 __set_errno (ENOMEM);
298 goto error;
299 }
300
301 n = __readlink (rpath, buf, path_max - 1);
302 if (n < 0)
303 {
304 int saved_errno = errno;
305 freea (buf);
306 __set_errno (saved_errno);
307 goto error;
308 }
309 buf[n] = '\0';
310
311 if (!extra_buf)
312 {
313 extra_buf = malloca (path_max);
314 if (!extra_buf)
315 {
316 freea (buf);
317 __set_errno (ENOMEM);
318 goto error;
319 }
320 }
321
322 len = strlen (end);
323 /* Check that n + len + 1 doesn't overflow and is <= path_max. */
324 if (n >= SIZE_MAX - len || n + len >= path_max)
325 {
326 freea (buf);
327 __set_errno (ENAMETOOLONG);
328 goto error;
329 }
330
331 /* Careful here, end may be a pointer into extra_buf... */
332 memmove (&extra_buf[n], end, len + 1);
333 name = end = memcpy (extra_buf, buf, n);
334
335 if (IS_ABSOLUTE_FILE_NAME (buf))
336 {
337 size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);
338
339 if (pfxlen)
340 memcpy (rpath, buf, pfxlen);
341 dest = rpath + pfxlen;
342 *dest++ = '/'; /* It's an absolute symlink */
343 if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
344 {
345 if (ISSLASH (buf[1]) && !ISSLASH (buf[2]) && !pfxlen)
346 *dest++ = '/';
347 *dest = '\0';
348 }
349 /* Install the new prefix to be in effect hereafter. */
350 prefix_len = pfxlen;
351 }
352 else
353 {
354 /* Back up to previous component, ignore if at root
355 already: */
356 if (dest > rpath + prefix_len + 1)
357 for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
358 continue;
359 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1
360 && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)
361 dest++;
362 }
363 }
364 else if (!S_ISDIR (st.st_mode) && *end != '\0')
365 {
366 __set_errno (ENOTDIR);
367 goto error;
368 }
369 }
370 }
371 if (dest > rpath + prefix_len + 1 && ISSLASH (dest[-1]))
372 --dest;
373 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && !prefix_len
374 && ISSLASH (*dest) && !ISSLASH (dest[1]))
375 dest++;
376 *dest = '\0';
377
378 if (extra_buf)
379 freea (extra_buf);
380
381 return rpath;
382
383error:
384 {
385 int saved_errno = errno;
386 if (extra_buf)
387 freea (extra_buf);
388 if (resolved == NULL)
389 free (rpath);
390 __set_errno (saved_errno);
391 }
392 return NULL;
393}
394versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
395#endif /* !FUNC_REALPATH_WORKS || defined _LIBC */
396
397
398#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3)
399char *
400attribute_compat_text_section
401__old_realpath (const char *name, char *resolved)
402{
403 if (resolved == NULL)
404 {
405 __set_errno (EINVAL);
406 return NULL;
407 }
408
409 return __realpath (name, resolved);
410}
411compat_symbol (libc, __old_realpath, realpath, GLIBC_2_0);
412#endif
413
414
415char *
416__canonicalize_file_name (const char *name)
417{
418 return __realpath (name, NULL);
419}
420weak_alias (__canonicalize_file_name, canonicalize_file_name)
421
422#else
423
424/* This declaration is solely to ensure that after preprocessing
425 this file is never empty. */
426typedef int dummy;
427
428#endif
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 6e817fa6897..d0bef0bd5de 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -72,6 +72,7 @@
72# byteswap \ 72# byteswap \
73# c-ctype \ 73# c-ctype \
74# c-strcase \ 74# c-strcase \
75# canonicalize-lgpl \
75# careadlinkat \ 76# careadlinkat \
76# close-stream \ 77# close-stream \
77# copy-file-range \ 78# copy-file-range \
@@ -484,6 +485,8 @@ GTK_CFLAGS = @GTK_CFLAGS@
484GTK_LIBS = @GTK_LIBS@ 485GTK_LIBS = @GTK_LIBS@
485GTK_OBJ = @GTK_OBJ@ 486GTK_OBJ = @GTK_OBJ@
486GZIP_PROG = @GZIP_PROG@ 487GZIP_PROG = @GZIP_PROG@
488HARFBUZZ_CFLAGS = @HARFBUZZ_CFLAGS@
489HARFBUZZ_LIBS = @HARFBUZZ_LIBS@
487HAVE_ALLOCA_H = @HAVE_ALLOCA_H@ 490HAVE_ALLOCA_H = @HAVE_ALLOCA_H@
488HAVE_ALPHASORT = @HAVE_ALPHASORT@ 491HAVE_ALPHASORT = @HAVE_ALPHASORT@
489HAVE_ATOLL = @HAVE_ATOLL@ 492HAVE_ATOLL = @HAVE_ATOLL@
@@ -1105,6 +1108,7 @@ pdfdir = @pdfdir@
1105prefix = @prefix@ 1108prefix = @prefix@
1106program_transform_name = @program_transform_name@ 1109program_transform_name = @program_transform_name@
1107psdir = @psdir@ 1110psdir = @psdir@
1111runstatedir = @runstatedir@
1108sbindir = @sbindir@ 1112sbindir = @sbindir@
1109sharedstatedir = @sharedstatedir@ 1113sharedstatedir = @sharedstatedir@
1110srcdir = @srcdir@ 1114srcdir = @srcdir@
@@ -1243,6 +1247,17 @@ libgnu_a_SOURCES += c-strcase.h c-strcasecmp.c c-strncasecmp.c
1243endif 1247endif
1244## end gnulib module c-strcase 1248## end gnulib module c-strcase
1245 1249
1250## begin gnulib module canonicalize-lgpl
1251ifeq (,$(OMIT_GNULIB_MODULE_canonicalize-lgpl))
1252
1253
1254EXTRA_DIST += canonicalize-lgpl.c
1255
1256EXTRA_libgnu_a_SOURCES += canonicalize-lgpl.c
1257
1258endif
1259## end gnulib module canonicalize-lgpl
1260
1246## begin gnulib module careadlinkat 1261## begin gnulib module careadlinkat
1247ifeq (,$(OMIT_GNULIB_MODULE_careadlinkat)) 1262ifeq (,$(OMIT_GNULIB_MODULE_careadlinkat))
1248 1263
@@ -1980,6 +1995,18 @@ EXTRA_libgnu_a_SOURCES += lstat.c
1980endif 1995endif
1981## end gnulib module lstat 1996## end gnulib module lstat
1982 1997
1998## begin gnulib module malloca
1999ifeq (,$(OMIT_GNULIB_MODULE_malloca))
2000
2001ifneq (,$(gl_GNULIB_ENABLED_malloca))
2002libgnu_a_SOURCES += malloca.c
2003
2004endif
2005EXTRA_DIST += malloca.h
2006
2007endif
2008## end gnulib module malloca
2009
1983## begin gnulib module memmem-simple 2010## begin gnulib module memmem-simple
1984ifeq (,$(OMIT_GNULIB_MODULE_memmem-simple)) 2011ifeq (,$(OMIT_GNULIB_MODULE_memmem-simple))
1985 2012
@@ -2079,6 +2106,17 @@ EXTRA_DIST += openat.h
2079endif 2106endif
2080## end gnulib module openat-h 2107## end gnulib module openat-h
2081 2108
2109## begin gnulib module pathmax
2110ifeq (,$(OMIT_GNULIB_MODULE_pathmax))
2111
2112ifneq (,$(gl_GNULIB_ENABLED_pathmax))
2113
2114endif
2115EXTRA_DIST += pathmax.h
2116
2117endif
2118## end gnulib module pathmax
2119
2082## begin gnulib module pipe2 2120## begin gnulib module pipe2
2083ifeq (,$(OMIT_GNULIB_MODULE_pipe2)) 2121ifeq (,$(OMIT_GNULIB_MODULE_pipe2))
2084 2122
diff --git a/lib/malloca.c b/lib/malloca.c
new file mode 100644
index 00000000000..f60c5fb5d93
--- /dev/null
+++ b/lib/malloca.c
@@ -0,0 +1,105 @@
1/* Safe automatic memory allocation.
2 Copyright (C) 2003, 2006-2007, 2009-2019 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2003, 2018.
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#define _GL_USE_STDLIB_ALLOC 1
19#include <config.h>
20
21/* Specification. */
22#include "malloca.h"
23
24#include "verify.h"
25
26/* The speed critical point in this file is freea() applied to an alloca()
27 result: it must be fast, to match the speed of alloca(). The speed of
28 mmalloca() and freea() in the other case are not critical, because they
29 are only invoked for big memory sizes.
30 Here we use a bit in the address as an indicator, an idea by Ondřej Bílka.
31 malloca() can return three types of pointers:
32 - Pointers ≡ 0 mod 2*sa_alignment_max come from stack allocation.
33 - Pointers ≡ sa_alignment_max mod 2*sa_alignment_max come from heap
34 allocation.
35 - NULL comes from a failed heap allocation. */
36
37/* Type for holding very small pointer differences. */
38typedef unsigned char small_t;
39/* Verify that it is wide enough. */
40verify (2 * sa_alignment_max - 1 <= (small_t) -1);
41
42void *
43mmalloca (size_t n)
44{
45#if HAVE_ALLOCA
46 /* Allocate one more word, used to determine the address to pass to freea(),
47 and room for the alignment ≡ sa_alignment_max mod 2*sa_alignment_max. */
48 size_t nplus = n + sizeof (small_t) + 2 * sa_alignment_max - 1;
49
50 if (nplus >= n)
51 {
52 char *mem = (char *) malloc (nplus);
53
54 if (mem != NULL)
55 {
56 char *p =
57 (char *)((((uintptr_t)mem + sizeof (small_t) + sa_alignment_max - 1)
58 & ~(uintptr_t)(2 * sa_alignment_max - 1))
59 + sa_alignment_max);
60 /* Here p >= mem + sizeof (small_t),
61 and p <= mem + sizeof (small_t) + 2 * sa_alignment_max - 1
62 hence p + n <= mem + nplus.
63 So, the memory range [p, p+n) lies in the allocated memory range
64 [mem, mem + nplus). */
65 ((small_t *) p)[-1] = p - mem;
66 /* p ≡ sa_alignment_max mod 2*sa_alignment_max. */
67 return p;
68 }
69 }
70 /* Out of memory. */
71 return NULL;
72#else
73# if !MALLOC_0_IS_NONNULL
74 if (n == 0)
75 n = 1;
76# endif
77 return malloc (n);
78#endif
79}
80
81#if HAVE_ALLOCA
82void
83freea (void *p)
84{
85 /* Check argument. */
86 if ((uintptr_t) p & (sa_alignment_max - 1))
87 {
88 /* p was not the result of a malloca() call. Invalid argument. */
89 abort ();
90 }
91 /* Determine whether p was a non-NULL pointer returned by mmalloca(). */
92 if ((uintptr_t) p & sa_alignment_max)
93 {
94 void *mem = (char *) p - ((small_t *) p)[-1];
95 free (mem);
96 }
97}
98#endif
99
100/*
101 * Hey Emacs!
102 * Local Variables:
103 * coding: utf-8
104 * End:
105 */
diff --git a/lib/malloca.h b/lib/malloca.h
new file mode 100644
index 00000000000..d80c316caa9
--- /dev/null
+++ b/lib/malloca.h
@@ -0,0 +1,127 @@
1/* Safe automatic memory allocation.
2 Copyright (C) 2003-2007, 2009-2019 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2003.
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 _MALLOCA_H
19#define _MALLOCA_H
20
21#include <alloca.h>
22#include <stddef.h>
23#include <stdlib.h>
24#include <stdint.h>
25
26#include "xalloc-oversized.h"
27
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33
34/* safe_alloca(N) is equivalent to alloca(N) when it is safe to call
35 alloca(N); otherwise it returns NULL. It either returns N bytes of
36 memory allocated on the stack, that lasts until the function returns,
37 or NULL.
38 Use of safe_alloca should be avoided:
39 - inside arguments of function calls - undefined behaviour,
40 - in inline functions - the allocation may actually last until the
41 calling function returns.
42*/
43#if HAVE_ALLOCA
44/* The OS usually guarantees only one guard page at the bottom of the stack,
45 and a page size can be as small as 4096 bytes. So we cannot safely
46 allocate anything larger than 4096 bytes. Also care for the possibility
47 of a few compiler-allocated temporary stack slots.
48 This must be a macro, not a function. */
49# define safe_alloca(N) ((N) < 4032 ? alloca (N) : NULL)
50#else
51# define safe_alloca(N) ((void) (N), NULL)
52#endif
53
54/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
55 memory allocated on the stack, that must be freed using freea() before
56 the function returns. Upon failure, it returns NULL. */
57#if HAVE_ALLOCA
58# define malloca(N) \
59 ((N) < 4032 - (2 * sa_alignment_max - 1) \
60 ? (void *) (((uintptr_t) (char *) alloca ((N) + 2 * sa_alignment_max - 1) \
61 + (2 * sa_alignment_max - 1)) \
62 & ~(uintptr_t)(2 * sa_alignment_max - 1)) \
63 : mmalloca (N))
64#else
65# define malloca(N) \
66 mmalloca (N)
67#endif
68extern void * mmalloca (size_t n);
69
70/* Free a block of memory allocated through malloca(). */
71#if HAVE_ALLOCA
72extern void freea (void *p);
73#else
74# define freea free
75#endif
76
77/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
78 It allocates an array of N objects, each with S bytes of memory,
79 on the stack. S must be positive and N must be nonnegative.
80 The array must be freed using freea() before the function returns. */
81#define nmalloca(n, s) (xalloc_oversized (n, s) ? NULL : malloca ((n) * (s)))
82
83
84#ifdef __cplusplus
85}
86#endif
87
88
89/* ------------------- Auxiliary, non-public definitions ------------------- */
90
91/* Determine the alignment of a type at compile time. */
92#if defined __GNUC__ || defined __IBM__ALIGNOF__
93# define sa_alignof __alignof__
94#elif defined __cplusplus
95 template <class type> struct sa_alignof_helper { char __slot1; type __slot2; };
96# define sa_alignof(type) offsetof (sa_alignof_helper<type>, __slot2)
97#elif defined __hpux
98 /* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
99 values. */
100# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
101#elif defined _AIX
102 /* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
103 values. */
104# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
105#else
106# define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
107#endif
108
109enum
110{
111/* The desired alignment of memory allocations is the maximum alignment
112 among all elementary types. */
113 sa_alignment_long = sa_alignof (long),
114 sa_alignment_double = sa_alignof (double),
115#if HAVE_LONG_LONG_INT
116 sa_alignment_longlong = sa_alignof (long long),
117#endif
118 sa_alignment_longdouble = sa_alignof (long double),
119 sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
120#if HAVE_LONG_LONG_INT
121 | (sa_alignment_longlong - 1)
122#endif
123 | (sa_alignment_longdouble - 1)
124 ) + 1
125};
126
127#endif /* _MALLOCA_H */
diff --git a/lib/pathmax.h b/lib/pathmax.h
new file mode 100644
index 00000000000..9463a1fb2c6
--- /dev/null
+++ b/lib/pathmax.h
@@ -0,0 +1,83 @@
1/* Define PATH_MAX somehow. Requires sys/types.h.
2 Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2019 Free Software
3 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 _PATHMAX_H
19# define _PATHMAX_H
20
21/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
22 including the terminating NUL byte.
23 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
24 PATH_MAX is not defined on systems which have no limit on filename length,
25 such as GNU/Hurd.
26
27 This file does *not* define PATH_MAX always. Programs that use this file
28 can handle the GNU/Hurd case in several ways:
29 - Either with a package-wide handling, or with a per-file handling,
30 - Either through a
31 #ifdef PATH_MAX
32 or through a fallback like
33 #ifndef PATH_MAX
34 # define PATH_MAX 8192
35 #endif
36 or through a fallback like
37 #ifndef PATH_MAX
38 # define PATH_MAX pathconf ("/", _PC_PATH_MAX)
39 #endif
40 */
41
42# include <unistd.h>
43
44# include <limits.h>
45
46# ifndef _POSIX_PATH_MAX
47# define _POSIX_PATH_MAX 256
48# endif
49
50/* Don't include sys/param.h if it already has been. */
51# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
52# include <sys/param.h>
53# endif
54
55# if !defined PATH_MAX && defined MAXPATHLEN
56# define PATH_MAX MAXPATHLEN
57# endif
58
59# ifdef __hpux
60/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
61 *not* including the terminating NUL byte, and is set to 1023.
62 Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
63 not defined at all any more. */
64# undef PATH_MAX
65# define PATH_MAX 1024
66# endif
67
68# if defined _WIN32 && ! defined __CYGWIN__
69/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
70 section "Maximum Path Length Limitation",
71 <https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation>
72 explains that the maximum size of a filename, including the terminating
73 NUL byte, is 260 = 3 + 256 + 1.
74 This is the same value as
75 - FILENAME_MAX in <stdio.h>,
76 - _MAX_PATH in <stdlib.h>,
77 - MAX_PATH in <windef.h>.
78 Undefine the original value, because mingw's <limits.h> gets it wrong. */
79# undef PATH_MAX
80# define PATH_MAX 260
81# endif
82
83#endif /* _PATHMAX_H */
diff --git a/m4/canonicalize.m4 b/m4/canonicalize.m4
new file mode 100644
index 00000000000..b61747bd1a5
--- /dev/null
+++ b/m4/canonicalize.m4
@@ -0,0 +1,133 @@
1# canonicalize.m4 serial 30
2
3dnl Copyright (C) 2003-2007, 2009-2019 Free Software Foundation, Inc.
4
5dnl This file is free software; the Free Software Foundation
6dnl gives unlimited permission to copy and/or distribute it,
7dnl with or without modifications, as long as this notice is preserved.
8
9# Provides canonicalize_file_name and canonicalize_filename_mode, but does
10# not provide or fix realpath.
11AC_DEFUN([gl_FUNC_CANONICALIZE_FILENAME_MODE],
12[
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 AC_CHECK_FUNCS_ONCE([canonicalize_file_name])
15 AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
16 AC_REQUIRE([gl_FUNC_REALPATH_WORKS])
17 if test $ac_cv_func_canonicalize_file_name = no; then
18 HAVE_CANONICALIZE_FILE_NAME=0
19 else
20 case "$gl_cv_func_realpath_works" in
21 *yes) ;;
22 *) REPLACE_CANONICALIZE_FILE_NAME=1 ;;
23 esac
24 fi
25])
26
27# Provides canonicalize_file_name and realpath.
28AC_DEFUN([gl_CANONICALIZE_LGPL],
29[
30 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
31 AC_REQUIRE([gl_CANONICALIZE_LGPL_SEPARATE])
32 if test $ac_cv_func_canonicalize_file_name = no; then
33 HAVE_CANONICALIZE_FILE_NAME=0
34 if test $ac_cv_func_realpath = no; then
35 HAVE_REALPATH=0
36 else
37 case "$gl_cv_func_realpath_works" in
38 *yes) ;;
39 *) REPLACE_REALPATH=1 ;;
40 esac
41 fi
42 else
43 case "$gl_cv_func_realpath_works" in
44 *yes)
45 ;;
46 *)
47 REPLACE_CANONICALIZE_FILE_NAME=1
48 REPLACE_REALPATH=1
49 ;;
50 esac
51 fi
52])
53
54# Like gl_CANONICALIZE_LGPL, except prepare for separate compilation
55# (no REPLACE_CANONICALIZE_FILE_NAME, no REPLACE_REALPATH, no AC_LIBOBJ).
56AC_DEFUN([gl_CANONICALIZE_LGPL_SEPARATE],
57[
58 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
59 AC_CHECK_FUNCS_ONCE([canonicalize_file_name getcwd readlink])
60 AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
61 AC_REQUIRE([gl_FUNC_REALPATH_WORKS])
62 AC_CHECK_HEADERS_ONCE([sys/param.h])
63])
64
65# Check whether realpath works. Assume that if a platform has both
66# realpath and canonicalize_file_name, but the former is broken, then
67# so is the latter.
68AC_DEFUN([gl_FUNC_REALPATH_WORKS],
69[
70 AC_CHECK_FUNCS_ONCE([realpath])
71 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
72 AC_CACHE_CHECK([whether realpath works], [gl_cv_func_realpath_works], [
73 touch conftest.a
74 mkdir conftest.d
75 AC_RUN_IFELSE([
76 AC_LANG_PROGRAM([[
77 ]GL_NOCRASH[
78 #include <stdlib.h>
79 #include <string.h>
80 ]], [[
81 int result = 0;
82 {
83 char *name = realpath ("conftest.a", NULL);
84 if (!(name && *name == '/'))
85 result |= 1;
86 free (name);
87 }
88 {
89 char *name = realpath ("conftest.b/../conftest.a", NULL);
90 if (name != NULL)
91 result |= 2;
92 free (name);
93 }
94 {
95 char *name = realpath ("conftest.a/", NULL);
96 if (name != NULL)
97 result |= 4;
98 free (name);
99 }
100 {
101 char *name1 = realpath (".", NULL);
102 char *name2 = realpath ("conftest.d//./..", NULL);
103 if (! name1 || ! name2 || strcmp (name1, name2))
104 result |= 8;
105 free (name1);
106 free (name2);
107 }
108 return result;
109 ]])
110 ],
111 [gl_cv_func_realpath_works=yes],
112 [gl_cv_func_realpath_works=no],
113 [case "$host_os" in
114 # Guess yes on glibc systems.
115 *-gnu* | gnu*) gl_cv_func_realpath_works="guessing yes" ;;
116 # Guess yes on musl systems.
117 *-musl*) gl_cv_func_realpath_works="guessing yes" ;;
118 # Guess no on native Windows.
119 mingw*) gl_cv_func_realpath_works="guessing no" ;;
120 # If we don't know, assume the worst.
121 *) gl_cv_func_realpath_works="guessing no" ;;
122 esac
123 ])
124 rm -rf conftest.a conftest.d
125 ])
126 case "$gl_cv_func_realpath_works" in
127 *yes)
128 AC_DEFINE([FUNC_REALPATH_WORKS], [1], [Define to 1 if realpath()
129 can malloc memory, always gives an absolute path, and handles
130 trailing slash correctly.])
131 ;;
132 esac
133])
diff --git a/m4/double-slash-root.m4 b/m4/double-slash-root.m4
new file mode 100644
index 00000000000..0c5afb17156
--- /dev/null
+++ b/m4/double-slash-root.m4
@@ -0,0 +1,38 @@
1# double-slash-root.m4 serial 4 -*- Autoconf -*-
2dnl Copyright (C) 2006, 2008-2019 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_DOUBLE_SLASH_ROOT],
8[
9 AC_REQUIRE([AC_CANONICAL_HOST])
10 AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root],
11 [ if test x"$cross_compiling" = xyes ; then
12 # When cross-compiling, there is no way to tell whether // is special
13 # short of a list of hosts. However, the only known hosts to date
14 # that have a distinct // are Apollo DomainOS (too old to port to),
15 # Cygwin, and z/OS. If anyone knows of another system for which // has
16 # special semantics and is distinct from /, please report it to
17 # <bug-gnulib@gnu.org>.
18 case $host in
19 *-cygwin | i370-ibm-openedition)
20 gl_cv_double_slash_root=yes ;;
21 *)
22 # Be optimistic and assume that / and // are the same when we
23 # don't know.
24 gl_cv_double_slash_root='unknown, assuming no' ;;
25 esac
26 else
27 set x `ls -di / // 2>/dev/null`
28 if test "$[2]" = "$[4]" && wc //dev/null >/dev/null 2>&1; then
29 gl_cv_double_slash_root=no
30 else
31 gl_cv_double_slash_root=yes
32 fi
33 fi])
34 if test "$gl_cv_double_slash_root" = yes; then
35 AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], [1],
36 [Define to 1 if // is a file system root distinct from /.])
37 fi
38])
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 4627575bf63..cb6dce15ccf 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -52,6 +52,7 @@ AC_DEFUN([gl_EARLY],
52 # Code from module byteswap: 52 # Code from module byteswap:
53 # Code from module c-ctype: 53 # Code from module c-ctype:
54 # Code from module c-strcase: 54 # Code from module c-strcase:
55 # Code from module canonicalize-lgpl:
55 # Code from module careadlinkat: 56 # Code from module careadlinkat:
56 # Code from module clock-time: 57 # Code from module clock-time:
57 # Code from module cloexec: 58 # Code from module cloexec:
@@ -113,6 +114,7 @@ AC_DEFUN([gl_EARLY],
113 # Code from module limits-h: 114 # Code from module limits-h:
114 # Code from module localtime-buffer: 115 # Code from module localtime-buffer:
115 # Code from module lstat: 116 # Code from module lstat:
117 # Code from module malloca:
116 # Code from module manywarnings: 118 # Code from module manywarnings:
117 # Code from module memmem-simple: 119 # Code from module memmem-simple:
118 # Code from module memrchr: 120 # Code from module memrchr:
@@ -125,6 +127,7 @@ AC_DEFUN([gl_EARLY],
125 # Code from module nstrftime: 127 # Code from module nstrftime:
126 # Code from module open: 128 # Code from module open:
127 # Code from module openat-h: 129 # Code from module openat-h:
130 # Code from module pathmax:
128 # Code from module pipe2: 131 # Code from module pipe2:
129 # Code from module pselect: 132 # Code from module pselect:
130 # Code from module pthread_sigmask: 133 # Code from module pthread_sigmask:
@@ -199,6 +202,13 @@ AC_DEFUN([gl_INIT],
199 gl_FUNC_ALLOCA 202 gl_FUNC_ALLOCA
200 gl___BUILTIN_EXPECT 203 gl___BUILTIN_EXPECT
201 gl_BYTESWAP 204 gl_BYTESWAP
205 gl_CANONICALIZE_LGPL
206 if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then
207 AC_LIBOBJ([canonicalize-lgpl])
208 fi
209 gl_MODULE_INDICATOR([canonicalize-lgpl])
210 gl_STDLIB_MODULE_INDICATOR([canonicalize_file_name])
211 gl_STDLIB_MODULE_INDICATOR([realpath])
202 AC_CHECK_FUNCS_ONCE([readlinkat]) 212 AC_CHECK_FUNCS_ONCE([readlinkat])
203 gl_CLOCK_TIME 213 gl_CLOCK_TIME
204 gl_MODULE_INDICATOR([close-stream]) 214 gl_MODULE_INDICATOR([close-stream])
@@ -447,9 +457,11 @@ AC_DEFUN([gl_INIT],
447 gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=false 457 gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=false
448 gl_gnulib_enabled_21ee726a3540c09237a8e70c0baf7467=false 458 gl_gnulib_enabled_21ee726a3540c09237a8e70c0baf7467=false
449 gl_gnulib_enabled_2049e887c7e5308faad27b3f894bb8c9=false 459 gl_gnulib_enabled_2049e887c7e5308faad27b3f894bb8c9=false
460 gl_gnulib_enabled_malloca=false
450 gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31=false 461 gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31=false
451 gl_gnulib_enabled_open=false 462 gl_gnulib_enabled_open=false
452 gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=false 463 gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=false
464 gl_gnulib_enabled_pathmax=false
453 gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=false 465 gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=false
454 gl_gnulib_enabled_strtoll=false 466 gl_gnulib_enabled_strtoll=false
455 gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=false 467 gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=false
@@ -561,6 +573,14 @@ AC_DEFUN([gl_INIT],
561 gl_gnulib_enabled_2049e887c7e5308faad27b3f894bb8c9=true 573 gl_gnulib_enabled_2049e887c7e5308faad27b3f894bb8c9=true
562 fi 574 fi
563 } 575 }
576 func_gl_gnulib_m4code_malloca ()
577 {
578 if ! $gl_gnulib_enabled_malloca; then
579 gl_MALLOCA
580 gl_gnulib_enabled_malloca=true
581 func_gl_gnulib_m4code_682e609604ccaac6be382e4ee3a4eaec
582 fi
583 }
564 func_gl_gnulib_m4code_5264294aa0a5557541b53c8c741f7f31 () 584 func_gl_gnulib_m4code_5264294aa0a5557541b53c8c741f7f31 ()
565 { 585 {
566 if ! $gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31; then 586 if ! $gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31; then
@@ -593,6 +613,13 @@ AC_DEFUN([gl_INIT],
593 gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=true 613 gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=true
594 fi 614 fi
595 } 615 }
616 func_gl_gnulib_m4code_pathmax ()
617 {
618 if ! $gl_gnulib_enabled_pathmax; then
619 gl_PATHMAX
620 gl_gnulib_enabled_pathmax=true
621 fi
622 }
596 func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c () 623 func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c ()
597 { 624 {
598 if ! $gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c; then 625 if ! $gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c; then
@@ -617,6 +644,12 @@ AC_DEFUN([gl_INIT],
617 gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=true 644 gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=true
618 fi 645 fi
619 } 646 }
647 if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then
648 func_gl_gnulib_m4code_malloca
649 fi
650 if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then
651 func_gl_gnulib_m4code_pathmax
652 fi
620 if test $HAVE_FACCESSAT = 0 || test $REPLACE_FACCESSAT = 1; then 653 if test $HAVE_FACCESSAT = 0 || test $REPLACE_FACCESSAT = 1; then
621 func_gl_gnulib_m4code_260941c0e5dc67ec9e87d1fb321c300b 654 func_gl_gnulib_m4code_260941c0e5dc67ec9e87d1fb321c300b
622 fi 655 fi
@@ -676,9 +709,11 @@ AC_DEFUN([gl_INIT],
676 AM_CONDITIONAL([gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1], [$gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1]) 709 AM_CONDITIONAL([gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1], [$gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1])
677 AM_CONDITIONAL([gl_GNULIB_ENABLED_21ee726a3540c09237a8e70c0baf7467], [$gl_gnulib_enabled_21ee726a3540c09237a8e70c0baf7467]) 710 AM_CONDITIONAL([gl_GNULIB_ENABLED_21ee726a3540c09237a8e70c0baf7467], [$gl_gnulib_enabled_21ee726a3540c09237a8e70c0baf7467])
678 AM_CONDITIONAL([gl_GNULIB_ENABLED_2049e887c7e5308faad27b3f894bb8c9], [$gl_gnulib_enabled_2049e887c7e5308faad27b3f894bb8c9]) 711 AM_CONDITIONAL([gl_GNULIB_ENABLED_2049e887c7e5308faad27b3f894bb8c9], [$gl_gnulib_enabled_2049e887c7e5308faad27b3f894bb8c9])
712 AM_CONDITIONAL([gl_GNULIB_ENABLED_malloca], [$gl_gnulib_enabled_malloca])
679 AM_CONDITIONAL([gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31], [$gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31]) 713 AM_CONDITIONAL([gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31], [$gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31])
680 AM_CONDITIONAL([gl_GNULIB_ENABLED_open], [$gl_gnulib_enabled_open]) 714 AM_CONDITIONAL([gl_GNULIB_ENABLED_open], [$gl_gnulib_enabled_open])
681 AM_CONDITIONAL([gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7], [$gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7]) 715 AM_CONDITIONAL([gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7], [$gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7])
716 AM_CONDITIONAL([gl_GNULIB_ENABLED_pathmax], [$gl_gnulib_enabled_pathmax])
682 AM_CONDITIONAL([gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c], [$gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c]) 717 AM_CONDITIONAL([gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c], [$gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c])
683 AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll]) 718 AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll])
684 AM_CONDITIONAL([gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec], [$gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec]) 719 AM_CONDITIONAL([gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec], [$gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec])
@@ -845,6 +880,7 @@ AC_DEFUN([gl_FILE_LIST], [
845 lib/c-strcase.h 880 lib/c-strcase.h
846 lib/c-strcasecmp.c 881 lib/c-strcasecmp.c
847 lib/c-strncasecmp.c 882 lib/c-strncasecmp.c
883 lib/canonicalize-lgpl.c
848 lib/careadlinkat.c 884 lib/careadlinkat.c
849 lib/careadlinkat.h 885 lib/careadlinkat.h
850 lib/cdefs.h 886 lib/cdefs.h
@@ -915,6 +951,8 @@ AC_DEFUN([gl_FILE_LIST], [
915 lib/localtime-buffer.c 951 lib/localtime-buffer.c
916 lib/localtime-buffer.h 952 lib/localtime-buffer.h
917 lib/lstat.c 953 lib/lstat.c
954 lib/malloca.c
955 lib/malloca.h
918 lib/md5.c 956 lib/md5.c
919 lib/md5.h 957 lib/md5.h
920 lib/memmem.c 958 lib/memmem.c
@@ -928,6 +966,7 @@ AC_DEFUN([gl_FILE_LIST], [
928 lib/openat-priv.h 966 lib/openat-priv.h
929 lib/openat-proc.c 967 lib/openat-proc.c
930 lib/openat.h 968 lib/openat.h
969 lib/pathmax.h
931 lib/pipe2.c 970 lib/pipe2.c
932 lib/pselect.c 971 lib/pselect.c
933 lib/pthread_sigmask.c 972 lib/pthread_sigmask.c
@@ -1001,6 +1040,7 @@ AC_DEFUN([gl_FILE_LIST], [
1001 m4/alloca.m4 1040 m4/alloca.m4
1002 m4/builtin-expect.m4 1041 m4/builtin-expect.m4
1003 m4/byteswap.m4 1042 m4/byteswap.m4
1043 m4/canonicalize.m4
1004 m4/clock_time.m4 1044 m4/clock_time.m4
1005 m4/copy-file-range.m4 1045 m4/copy-file-range.m4
1006 m4/count-leading-zeros.m4 1046 m4/count-leading-zeros.m4
@@ -1009,6 +1049,7 @@ AC_DEFUN([gl_FILE_LIST], [
1009 m4/d-type.m4 1049 m4/d-type.m4
1010 m4/dirent_h.m4 1050 m4/dirent_h.m4
1011 m4/dirfd.m4 1051 m4/dirfd.m4
1052 m4/double-slash-root.m4
1012 m4/dup2.m4 1053 m4/dup2.m4
1013 m4/eealloc.m4 1054 m4/eealloc.m4
1014 m4/environ.m4 1055 m4/environ.m4
@@ -1048,6 +1089,7 @@ AC_DEFUN([gl_FILE_LIST], [
1048 m4/localtime-buffer.m4 1089 m4/localtime-buffer.m4
1049 m4/longlong.m4 1090 m4/longlong.m4
1050 m4/lstat.m4 1091 m4/lstat.m4
1092 m4/malloca.m4
1051 m4/manywarnings-c++.m4 1093 m4/manywarnings-c++.m4
1052 m4/manywarnings.m4 1094 m4/manywarnings.m4
1053 m4/mbstate_t.m4 1095 m4/mbstate_t.m4
@@ -1064,6 +1106,7 @@ AC_DEFUN([gl_FILE_LIST], [
1064 m4/off_t.m4 1106 m4/off_t.m4
1065 m4/open-cloexec.m4 1107 m4/open-cloexec.m4
1066 m4/open.m4 1108 m4/open.m4
1109 m4/pathmax.m4
1067 m4/pipe2.m4 1110 m4/pipe2.m4
1068 m4/pselect.m4 1111 m4/pselect.m4
1069 m4/pthread_sigmask.m4 1112 m4/pthread_sigmask.m4
diff --git a/m4/malloca.m4 b/m4/malloca.m4
new file mode 100644
index 00000000000..820f40a8a88
--- /dev/null
+++ b/m4/malloca.m4
@@ -0,0 +1,15 @@
1# malloca.m4 serial 1
2dnl Copyright (C) 2003-2004, 2006-2007, 2009-2019 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8AC_DEFUN([gl_MALLOCA],
9[
10 dnl Use the autoconf tests for alloca(), but not the AC_SUBSTed variables
11 dnl @ALLOCA@ and @LTALLOCA@.
12 dnl gl_FUNC_ALLOCA dnl Already brought in by the module dependencies.
13 AC_REQUIRE([gl_EEMALLOC])
14 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
15])
diff --git a/m4/pathmax.m4 b/m4/pathmax.m4
new file mode 100644
index 00000000000..0770aca3aac
--- /dev/null
+++ b/m4/pathmax.m4
@@ -0,0 +1,42 @@
1# pathmax.m4 serial 11
2dnl Copyright (C) 2002-2003, 2005-2006, 2009-2019 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8AC_DEFUN([gl_PATHMAX],
9[
10 dnl Prerequisites of lib/pathmax.h.
11 AC_CHECK_HEADERS_ONCE([sys/param.h])
12])
13
14# Expands to a piece of C program that defines PATH_MAX in the same way as
15# "pathmax.h" will do.
16AC_DEFUN([gl_PATHMAX_SNIPPET], [[
17/* Arrange to define PATH_MAX, like "pathmax.h" does. */
18#if HAVE_UNISTD_H
19# include <unistd.h>
20#endif
21#include <limits.h>
22#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
23# include <sys/param.h>
24#endif
25#if !defined PATH_MAX && defined MAXPATHLEN
26# define PATH_MAX MAXPATHLEN
27#endif
28#ifdef __hpux
29# undef PATH_MAX
30# define PATH_MAX 1024
31#endif
32#if defined _WIN32 && ! defined __CYGWIN__
33# undef PATH_MAX
34# define PATH_MAX 260
35#endif
36]])
37
38# Prerequisites of gl_PATHMAX_SNIPPET.
39AC_DEFUN([gl_PATHMAX_SNIPPET_PREREQ],
40[
41 AC_CHECK_HEADERS_ONCE([unistd.h sys/param.h])
42])
diff --git a/src/emacs.c b/src/emacs.c
index fd46540ce22..6463c1be1b7 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -709,9 +709,6 @@ load_pdump (int argc, char **argv)
709{ 709{
710 const char *const suffix = ".pdmp"; 710 const char *const suffix = ".pdmp";
711 enum pdumper_load_result result; 711 enum pdumper_load_result result;
712#ifdef WINDOWSNT
713 size_t argv0_len;
714#endif
715 712
716 /* TODO: maybe more thoroughly scrub process environment in order to 713 /* TODO: maybe more thoroughly scrub process environment in order to
717 make this use case (loading a pdumper image in an unexeced emacs) 714 make this use case (loading a pdumper image in an unexeced emacs)
@@ -747,17 +744,23 @@ load_pdump (int argc, char **argv)
747 } 744 }
748 745
749 /* Look for a dump file in the same directory as the executable; it 746 /* Look for a dump file in the same directory as the executable; it
750 should have the same basename. */ 747 should have the same basename. If the directory name is, however,
748 a symbolic link, resolve the symbolic symbolic link first. */
749
750 char* argv0 = realpath (argv[0], NULL);
751 if (!argv0)
752 fatal ("could not resolve realpath of \"%s\": %s",
753 argv0, strerror (errno));
751 754
752 dump_file = alloca (strlen (argv[0]) + strlen (suffix) + 1); 755 dump_file = alloca (strlen (argv0) + strlen (suffix) + 1);
753#ifdef DOS_NT 756#ifdef DOS_NT
754 /* Remove the .exe extension if present. */ 757 /* Remove the .exe extension if present. */
755 argv0_len = strlen (argv[0]); 758 size_t argv0_len = strlen (argv0);
756 if (argv0_len >= 4 && c_strcasecmp (argv[0] + argv0_len - 4, ".exe") == 0) 759 if (argv0_len >= 4 && c_strcasecmp (argv0 + argv0_len - 4, ".exe") == 0)
757 sprintf (dump_file, "%.*s%s", (int)(argv0_len - 4), argv[0], suffix); 760 sprintf (dump_file, "%.*s%s", (int)(argv0_len - 4), argv0, suffix);
758 else 761 else
759#endif 762#endif
760 sprintf (dump_file, "%s%s", argv[0], suffix); 763 sprintf (dump_file, "%s%s", argv0, suffix);
761 764
762 result = pdumper_load (dump_file); 765 result = pdumper_load (dump_file);
763 if (result == PDUMPER_LOAD_SUCCESS) 766 if (result == PDUMPER_LOAD_SUCCESS)
@@ -790,17 +793,17 @@ load_pdump (int argc, char **argv)
790 793
791 if (result == PDUMPER_LOAD_FILE_NOT_FOUND) 794 if (result == PDUMPER_LOAD_FILE_NOT_FOUND)
792 { 795 {
793 /* Finally, look for basename(argv[0])+".pdmp" in PATH_EXEC. 796 /* Finally, look for basename(argv0)+".pdmp" in PATH_EXEC.
794 This way, they can rename both the executable and its pdump 797 This way, they can rename both the executable and its pdump
795 file in PATH_EXEC, and have several Emacs configurations in 798 file in PATH_EXEC, and have several Emacs configurations in
796 the same versioned libexec subdirectory. */ 799 the same versioned libexec subdirectory. */
797 char *p, *last_sep = NULL; 800 char *p, *last_sep = NULL;
798 for (p = argv[0]; *p; p++) 801 for (p = argv0; *p; p++)
799 { 802 {
800 if (IS_DIRECTORY_SEP (*p)) 803 if (IS_DIRECTORY_SEP (*p))
801 last_sep = p; 804 last_sep = p;
802 } 805 }
803 argv0_base = last_sep ? last_sep + 1 : argv[0]; 806 argv0_base = last_sep ? last_sep + 1 : argv0;
804 dump_file = alloca (strlen (path_exec) 807 dump_file = alloca (strlen (path_exec)
805 + 1 808 + 1
806 + strlen (argv0_base) 809 + strlen (argv0_base)