1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-23 10:34:07 +00:00

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
This commit is contained in:
Daniel Colascione 2019-06-23 18:19:08 -07:00
parent f3b1b5fb50
commit b9ac4f815e
15 changed files with 1137 additions and 39 deletions

View File

@ -29,6 +29,7 @@ GNULIB_MODULES='
alloca-opt binary-io byteswap c-ctype c-strcase
careadlinkat close-stream copy-file-range
count-leading-zeros count-one-bits count-trailing-zeros
canonicalize-lgpl
crypto/md5-buffer crypto/sha1-buffer crypto/sha256-buffer crypto/sha512-buffer
d-type diffseq dosname dtoastr dtotimespec dup2
environ execinfo explicit_bzero faccessat

View File

@ -2,7 +2,7 @@
# Attempt to guess a canonical system name.
# Copyright 1992-2019 Free Software Foundation, Inc.
timestamp='2019-05-28'
timestamp='2019-06-10'
# This file is free software; you can redistribute it and/or modify it
# 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
*:SolidBSD:*:*)
echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE"
exit ;;
*:OS108:*:*)
echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE"
exit ;;
macppc:MirBSD:*:*)
echo powerpc-unknown-mirbsd"$UNAME_RELEASE"
exit ;;

View File

@ -1,31 +1,46 @@
eval '(exit $?0)' && eval 'exec perl -wS "$0" "$@"'
& eval 'exec perl -wS "$0" $argv:q'
if 0;
#!/bin/sh
#! -*-perl-*-
# Convert git log output to ChangeLog format.
# Copyright (C) 2008-2019 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Written by Jim Meyering
# This is a prologue that allows to run a perl script as an executable
# on systems that are compliant to a POSIX version before POSIX:2017.
# On such systems, the usual invocation of an executable through execlp()
# or execvp() fails with ENOEXEC if it is a script that does not start
# with a #! line. The script interpreter mentioned in the #! line has
# to be /bin/sh, because on GuixSD systems that is the only program that
# has a fixed file name. The second line is essential for perl and is
# also useful for editing this file in Emacs. The next two lines below
# are valid code in both sh and perl. When executed by sh, they re-execute
# the script through the perl program found in $PATH. The '-x' option
# is essential as well; without it, perl would re-execute the script
# through /bin/sh. When executed by perl, the next two lines are a no-op.
eval 'exec perl -wSx "$0" "$@"'
if 0;
my $VERSION = '2018-03-07 03:47'; # UTC
# The definition above must lie within the first 8 lines in order
# for the Emacs time-stamp write hook (at end) to update it.
# If you change this file with Emacs, please let the write hook
# do its job. Otherwise, update this string manually.
# Copyright (C) 2008-2019 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Written by Jim Meyering
use strict;
use warnings;
use Getopt::Long;
@ -492,6 +507,7 @@ sub git_dir_option($)
# mode: perl
# indent-tabs-mode: nil
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-line-limit: 50
# time-stamp-start: "my $VERSION = '"
# time-stamp-format: "%:y-%02m-%02d %02H:%02M"
# time-stamp-time-zone: "UTC0"

View File

@ -1,9 +1,7 @@
eval '(exit $?0)' && eval 'exec perl -wS -0777 -pi "$0" "$@"'
& eval 'exec perl -wS -0777 -pi "$0" $argv:q'
if 0;
# Update an FSF copyright year list to include the current year.
#!/bin/sh
#! -*-perl-*-
my $VERSION = '2018-03-07.03:47'; # UTC
# Update an FSF copyright year list to include the current year.
# Copyright (C) 2009-2019 Free Software Foundation, Inc.
#
@ -19,9 +17,12 @@ my $VERSION = '2018-03-07.03:47'; # UTC
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Written by Jim Meyering and Joel E. Denny
# This script updates an FSF copyright year list to include the current year.
# Usage: update-copyright [FILE...]
#
# The arguments to this script should be names of files that contain
# copyright statements to be updated. The copyright holder's name
# defaults to "Free Software Foundation, Inc." but may be changed to
@ -121,6 +122,27 @@ my $VERSION = '2018-03-07.03:47'; # UTC
# 5. Set UPDATE_COPYRIGHT_HOLDER if the copyright holder is other
# than "Free Software Foundation, Inc.".
# This is a prologue that allows to run a perl script as an executable
# on systems that are compliant to a POSIX version before POSIX:2017.
# On such systems, the usual invocation of an executable through execlp()
# or execvp() fails with ENOEXEC if it is a script that does not start
# with a #! line. The script interpreter mentioned in the #! line has
# to be /bin/sh, because on GuixSD systems that is the only program that
# has a fixed file name. The second line is essential for perl and is
# also useful for editing this file in Emacs. The next two lines below
# are valid code in both sh and perl. When executed by sh, they re-execute
# the script through the perl program found in $PATH. The '-x' option
# is essential as well; without it, perl would re-execute the script
# through /bin/sh. When executed by perl, the next two lines are a no-op.
eval 'exec perl -wSx "$0" "$@"'
if 0;
my $VERSION = '2018-03-07.03:47'; # UTC
# The definition above must lie within the first 8 lines in order
# for the Emacs time-stamp write hook (at end) to update it.
# If you change this file with Emacs, please let the write hook
# do its job. Otherwise, update this string manually.
use strict;
use warnings;
@ -270,6 +292,7 @@ else
# mode: perl
# indent-tabs-mode: nil
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-line-limit: 200
# time-stamp-start: "my $VERSION = '"
# time-stamp-format: "%:y-%02m-%02d.%02H:%02M"
# time-stamp-time-zone: "UTC0"

428
lib/canonicalize-lgpl.c Normal file
View File

@ -0,0 +1,428 @@
/* Return the canonical absolute name of a given file.
Copyright (C) 1996-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#ifndef _LIBC
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
optimizes away the name == NULL test below. */
# define _GL_ARG_NONNULL(params)
# define _GL_USE_STDLIB_ALLOC 1
# include <config.h>
#endif
#if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC
/* Specification. */
#include <stdlib.h>
#include <alloca.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#if HAVE_SYS_PARAM_H || defined _LIBC
# include <sys/param.h>
#endif
#include <sys/stat.h>
#include <errno.h>
#include <stddef.h>
#ifdef _LIBC
# include <shlib-compat.h>
#else
# define SHLIB_COMPAT(lib, introduced, obsoleted) 0
# define versioned_symbol(lib, local, symbol, version) extern int dummy
# define compat_symbol(lib, local, symbol, version)
# define weak_alias(local, symbol)
# define __canonicalize_file_name canonicalize_file_name
# define __realpath realpath
# include "pathmax.h"
# include "malloca.h"
# include "dosname.h"
# if HAVE_GETCWD
# if IN_RELOCWRAPPER
/* When building the relocatable program wrapper, use the system's getcwd
function, not the gnulib override, otherwise we would get a link error.
*/
# undef getcwd
# endif
# if defined VMS && !defined getcwd
/* We want the directory in Unix syntax, not in VMS syntax.
The gnulib override of 'getcwd' takes 2 arguments; the original VMS
'getcwd' takes 3 arguments. */
# define __getcwd(buf, max) getcwd (buf, max, 0)
# else
# define __getcwd getcwd
# endif
# else
# define __getcwd(buf, max) getwd (buf)
# endif
# define __readlink readlink
# define __set_errno(e) errno = (e)
# ifndef MAXSYMLINKS
# ifdef SYMLOOP_MAX
# define MAXSYMLINKS SYMLOOP_MAX
# else
# define MAXSYMLINKS 20
# endif
# endif
#endif
#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
#endif
/* Define this independently so that stdint.h is not a prerequisite. */
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
#if !FUNC_REALPATH_WORKS || defined _LIBC
static void
alloc_failed (void)
{
#if defined _WIN32 && ! defined __CYGWIN__
/* Avoid errno problem without using the malloc or realloc modules; see:
https://lists.gnu.org/r/bug-gnulib/2016-08/msg00025.html */
errno = ENOMEM;
#endif
}
/* Return the canonical absolute name of file NAME. A canonical name
does not contain any ".", ".." components nor any repeated path
separators ('/') or symlinks. All path components must exist. If
RESOLVED is null, the result is malloc'd; otherwise, if the
canonical name is PATH_MAX chars or more, returns null with 'errno'
set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
returns the name in RESOLVED. If the name cannot be resolved and
RESOLVED is non-NULL, it contains the path of the first component
that cannot be resolved. If the path can be resolved, RESOLVED
holds the same value as the value returned. */
char *
__realpath (const char *name, char *resolved)
{
char *rpath, *dest, *extra_buf = NULL;
const char *start, *end, *rpath_limit;
long int path_max;
int num_links = 0;
size_t prefix_len;
if (name == NULL)
{
/* As per Single Unix Specification V2 we must return an error if
either parameter is a null pointer. We extend this to allow
the RESOLVED parameter to be NULL in case the we are expected to
allocate the room for the return value. */
__set_errno (EINVAL);
return NULL;
}
if (name[0] == '\0')
{
/* As per Single Unix Specification V2 we must return an error if
the name argument points to an empty string. */
__set_errno (ENOENT);
return NULL;
}
#ifdef PATH_MAX
path_max = PATH_MAX;
#else
path_max = pathconf (name, _PC_PATH_MAX);
if (path_max <= 0)
path_max = 8192;
#endif
if (resolved == NULL)
{
rpath = malloc (path_max);
if (rpath == NULL)
{
alloc_failed ();
return NULL;
}
}
else
rpath = resolved;
rpath_limit = rpath + path_max;
/* This is always zero for Posix hosts, but can be 2 for MS-Windows
and MS-DOS X:/foo/bar file names. */
prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
if (!IS_ABSOLUTE_FILE_NAME (name))
{
if (!__getcwd (rpath, path_max))
{
rpath[0] = '\0';
goto error;
}
dest = strchr (rpath, '\0');
start = name;
prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath);
}
else
{
dest = rpath;
if (prefix_len)
{
memcpy (rpath, name, prefix_len);
dest += prefix_len;
}
*dest++ = '/';
if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
{
if (ISSLASH (name[1]) && !ISSLASH (name[2]) && !prefix_len)
*dest++ = '/';
*dest = '\0';
}
start = name + prefix_len;
}
for (end = start; *start; start = end)
{
#ifdef _LIBC
struct stat64 st;
#else
struct stat st;
#endif
/* Skip sequence of multiple path-separators. */
while (ISSLASH (*start))
++start;
/* Find end of path component. */
for (end = start; *end && !ISSLASH (*end); ++end)
/* Nothing. */;
if (end - start == 0)
break;
else if (end - start == 1 && start[0] == '.')
/* nothing */;
else if (end - start == 2 && start[0] == '.' && start[1] == '.')
{
/* Back up to previous component, ignore if at root already. */
if (dest > rpath + prefix_len + 1)
for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
continue;
if (DOUBLE_SLASH_IS_DISTINCT_ROOT
&& dest == rpath + 1 && !prefix_len
&& ISSLASH (*dest) && !ISSLASH (dest[1]))
dest++;
}
else
{
size_t new_size;
if (!ISSLASH (dest[-1]))
*dest++ = '/';
if (dest + (end - start) >= rpath_limit)
{
ptrdiff_t dest_offset = dest - rpath;
char *new_rpath;
if (resolved)
{
__set_errno (ENAMETOOLONG);
if (dest > rpath + prefix_len + 1)
dest--;
*dest = '\0';
goto error;
}
new_size = rpath_limit - rpath;
if (end - start + 1 > path_max)
new_size += end - start + 1;
else
new_size += path_max;
new_rpath = (char *) realloc (rpath, new_size);
if (new_rpath == NULL)
{
alloc_failed ();
goto error;
}
rpath = new_rpath;
rpath_limit = rpath + new_size;
dest = rpath + dest_offset;
}
#ifdef _LIBC
dest = __mempcpy (dest, start, end - start);
#else
memcpy (dest, start, end - start);
dest += end - start;
#endif
*dest = '\0';
/* FIXME: if lstat fails with errno == EOVERFLOW,
the entry exists. */
#ifdef _LIBC
if (__lxstat64 (_STAT_VER, rpath, &st) < 0)
#else
if (lstat (rpath, &st) < 0)
#endif
goto error;
if (S_ISLNK (st.st_mode))
{
char *buf;
size_t len;
ssize_t n;
if (++num_links > MAXSYMLINKS)
{
__set_errno (ELOOP);
goto error;
}
buf = malloca (path_max);
if (!buf)
{
__set_errno (ENOMEM);
goto error;
}
n = __readlink (rpath, buf, path_max - 1);
if (n < 0)
{
int saved_errno = errno;
freea (buf);
__set_errno (saved_errno);
goto error;
}
buf[n] = '\0';
if (!extra_buf)
{
extra_buf = malloca (path_max);
if (!extra_buf)
{
freea (buf);
__set_errno (ENOMEM);
goto error;
}
}
len = strlen (end);
/* Check that n + len + 1 doesn't overflow and is <= path_max. */
if (n >= SIZE_MAX - len || n + len >= path_max)
{
freea (buf);
__set_errno (ENAMETOOLONG);
goto error;
}
/* Careful here, end may be a pointer into extra_buf... */
memmove (&extra_buf[n], end, len + 1);
name = end = memcpy (extra_buf, buf, n);
if (IS_ABSOLUTE_FILE_NAME (buf))
{
size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);
if (pfxlen)
memcpy (rpath, buf, pfxlen);
dest = rpath + pfxlen;
*dest++ = '/'; /* It's an absolute symlink */
if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
{
if (ISSLASH (buf[1]) && !ISSLASH (buf[2]) && !pfxlen)
*dest++ = '/';
*dest = '\0';
}
/* Install the new prefix to be in effect hereafter. */
prefix_len = pfxlen;
}
else
{
/* Back up to previous component, ignore if at root
already: */
if (dest > rpath + prefix_len + 1)
for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
continue;
if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1
&& ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)
dest++;
}
}
else if (!S_ISDIR (st.st_mode) && *end != '\0')
{
__set_errno (ENOTDIR);
goto error;
}
}
}
if (dest > rpath + prefix_len + 1 && ISSLASH (dest[-1]))
--dest;
if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && !prefix_len
&& ISSLASH (*dest) && !ISSLASH (dest[1]))
dest++;
*dest = '\0';
if (extra_buf)
freea (extra_buf);
return rpath;
error:
{
int saved_errno = errno;
if (extra_buf)
freea (extra_buf);
if (resolved == NULL)
free (rpath);
__set_errno (saved_errno);
}
return NULL;
}
versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
#endif /* !FUNC_REALPATH_WORKS || defined _LIBC */
#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3)
char *
attribute_compat_text_section
__old_realpath (const char *name, char *resolved)
{
if (resolved == NULL)
{
__set_errno (EINVAL);
return NULL;
}
return __realpath (name, resolved);
}
compat_symbol (libc, __old_realpath, realpath, GLIBC_2_0);
#endif
char *
__canonicalize_file_name (const char *name)
{
return __realpath (name, NULL);
}
weak_alias (__canonicalize_file_name, canonicalize_file_name)
#else
/* This declaration is solely to ensure that after preprocessing
this file is never empty. */
typedef int dummy;
#endif

View File

@ -72,6 +72,7 @@
# byteswap \
# c-ctype \
# c-strcase \
# canonicalize-lgpl \
# careadlinkat \
# close-stream \
# copy-file-range \
@ -484,6 +485,8 @@ GTK_CFLAGS = @GTK_CFLAGS@
GTK_LIBS = @GTK_LIBS@
GTK_OBJ = @GTK_OBJ@
GZIP_PROG = @GZIP_PROG@
HARFBUZZ_CFLAGS = @HARFBUZZ_CFLAGS@
HARFBUZZ_LIBS = @HARFBUZZ_LIBS@
HAVE_ALLOCA_H = @HAVE_ALLOCA_H@
HAVE_ALPHASORT = @HAVE_ALPHASORT@
HAVE_ATOLL = @HAVE_ATOLL@
@ -1105,6 +1108,7 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
@ -1243,6 +1247,17 @@ libgnu_a_SOURCES += c-strcase.h c-strcasecmp.c c-strncasecmp.c
endif
## end gnulib module c-strcase
## begin gnulib module canonicalize-lgpl
ifeq (,$(OMIT_GNULIB_MODULE_canonicalize-lgpl))
EXTRA_DIST += canonicalize-lgpl.c
EXTRA_libgnu_a_SOURCES += canonicalize-lgpl.c
endif
## end gnulib module canonicalize-lgpl
## begin gnulib module careadlinkat
ifeq (,$(OMIT_GNULIB_MODULE_careadlinkat))
@ -1980,6 +1995,18 @@ EXTRA_libgnu_a_SOURCES += lstat.c
endif
## end gnulib module lstat
## begin gnulib module malloca
ifeq (,$(OMIT_GNULIB_MODULE_malloca))
ifneq (,$(gl_GNULIB_ENABLED_malloca))
libgnu_a_SOURCES += malloca.c
endif
EXTRA_DIST += malloca.h
endif
## end gnulib module malloca
## begin gnulib module memmem-simple
ifeq (,$(OMIT_GNULIB_MODULE_memmem-simple))
@ -2079,6 +2106,17 @@ EXTRA_DIST += openat.h
endif
## end gnulib module openat-h
## begin gnulib module pathmax
ifeq (,$(OMIT_GNULIB_MODULE_pathmax))
ifneq (,$(gl_GNULIB_ENABLED_pathmax))
endif
EXTRA_DIST += pathmax.h
endif
## end gnulib module pathmax
## begin gnulib module pipe2
ifeq (,$(OMIT_GNULIB_MODULE_pipe2))

105
lib/malloca.c Normal file
View File

@ -0,0 +1,105 @@
/* Safe automatic memory allocation.
Copyright (C) 2003, 2006-2007, 2009-2019 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003, 2018.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>. */
#define _GL_USE_STDLIB_ALLOC 1
#include <config.h>
/* Specification. */
#include "malloca.h"
#include "verify.h"
/* The speed critical point in this file is freea() applied to an alloca()
result: it must be fast, to match the speed of alloca(). The speed of
mmalloca() and freea() in the other case are not critical, because they
are only invoked for big memory sizes.
Here we use a bit in the address as an indicator, an idea by Ondřej Bílka.
malloca() can return three types of pointers:
- Pointers 0 mod 2*sa_alignment_max come from stack allocation.
- Pointers sa_alignment_max mod 2*sa_alignment_max come from heap
allocation.
- NULL comes from a failed heap allocation. */
/* Type for holding very small pointer differences. */
typedef unsigned char small_t;
/* Verify that it is wide enough. */
verify (2 * sa_alignment_max - 1 <= (small_t) -1);
void *
mmalloca (size_t n)
{
#if HAVE_ALLOCA
/* Allocate one more word, used to determine the address to pass to freea(),
and room for the alignment sa_alignment_max mod 2*sa_alignment_max. */
size_t nplus = n + sizeof (small_t) + 2 * sa_alignment_max - 1;
if (nplus >= n)
{
char *mem = (char *) malloc (nplus);
if (mem != NULL)
{
char *p =
(char *)((((uintptr_t)mem + sizeof (small_t) + sa_alignment_max - 1)
& ~(uintptr_t)(2 * sa_alignment_max - 1))
+ sa_alignment_max);
/* Here p >= mem + sizeof (small_t),
and p <= mem + sizeof (small_t) + 2 * sa_alignment_max - 1
hence p + n <= mem + nplus.
So, the memory range [p, p+n) lies in the allocated memory range
[mem, mem + nplus). */
((small_t *) p)[-1] = p - mem;
/* p ≡ sa_alignment_max mod 2*sa_alignment_max. */
return p;
}
}
/* Out of memory. */
return NULL;
#else
# if !MALLOC_0_IS_NONNULL
if (n == 0)
n = 1;
# endif
return malloc (n);
#endif
}
#if HAVE_ALLOCA
void
freea (void *p)
{
/* Check argument. */
if ((uintptr_t) p & (sa_alignment_max - 1))
{
/* p was not the result of a malloca() call. Invalid argument. */
abort ();
}
/* Determine whether p was a non-NULL pointer returned by mmalloca(). */
if ((uintptr_t) p & sa_alignment_max)
{
void *mem = (char *) p - ((small_t *) p)[-1];
free (mem);
}
}
#endif
/*
* Hey Emacs!
* Local Variables:
* coding: utf-8
* End:
*/

127
lib/malloca.h Normal file
View File

@ -0,0 +1,127 @@
/* Safe automatic memory allocation.
Copyright (C) 2003-2007, 2009-2019 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>. */
#ifndef _MALLOCA_H
#define _MALLOCA_H
#include <alloca.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include "xalloc-oversized.h"
#ifdef __cplusplus
extern "C" {
#endif
/* safe_alloca(N) is equivalent to alloca(N) when it is safe to call
alloca(N); otherwise it returns NULL. It either returns N bytes of
memory allocated on the stack, that lasts until the function returns,
or NULL.
Use of safe_alloca should be avoided:
- inside arguments of function calls - undefined behaviour,
- in inline functions - the allocation may actually last until the
calling function returns.
*/
#if HAVE_ALLOCA
/* The OS usually guarantees only one guard page at the bottom of the stack,
and a page size can be as small as 4096 bytes. So we cannot safely
allocate anything larger than 4096 bytes. Also care for the possibility
of a few compiler-allocated temporary stack slots.
This must be a macro, not a function. */
# define safe_alloca(N) ((N) < 4032 ? alloca (N) : NULL)
#else
# define safe_alloca(N) ((void) (N), NULL)
#endif
/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
memory allocated on the stack, that must be freed using freea() before
the function returns. Upon failure, it returns NULL. */
#if HAVE_ALLOCA
# define malloca(N) \
((N) < 4032 - (2 * sa_alignment_max - 1) \
? (void *) (((uintptr_t) (char *) alloca ((N) + 2 * sa_alignment_max - 1) \
+ (2 * sa_alignment_max - 1)) \
& ~(uintptr_t)(2 * sa_alignment_max - 1)) \
: mmalloca (N))
#else
# define malloca(N) \
mmalloca (N)
#endif
extern void * mmalloca (size_t n);
/* Free a block of memory allocated through malloca(). */
#if HAVE_ALLOCA
extern void freea (void *p);
#else
# define freea free
#endif
/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
It allocates an array of N objects, each with S bytes of memory,
on the stack. S must be positive and N must be nonnegative.
The array must be freed using freea() before the function returns. */
#define nmalloca(n, s) (xalloc_oversized (n, s) ? NULL : malloca ((n) * (s)))
#ifdef __cplusplus
}
#endif
/* ------------------- Auxiliary, non-public definitions ------------------- */
/* Determine the alignment of a type at compile time. */
#if defined __GNUC__ || defined __IBM__ALIGNOF__
# define sa_alignof __alignof__
#elif defined __cplusplus
template <class type> struct sa_alignof_helper { char __slot1; type __slot2; };
# define sa_alignof(type) offsetof (sa_alignof_helper<type>, __slot2)
#elif defined __hpux
/* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
values. */
# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
#elif defined _AIX
/* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
values. */
# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
#else
# define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
#endif
enum
{
/* The desired alignment of memory allocations is the maximum alignment
among all elementary types. */
sa_alignment_long = sa_alignof (long),
sa_alignment_double = sa_alignof (double),
#if HAVE_LONG_LONG_INT
sa_alignment_longlong = sa_alignof (long long),
#endif
sa_alignment_longdouble = sa_alignof (long double),
sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
#if HAVE_LONG_LONG_INT
| (sa_alignment_longlong - 1)
#endif
| (sa_alignment_longdouble - 1)
) + 1
};
#endif /* _MALLOCA_H */

83
lib/pathmax.h Normal file
View File

@ -0,0 +1,83 @@
/* Define PATH_MAX somehow. Requires sys/types.h.
Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2019 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>. */
#ifndef _PATHMAX_H
# define _PATHMAX_H
/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
including the terminating NUL byte.
<http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
PATH_MAX is not defined on systems which have no limit on filename length,
such as GNU/Hurd.
This file does *not* define PATH_MAX always. Programs that use this file
can handle the GNU/Hurd case in several ways:
- Either with a package-wide handling, or with a per-file handling,
- Either through a
#ifdef PATH_MAX
or through a fallback like
#ifndef PATH_MAX
# define PATH_MAX 8192
#endif
or through a fallback like
#ifndef PATH_MAX
# define PATH_MAX pathconf ("/", _PC_PATH_MAX)
#endif
*/
# include <unistd.h>
# include <limits.h>
# ifndef _POSIX_PATH_MAX
# define _POSIX_PATH_MAX 256
# endif
/* Don't include sys/param.h if it already has been. */
# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
# include <sys/param.h>
# endif
# if !defined PATH_MAX && defined MAXPATHLEN
# define PATH_MAX MAXPATHLEN
# endif
# ifdef __hpux
/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
*not* including the terminating NUL byte, and is set to 1023.
Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
not defined at all any more. */
# undef PATH_MAX
# define PATH_MAX 1024
# endif
# if defined _WIN32 && ! defined __CYGWIN__
/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
section "Maximum Path Length Limitation",
<https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation>
explains that the maximum size of a filename, including the terminating
NUL byte, is 260 = 3 + 256 + 1.
This is the same value as
- FILENAME_MAX in <stdio.h>,
- _MAX_PATH in <stdlib.h>,
- MAX_PATH in <windef.h>.
Undefine the original value, because mingw's <limits.h> gets it wrong. */
# undef PATH_MAX
# define PATH_MAX 260
# endif
#endif /* _PATHMAX_H */

133
m4/canonicalize.m4 Normal file
View File

@ -0,0 +1,133 @@
# canonicalize.m4 serial 30
dnl Copyright (C) 2003-2007, 2009-2019 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
# Provides canonicalize_file_name and canonicalize_filename_mode, but does
# not provide or fix realpath.
AC_DEFUN([gl_FUNC_CANONICALIZE_FILENAME_MODE],
[
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
AC_CHECK_FUNCS_ONCE([canonicalize_file_name])
AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
AC_REQUIRE([gl_FUNC_REALPATH_WORKS])
if test $ac_cv_func_canonicalize_file_name = no; then
HAVE_CANONICALIZE_FILE_NAME=0
else
case "$gl_cv_func_realpath_works" in
*yes) ;;
*) REPLACE_CANONICALIZE_FILE_NAME=1 ;;
esac
fi
])
# Provides canonicalize_file_name and realpath.
AC_DEFUN([gl_CANONICALIZE_LGPL],
[
AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
AC_REQUIRE([gl_CANONICALIZE_LGPL_SEPARATE])
if test $ac_cv_func_canonicalize_file_name = no; then
HAVE_CANONICALIZE_FILE_NAME=0
if test $ac_cv_func_realpath = no; then
HAVE_REALPATH=0
else
case "$gl_cv_func_realpath_works" in
*yes) ;;
*) REPLACE_REALPATH=1 ;;
esac
fi
else
case "$gl_cv_func_realpath_works" in
*yes)
;;
*)
REPLACE_CANONICALIZE_FILE_NAME=1
REPLACE_REALPATH=1
;;
esac
fi
])
# Like gl_CANONICALIZE_LGPL, except prepare for separate compilation
# (no REPLACE_CANONICALIZE_FILE_NAME, no REPLACE_REALPATH, no AC_LIBOBJ).
AC_DEFUN([gl_CANONICALIZE_LGPL_SEPARATE],
[
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
AC_CHECK_FUNCS_ONCE([canonicalize_file_name getcwd readlink])
AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
AC_REQUIRE([gl_FUNC_REALPATH_WORKS])
AC_CHECK_HEADERS_ONCE([sys/param.h])
])
# Check whether realpath works. Assume that if a platform has both
# realpath and canonicalize_file_name, but the former is broken, then
# so is the latter.
AC_DEFUN([gl_FUNC_REALPATH_WORKS],
[
AC_CHECK_FUNCS_ONCE([realpath])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether realpath works], [gl_cv_func_realpath_works], [
touch conftest.a
mkdir conftest.d
AC_RUN_IFELSE([
AC_LANG_PROGRAM([[
]GL_NOCRASH[
#include <stdlib.h>
#include <string.h>
]], [[
int result = 0;
{
char *name = realpath ("conftest.a", NULL);
if (!(name && *name == '/'))
result |= 1;
free (name);
}
{
char *name = realpath ("conftest.b/../conftest.a", NULL);
if (name != NULL)
result |= 2;
free (name);
}
{
char *name = realpath ("conftest.a/", NULL);
if (name != NULL)
result |= 4;
free (name);
}
{
char *name1 = realpath (".", NULL);
char *name2 = realpath ("conftest.d//./..", NULL);
if (! name1 || ! name2 || strcmp (name1, name2))
result |= 8;
free (name1);
free (name2);
}
return result;
]])
],
[gl_cv_func_realpath_works=yes],
[gl_cv_func_realpath_works=no],
[case "$host_os" in
# Guess yes on glibc systems.
*-gnu* | gnu*) gl_cv_func_realpath_works="guessing yes" ;;
# Guess yes on musl systems.
*-musl*) gl_cv_func_realpath_works="guessing yes" ;;
# Guess no on native Windows.
mingw*) gl_cv_func_realpath_works="guessing no" ;;
# If we don't know, assume the worst.
*) gl_cv_func_realpath_works="guessing no" ;;
esac
])
rm -rf conftest.a conftest.d
])
case "$gl_cv_func_realpath_works" in
*yes)
AC_DEFINE([FUNC_REALPATH_WORKS], [1], [Define to 1 if realpath()
can malloc memory, always gives an absolute path, and handles
trailing slash correctly.])
;;
esac
])

38
m4/double-slash-root.m4 Normal file
View File

@ -0,0 +1,38 @@
# double-slash-root.m4 serial 4 -*- Autoconf -*-
dnl Copyright (C) 2006, 2008-2019 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_DOUBLE_SLASH_ROOT],
[
AC_REQUIRE([AC_CANONICAL_HOST])
AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root],
[ if test x"$cross_compiling" = xyes ; then
# When cross-compiling, there is no way to tell whether // is special
# short of a list of hosts. However, the only known hosts to date
# that have a distinct // are Apollo DomainOS (too old to port to),
# Cygwin, and z/OS. If anyone knows of another system for which // has
# special semantics and is distinct from /, please report it to
# <bug-gnulib@gnu.org>.
case $host in
*-cygwin | i370-ibm-openedition)
gl_cv_double_slash_root=yes ;;
*)
# Be optimistic and assume that / and // are the same when we
# don't know.
gl_cv_double_slash_root='unknown, assuming no' ;;
esac
else
set x `ls -di / // 2>/dev/null`
if test "$[2]" = "$[4]" && wc //dev/null >/dev/null 2>&1; then
gl_cv_double_slash_root=no
else
gl_cv_double_slash_root=yes
fi
fi])
if test "$gl_cv_double_slash_root" = yes; then
AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], [1],
[Define to 1 if // is a file system root distinct from /.])
fi
])

View File

@ -52,6 +52,7 @@ AC_DEFUN([gl_EARLY],
# Code from module byteswap:
# Code from module c-ctype:
# Code from module c-strcase:
# Code from module canonicalize-lgpl:
# Code from module careadlinkat:
# Code from module clock-time:
# Code from module cloexec:
@ -113,6 +114,7 @@ AC_DEFUN([gl_EARLY],
# Code from module limits-h:
# Code from module localtime-buffer:
# Code from module lstat:
# Code from module malloca:
# Code from module manywarnings:
# Code from module memmem-simple:
# Code from module memrchr:
@ -125,6 +127,7 @@ AC_DEFUN([gl_EARLY],
# Code from module nstrftime:
# Code from module open:
# Code from module openat-h:
# Code from module pathmax:
# Code from module pipe2:
# Code from module pselect:
# Code from module pthread_sigmask:
@ -199,6 +202,13 @@ AC_DEFUN([gl_INIT],
gl_FUNC_ALLOCA
gl___BUILTIN_EXPECT
gl_BYTESWAP
gl_CANONICALIZE_LGPL
if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then
AC_LIBOBJ([canonicalize-lgpl])
fi
gl_MODULE_INDICATOR([canonicalize-lgpl])
gl_STDLIB_MODULE_INDICATOR([canonicalize_file_name])
gl_STDLIB_MODULE_INDICATOR([realpath])
AC_CHECK_FUNCS_ONCE([readlinkat])
gl_CLOCK_TIME
gl_MODULE_INDICATOR([close-stream])
@ -447,9 +457,11 @@ AC_DEFUN([gl_INIT],
gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=false
gl_gnulib_enabled_21ee726a3540c09237a8e70c0baf7467=false
gl_gnulib_enabled_2049e887c7e5308faad27b3f894bb8c9=false
gl_gnulib_enabled_malloca=false
gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31=false
gl_gnulib_enabled_open=false
gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=false
gl_gnulib_enabled_pathmax=false
gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=false
gl_gnulib_enabled_strtoll=false
gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=false
@ -561,6 +573,14 @@ AC_DEFUN([gl_INIT],
gl_gnulib_enabled_2049e887c7e5308faad27b3f894bb8c9=true
fi
}
func_gl_gnulib_m4code_malloca ()
{
if ! $gl_gnulib_enabled_malloca; then
gl_MALLOCA
gl_gnulib_enabled_malloca=true
func_gl_gnulib_m4code_682e609604ccaac6be382e4ee3a4eaec
fi
}
func_gl_gnulib_m4code_5264294aa0a5557541b53c8c741f7f31 ()
{
if ! $gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31; then
@ -593,6 +613,13 @@ AC_DEFUN([gl_INIT],
gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=true
fi
}
func_gl_gnulib_m4code_pathmax ()
{
if ! $gl_gnulib_enabled_pathmax; then
gl_PATHMAX
gl_gnulib_enabled_pathmax=true
fi
}
func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c ()
{
if ! $gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c; then
@ -617,6 +644,12 @@ AC_DEFUN([gl_INIT],
gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=true
fi
}
if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then
func_gl_gnulib_m4code_malloca
fi
if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then
func_gl_gnulib_m4code_pathmax
fi
if test $HAVE_FACCESSAT = 0 || test $REPLACE_FACCESSAT = 1; then
func_gl_gnulib_m4code_260941c0e5dc67ec9e87d1fb321c300b
fi
@ -676,9 +709,11 @@ AC_DEFUN([gl_INIT],
AM_CONDITIONAL([gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1], [$gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1])
AM_CONDITIONAL([gl_GNULIB_ENABLED_21ee726a3540c09237a8e70c0baf7467], [$gl_gnulib_enabled_21ee726a3540c09237a8e70c0baf7467])
AM_CONDITIONAL([gl_GNULIB_ENABLED_2049e887c7e5308faad27b3f894bb8c9], [$gl_gnulib_enabled_2049e887c7e5308faad27b3f894bb8c9])
AM_CONDITIONAL([gl_GNULIB_ENABLED_malloca], [$gl_gnulib_enabled_malloca])
AM_CONDITIONAL([gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31], [$gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31])
AM_CONDITIONAL([gl_GNULIB_ENABLED_open], [$gl_gnulib_enabled_open])
AM_CONDITIONAL([gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7], [$gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7])
AM_CONDITIONAL([gl_GNULIB_ENABLED_pathmax], [$gl_gnulib_enabled_pathmax])
AM_CONDITIONAL([gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c], [$gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c])
AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll])
AM_CONDITIONAL([gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec], [$gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec])
@ -845,6 +880,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/c-strcase.h
lib/c-strcasecmp.c
lib/c-strncasecmp.c
lib/canonicalize-lgpl.c
lib/careadlinkat.c
lib/careadlinkat.h
lib/cdefs.h
@ -915,6 +951,8 @@ AC_DEFUN([gl_FILE_LIST], [
lib/localtime-buffer.c
lib/localtime-buffer.h
lib/lstat.c
lib/malloca.c
lib/malloca.h
lib/md5.c
lib/md5.h
lib/memmem.c
@ -928,6 +966,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/openat-priv.h
lib/openat-proc.c
lib/openat.h
lib/pathmax.h
lib/pipe2.c
lib/pselect.c
lib/pthread_sigmask.c
@ -1001,6 +1040,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/alloca.m4
m4/builtin-expect.m4
m4/byteswap.m4
m4/canonicalize.m4
m4/clock_time.m4
m4/copy-file-range.m4
m4/count-leading-zeros.m4
@ -1009,6 +1049,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/d-type.m4
m4/dirent_h.m4
m4/dirfd.m4
m4/double-slash-root.m4
m4/dup2.m4
m4/eealloc.m4
m4/environ.m4
@ -1048,6 +1089,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/localtime-buffer.m4
m4/longlong.m4
m4/lstat.m4
m4/malloca.m4
m4/manywarnings-c++.m4
m4/manywarnings.m4
m4/mbstate_t.m4
@ -1064,6 +1106,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/off_t.m4
m4/open-cloexec.m4
m4/open.m4
m4/pathmax.m4
m4/pipe2.m4
m4/pselect.m4
m4/pthread_sigmask.m4

15
m4/malloca.m4 Normal file
View File

@ -0,0 +1,15 @@
# malloca.m4 serial 1
dnl Copyright (C) 2003-2004, 2006-2007, 2009-2019 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_MALLOCA],
[
dnl Use the autoconf tests for alloca(), but not the AC_SUBSTed variables
dnl @ALLOCA@ and @LTALLOCA@.
dnl gl_FUNC_ALLOCA dnl Already brought in by the module dependencies.
AC_REQUIRE([gl_EEMALLOC])
AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
])

42
m4/pathmax.m4 Normal file
View File

@ -0,0 +1,42 @@
# pathmax.m4 serial 11
dnl Copyright (C) 2002-2003, 2005-2006, 2009-2019 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_PATHMAX],
[
dnl Prerequisites of lib/pathmax.h.
AC_CHECK_HEADERS_ONCE([sys/param.h])
])
# Expands to a piece of C program that defines PATH_MAX in the same way as
# "pathmax.h" will do.
AC_DEFUN([gl_PATHMAX_SNIPPET], [[
/* Arrange to define PATH_MAX, like "pathmax.h" does. */
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <limits.h>
#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
# include <sys/param.h>
#endif
#if !defined PATH_MAX && defined MAXPATHLEN
# define PATH_MAX MAXPATHLEN
#endif
#ifdef __hpux
# undef PATH_MAX
# define PATH_MAX 1024
#endif
#if defined _WIN32 && ! defined __CYGWIN__
# undef PATH_MAX
# define PATH_MAX 260
#endif
]])
# Prerequisites of gl_PATHMAX_SNIPPET.
AC_DEFUN([gl_PATHMAX_SNIPPET_PREREQ],
[
AC_CHECK_HEADERS_ONCE([unistd.h sys/param.h])
])

View File

@ -709,9 +709,6 @@ load_pdump (int argc, char **argv)
{
const char *const suffix = ".pdmp";
enum pdumper_load_result result;
#ifdef WINDOWSNT
size_t argv0_len;
#endif
/* TODO: maybe more thoroughly scrub process environment in order to
make this use case (loading a pdumper image in an unexeced emacs)
@ -747,17 +744,23 @@ load_pdump (int argc, char **argv)
}
/* Look for a dump file in the same directory as the executable; it
should have the same basename. */
should have the same basename. If the directory name is, however,
a symbolic link, resolve the symbolic symbolic link first. */
dump_file = alloca (strlen (argv[0]) + strlen (suffix) + 1);
char* argv0 = realpath (argv[0], NULL);
if (!argv0)
fatal ("could not resolve realpath of \"%s\": %s",
argv0, strerror (errno));
dump_file = alloca (strlen (argv0) + strlen (suffix) + 1);
#ifdef DOS_NT
/* Remove the .exe extension if present. */
argv0_len = strlen (argv[0]);
if (argv0_len >= 4 && c_strcasecmp (argv[0] + argv0_len - 4, ".exe") == 0)
sprintf (dump_file, "%.*s%s", (int)(argv0_len - 4), argv[0], suffix);
size_t argv0_len = strlen (argv0);
if (argv0_len >= 4 && c_strcasecmp (argv0 + argv0_len - 4, ".exe") == 0)
sprintf (dump_file, "%.*s%s", (int)(argv0_len - 4), argv0, suffix);
else
#endif
sprintf (dump_file, "%s%s", argv[0], suffix);
sprintf (dump_file, "%s%s", argv0, suffix);
result = pdumper_load (dump_file);
if (result == PDUMPER_LOAD_SUCCESS)
@ -790,17 +793,17 @@ load_pdump (int argc, char **argv)
if (result == PDUMPER_LOAD_FILE_NOT_FOUND)
{
/* Finally, look for basename(argv[0])+".pdmp" in PATH_EXEC.
/* Finally, look for basename(argv0)+".pdmp" in PATH_EXEC.
This way, they can rename both the executable and its pdump
file in PATH_EXEC, and have several Emacs configurations in
the same versioned libexec subdirectory. */
char *p, *last_sep = NULL;
for (p = argv[0]; *p; p++)
for (p = argv0; *p; p++)
{
if (IS_DIRECTORY_SEP (*p))
last_sep = p;
}
argv0_base = last_sep ? last_sep + 1 : argv[0];
argv0_base = last_sep ? last_sep + 1 : argv0;
dump_file = alloca (strlen (path_exec)
+ 1
+ strlen (argv0_base)