mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2025-08-10 04:43:00 +03:00
scratch_buffer: adjust to glibc changes
Problem reported by Karl Berry in: https://lists.gnu.org/r/bug-gnulib/2022-11/msg00004.html * build-aux/depcomp, doc/make-stds.texi, lib/malloc/scratch_buffer.h: Autoupdate. * build-aux/install-reloc (func_create_wrapper): Omit removed file scratch_buffer_dupfree.c. * config/srclist.txt: Remove lib/malloc/scratch_buffer_dupfree.c * lib/canonicalize-lgpl.c: Merge changes from glibc through its commit ef0700004bf0dccf493a5e8e21f71d9e7972ea9f dated 2022-07-05 11:04:45 +0200. (__strdup) [!_LIBC]: New macro. (struct realpath_bufs): New type. (realpath_stk): Use it as the extra argument. All uses changed. No longer any need for noinline or GCC_BOGUS_WRETURN_LOCAL_ADDR. * lib/canonicalize.c (struct realpath_bufs) (canonicalize_filename_mode_stk): Likewise. * lib/malloc/scratch_buffer_dupfree.c: Remove, since it was removed in glibc. * lib/scratch_buffer.h (scratch_buffer_dupfree) [0]: (__libc_scratch_buffer_dupfree): Remove decls. * modules/relocatable-prog-wrapper (Files): * modules/scratch_buffer (Files, lib_SOURCES): Remove lib/malloc/scratch_buffer_dupfree.c.
This commit is contained in:
27
ChangeLog
27
ChangeLog
@@ -1,3 +1,30 @@
|
|||||||
|
2022-11-02 Paul Eggert <eggert@cs.ucla.edu>
|
||||||
|
|
||||||
|
scratch_buffer: adjust to glibc changes
|
||||||
|
Problem reported by Karl Berry in:
|
||||||
|
https://lists.gnu.org/r/bug-gnulib/2022-11/msg00004.html
|
||||||
|
* build-aux/depcomp, doc/make-stds.texi, lib/malloc/scratch_buffer.h:
|
||||||
|
Autoupdate.
|
||||||
|
* build-aux/install-reloc (func_create_wrapper):
|
||||||
|
Omit removed file scratch_buffer_dupfree.c.
|
||||||
|
* config/srclist.txt: Remove lib/malloc/scratch_buffer_dupfree.c
|
||||||
|
* lib/canonicalize-lgpl.c: Merge changes from glibc through its
|
||||||
|
commit ef0700004bf0dccf493a5e8e21f71d9e7972ea9f dated 2022-07-05
|
||||||
|
11:04:45 +0200.
|
||||||
|
(__strdup) [!_LIBC]: New macro.
|
||||||
|
(struct realpath_bufs): New type.
|
||||||
|
(realpath_stk): Use it as the extra argument. All uses changed.
|
||||||
|
No longer any need for noinline or GCC_BOGUS_WRETURN_LOCAL_ADDR.
|
||||||
|
* lib/canonicalize.c (struct realpath_bufs)
|
||||||
|
(canonicalize_filename_mode_stk): Likewise.
|
||||||
|
* lib/malloc/scratch_buffer_dupfree.c:
|
||||||
|
Remove, since it was removed in glibc.
|
||||||
|
* lib/scratch_buffer.h (scratch_buffer_dupfree) [0]:
|
||||||
|
(__libc_scratch_buffer_dupfree): Remove decls.
|
||||||
|
* modules/relocatable-prog-wrapper (Files):
|
||||||
|
* modules/scratch_buffer (Files, lib_SOURCES):
|
||||||
|
Remove lib/malloc/scratch_buffer_dupfree.c.
|
||||||
|
|
||||||
2022-11-01 Bruno Haible <bruno@clisp.org>
|
2022-11-01 Bruno Haible <bruno@clisp.org>
|
||||||
|
|
||||||
relocatable-script: Relax license.
|
relocatable-script: Relax license.
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# depcomp - compile a program generating dependencies as side-effects
|
# depcomp - compile a program generating dependencies as side-effects
|
||||||
|
|
||||||
scriptversion=2018-03-07.03; # UTC
|
scriptversion=2022-09-18.14; # UTC
|
||||||
|
|
||||||
# Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
# Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ gcc3)
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
gcc)
|
gcc)
|
||||||
## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
|
## Note that this doesn't just cater to obsolete pre-3.x GCC compilers.
|
||||||
## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
|
## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
|
||||||
## (see the conditional assignment to $gccflag above).
|
## (see the conditional assignment to $gccflag above).
|
||||||
## There are various ways to get dependency output from gcc. Here's
|
## There are various ways to get dependency output from gcc. Here's
|
||||||
|
@@ -237,7 +237,6 @@ func_create_wrapper ()
|
|||||||
"$srcdir"/readlink.c \
|
"$srcdir"/readlink.c \
|
||||||
"$srcdir"/stat.c \
|
"$srcdir"/stat.c \
|
||||||
"$srcdir"/canonicalize-lgpl.c \
|
"$srcdir"/canonicalize-lgpl.c \
|
||||||
"$srcdir"/malloc/scratch_buffer_dupfree.c \
|
|
||||||
"$srcdir"/malloc/scratch_buffer_grow.c \
|
"$srcdir"/malloc/scratch_buffer_grow.c \
|
||||||
"$srcdir"/malloc/scratch_buffer_grow_preserve.c \
|
"$srcdir"/malloc/scratch_buffer_grow_preserve.c \
|
||||||
"$srcdir"/malloc/scratch_buffer_set_array_size.c \
|
"$srcdir"/malloc/scratch_buffer_set_array_size.c \
|
||||||
@@ -263,7 +262,6 @@ func_create_wrapper ()
|
|||||||
readlink.o \
|
readlink.o \
|
||||||
stat.o \
|
stat.o \
|
||||||
canonicalize-lgpl.o \
|
canonicalize-lgpl.o \
|
||||||
scratch_buffer_dupfree.o \
|
|
||||||
scratch_buffer_grow.o \
|
scratch_buffer_grow.o \
|
||||||
scratch_buffer_grow_preserve.o \
|
scratch_buffer_grow_preserve.o \
|
||||||
scratch_buffer_set_array_size.o \
|
scratch_buffer_set_array_size.o \
|
||||||
|
@@ -59,7 +59,6 @@ $LIBCSRC include/filename.h lib
|
|||||||
#$LIBCSRC malloc/dynarray_resize.c lib/malloc
|
#$LIBCSRC malloc/dynarray_resize.c lib/malloc
|
||||||
#$LIBCSRC malloc/dynarray_resize_clear.c lib/malloc
|
#$LIBCSRC malloc/dynarray_resize_clear.c lib/malloc
|
||||||
$LIBCSRC include/scratch_buffer.h lib/malloc
|
$LIBCSRC include/scratch_buffer.h lib/malloc
|
||||||
$LIBCSRC malloc/scratch_buffer_dupfree.c lib/malloc
|
|
||||||
$LIBCSRC malloc/scratch_buffer_grow.c lib/malloc
|
$LIBCSRC malloc/scratch_buffer_grow.c lib/malloc
|
||||||
$LIBCSRC malloc/scratch_buffer_grow_preserve.c lib/malloc
|
$LIBCSRC malloc/scratch_buffer_grow_preserve.c lib/malloc
|
||||||
$LIBCSRC malloc/scratch_buffer_set_array_size.c lib/malloc
|
$LIBCSRC malloc/scratch_buffer_set_array_size.c lib/malloc
|
||||||
|
@@ -160,7 +160,7 @@ installation should not use any utilities directly except these:
|
|||||||
@c mkfifo mknod tee uname
|
@c mkfifo mknod tee uname
|
||||||
|
|
||||||
@example
|
@example
|
||||||
awk cat cmp cp diff echo egrep expr false grep install-info ln ls
|
awk cat cmp cp diff echo expr false grep install-info ln ls
|
||||||
mkdir mv printf pwd rm rmdir sed sleep sort tar test touch tr true
|
mkdir mv printf pwd rm rmdir sed sleep sort tar test touch tr true
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@@ -1135,7 +1135,7 @@ programs except for these:
|
|||||||
|
|
||||||
@example
|
@example
|
||||||
[ basename bash cat chgrp chmod chown cmp cp dd diff echo
|
[ basename bash cat chgrp chmod chown cmp cp dd diff echo
|
||||||
egrep expand expr false fgrep find getopt grep gunzip gzip
|
expand expr false find getopt grep gunzip gzip
|
||||||
hostname install install-info kill ldconfig ln ls md5sum
|
hostname install install-info kill ldconfig ln ls md5sum
|
||||||
mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
|
mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
|
||||||
test touch true uname xargs yes
|
test touch true uname xargs yes
|
||||||
|
@@ -47,6 +47,7 @@
|
|||||||
#else
|
#else
|
||||||
# define __canonicalize_file_name canonicalize_file_name
|
# define __canonicalize_file_name canonicalize_file_name
|
||||||
# define __realpath realpath
|
# define __realpath realpath
|
||||||
|
# define __strdup strdup
|
||||||
# include "pathmax.h"
|
# include "pathmax.h"
|
||||||
# define __faccessat faccessat
|
# define __faccessat faccessat
|
||||||
# if defined _WIN32 && !defined __CYGWIN__
|
# if defined _WIN32 && !defined __CYGWIN__
|
||||||
@@ -179,27 +180,16 @@ get_path_max (void)
|
|||||||
return path_max < 0 ? 1024 : path_max <= IDX_MAX ? path_max : IDX_MAX;
|
return path_max < 0 ? 1024 : path_max <= IDX_MAX ? path_max : IDX_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Act like __realpath (see below), with an additional argument
|
/* Scratch buffers used by realpath_stk and managed by __realpath. */
|
||||||
rname_buf that can be used as temporary storage.
|
struct realpath_bufs
|
||||||
|
{
|
||||||
|
struct scratch_buffer rname;
|
||||||
|
struct scratch_buffer extra;
|
||||||
|
struct scratch_buffer link;
|
||||||
|
};
|
||||||
|
|
||||||
If GCC_LINT is defined, do not inline this function with GCC 10.1
|
|
||||||
and later, to avoid creating a pointer to the stack that GCC
|
|
||||||
-Wreturn-local-addr incorrectly complains about. See:
|
|
||||||
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644
|
|
||||||
Although the noinline attribute can hurt performance a bit, no better way
|
|
||||||
to pacify GCC is known; even an explicit #pragma does not pacify GCC.
|
|
||||||
When the GCC bug is fixed this workaround should be limited to the
|
|
||||||
broken GCC versions. */
|
|
||||||
# if __GNUC_PREREQ (10, 1)
|
|
||||||
# if defined GCC_LINT || defined lint
|
|
||||||
__attribute__ ((__noinline__))
|
|
||||||
# elif __OPTIMIZE__ && !__NO_INLINE__
|
|
||||||
# define GCC_BOGUS_WRETURN_LOCAL_ADDR
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
static char *
|
static char *
|
||||||
realpath_stk (const char *name, char *resolved,
|
realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
|
||||||
struct scratch_buffer *rname_buf)
|
|
||||||
{
|
{
|
||||||
char *dest;
|
char *dest;
|
||||||
char const *start;
|
char const *start;
|
||||||
@@ -224,12 +214,7 @@ realpath_stk (const char *name, char *resolved,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct scratch_buffer extra_buffer, link_buffer;
|
char *rname = bufs->rname.data;
|
||||||
scratch_buffer_init (&extra_buffer);
|
|
||||||
scratch_buffer_init (&link_buffer);
|
|
||||||
scratch_buffer_init (rname_buf);
|
|
||||||
char *rname_on_stack = rname_buf->data;
|
|
||||||
char *rname = rname_on_stack;
|
|
||||||
bool end_in_extra_buffer = false;
|
bool end_in_extra_buffer = false;
|
||||||
bool failed = true;
|
bool failed = true;
|
||||||
|
|
||||||
@@ -239,16 +224,16 @@ realpath_stk (const char *name, char *resolved,
|
|||||||
|
|
||||||
if (!IS_ABSOLUTE_FILE_NAME (name))
|
if (!IS_ABSOLUTE_FILE_NAME (name))
|
||||||
{
|
{
|
||||||
while (!__getcwd (rname, rname_buf->length))
|
while (!__getcwd (bufs->rname.data, bufs->rname.length))
|
||||||
{
|
{
|
||||||
if (errno != ERANGE)
|
if (errno != ERANGE)
|
||||||
{
|
{
|
||||||
dest = rname;
|
dest = rname;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!scratch_buffer_grow (rname_buf))
|
if (!scratch_buffer_grow (&bufs->rname))
|
||||||
goto error_nomem;
|
return NULL;
|
||||||
rname = rname_buf->data;
|
rname = bufs->rname.data;
|
||||||
}
|
}
|
||||||
dest = __rawmemchr (rname, '\0');
|
dest = __rawmemchr (rname, '\0');
|
||||||
start = name;
|
start = name;
|
||||||
@@ -302,13 +287,13 @@ realpath_stk (const char *name, char *resolved,
|
|||||||
if (!ISSLASH (dest[-1]))
|
if (!ISSLASH (dest[-1]))
|
||||||
*dest++ = '/';
|
*dest++ = '/';
|
||||||
|
|
||||||
while (rname + rname_buf->length - dest
|
while (rname + bufs->rname.length - dest
|
||||||
< startlen + sizeof dir_suffix)
|
< startlen + sizeof dir_suffix)
|
||||||
{
|
{
|
||||||
idx_t dest_offset = dest - rname;
|
idx_t dest_offset = dest - rname;
|
||||||
if (!scratch_buffer_grow_preserve (rname_buf))
|
if (!scratch_buffer_grow_preserve (&bufs->rname))
|
||||||
goto error_nomem;
|
return NULL;
|
||||||
rname = rname_buf->data;
|
rname = bufs->rname.data;
|
||||||
dest = rname + dest_offset;
|
dest = rname + dest_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,13 +304,13 @@ realpath_stk (const char *name, char *resolved,
|
|||||||
ssize_t n;
|
ssize_t n;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
buf = link_buffer.data;
|
buf = bufs->link.data;
|
||||||
idx_t bufsize = link_buffer.length;
|
idx_t bufsize = bufs->link.length;
|
||||||
n = __readlink (rname, buf, bufsize - 1);
|
n = __readlink (rname, buf, bufsize - 1);
|
||||||
if (n < bufsize - 1)
|
if (n < bufsize - 1)
|
||||||
break;
|
break;
|
||||||
if (!scratch_buffer_grow (&link_buffer))
|
if (!scratch_buffer_grow (&bufs->link))
|
||||||
goto error_nomem;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (0 <= n)
|
if (0 <= n)
|
||||||
{
|
{
|
||||||
@@ -337,7 +322,7 @@ realpath_stk (const char *name, char *resolved,
|
|||||||
|
|
||||||
buf[n] = '\0';
|
buf[n] = '\0';
|
||||||
|
|
||||||
char *extra_buf = extra_buffer.data;
|
char *extra_buf = bufs->extra.data;
|
||||||
idx_t end_idx IF_LINT (= 0);
|
idx_t end_idx IF_LINT (= 0);
|
||||||
if (end_in_extra_buffer)
|
if (end_in_extra_buffer)
|
||||||
end_idx = end - extra_buf;
|
end_idx = end - extra_buf;
|
||||||
@@ -345,13 +330,13 @@ realpath_stk (const char *name, char *resolved,
|
|||||||
if (INT_ADD_OVERFLOW (len, n))
|
if (INT_ADD_OVERFLOW (len, n))
|
||||||
{
|
{
|
||||||
__set_errno (ENOMEM);
|
__set_errno (ENOMEM);
|
||||||
goto error_nomem;
|
return NULL;
|
||||||
}
|
}
|
||||||
while (extra_buffer.length <= len + n)
|
while (bufs->extra.length <= len + n)
|
||||||
{
|
{
|
||||||
if (!scratch_buffer_grow_preserve (&extra_buffer))
|
if (!scratch_buffer_grow_preserve (&bufs->extra))
|
||||||
goto error_nomem;
|
return NULL;
|
||||||
extra_buf = extra_buffer.data;
|
extra_buf = bufs->extra.data;
|
||||||
}
|
}
|
||||||
if (end_in_extra_buffer)
|
if (end_in_extra_buffer)
|
||||||
end = extra_buf + end_idx;
|
end = extra_buf + end_idx;
|
||||||
@@ -403,20 +388,30 @@ realpath_stk (const char *name, char *resolved,
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
*dest++ = '\0';
|
*dest++ = '\0';
|
||||||
if (resolved != NULL && dest - rname <= get_path_max ())
|
if (resolved != NULL)
|
||||||
rname = strcpy (resolved, rname);
|
|
||||||
|
|
||||||
error_nomem:
|
|
||||||
scratch_buffer_free (&extra_buffer);
|
|
||||||
scratch_buffer_free (&link_buffer);
|
|
||||||
|
|
||||||
if (failed || rname == resolved)
|
|
||||||
{
|
{
|
||||||
scratch_buffer_free (rname_buf);
|
/* Copy the full result on success or partial result if failure was due
|
||||||
return failed ? NULL : resolved;
|
to the path not existing or not being accessible. */
|
||||||
|
if ((!failed || errno == ENOENT || errno == EACCES)
|
||||||
|
&& dest - rname <= get_path_max ())
|
||||||
|
{
|
||||||
|
strcpy (resolved, rname);
|
||||||
|
if (failed)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
if (!failed)
|
||||||
|
__set_errno (ENAMETOOLONG);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (failed)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return __strdup (bufs->rname.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return scratch_buffer_dupfree (rname_buf, dest - rname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the canonical absolute name of file NAME. A canonical name
|
/* Return the canonical absolute name of file NAME. A canonical name
|
||||||
@@ -433,12 +428,15 @@ error_nomem:
|
|||||||
char *
|
char *
|
||||||
__realpath (const char *name, char *resolved)
|
__realpath (const char *name, char *resolved)
|
||||||
{
|
{
|
||||||
#ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR
|
struct realpath_bufs bufs;
|
||||||
#warning "GCC might issue a bogus -Wreturn-local-addr warning here."
|
scratch_buffer_init (&bufs.rname);
|
||||||
#warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."
|
scratch_buffer_init (&bufs.extra);
|
||||||
#endif
|
scratch_buffer_init (&bufs.link);
|
||||||
struct scratch_buffer rname_buffer;
|
char *result = realpath_stk (name, resolved, &bufs);
|
||||||
return realpath_stk (name, resolved, &rname_buffer);
|
scratch_buffer_free (&bufs.link);
|
||||||
|
scratch_buffer_free (&bufs.extra);
|
||||||
|
scratch_buffer_free (&bufs.rname);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
libc_hidden_def (__realpath)
|
libc_hidden_def (__realpath)
|
||||||
versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
|
versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
|
||||||
|
@@ -162,28 +162,18 @@ seen_triple (Hash_table **ht, char const *filename, struct stat const *st)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Scratch buffers used by canonicalize_filename_mode_stk and managed
|
||||||
|
by __realpath. */
|
||||||
|
struct realpath_bufs
|
||||||
|
{
|
||||||
|
struct scratch_buffer rname;
|
||||||
|
struct scratch_buffer extra;
|
||||||
|
struct scratch_buffer link;
|
||||||
|
};
|
||||||
|
|
||||||
/* Act like canonicalize_filename_mode (see below), with an additional argument
|
|
||||||
rname_buf that can be used as temporary storage.
|
|
||||||
|
|
||||||
If GCC_LINT is defined, do not inline this function with GCC 10.1
|
|
||||||
and later, to avoid creating a pointer to the stack that GCC
|
|
||||||
-Wreturn-local-addr incorrectly complains about. See:
|
|
||||||
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644
|
|
||||||
Although the noinline attribute can hurt performance a bit, no better way
|
|
||||||
to pacify GCC is known; even an explicit #pragma does not pacify GCC.
|
|
||||||
When the GCC bug is fixed this workaround should be limited to the
|
|
||||||
broken GCC versions. */
|
|
||||||
#if _GL_GNUC_PREREQ (10, 1)
|
|
||||||
# if defined GCC_LINT || defined lint
|
|
||||||
__attribute__ ((__noinline__))
|
|
||||||
# elif __OPTIMIZE__ && !__NO_INLINE__
|
|
||||||
# define GCC_BOGUS_WRETURN_LOCAL_ADDR
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
static char *
|
static char *
|
||||||
canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
||||||
struct scratch_buffer *rname_buf)
|
struct realpath_bufs *bufs)
|
||||||
{
|
{
|
||||||
char *dest;
|
char *dest;
|
||||||
char const *start;
|
char const *start;
|
||||||
@@ -211,12 +201,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct scratch_buffer extra_buffer, link_buffer;
|
char *rname = bufs->rname.data;
|
||||||
scratch_buffer_init (&extra_buffer);
|
|
||||||
scratch_buffer_init (&link_buffer);
|
|
||||||
scratch_buffer_init (rname_buf);
|
|
||||||
char *rname_on_stack = rname_buf->data;
|
|
||||||
char *rname = rname_on_stack;
|
|
||||||
bool end_in_extra_buffer = false;
|
bool end_in_extra_buffer = false;
|
||||||
bool failed = true;
|
bool failed = true;
|
||||||
|
|
||||||
@@ -226,12 +211,12 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
|||||||
|
|
||||||
if (!IS_ABSOLUTE_FILE_NAME (name))
|
if (!IS_ABSOLUTE_FILE_NAME (name))
|
||||||
{
|
{
|
||||||
while (!getcwd (rname, rname_buf->length))
|
while (!getcwd (bufs->rname.data, bufs->rname.length))
|
||||||
{
|
{
|
||||||
switch (errno)
|
switch (errno)
|
||||||
{
|
{
|
||||||
case ERANGE:
|
case ERANGE:
|
||||||
if (scratch_buffer_grow (rname_buf))
|
if (scratch_buffer_grow (&bufs->rname))
|
||||||
break;
|
break;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case ENOMEM:
|
case ENOMEM:
|
||||||
@@ -241,7 +226,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
|||||||
dest = rname;
|
dest = rname;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
rname = rname_buf->data;
|
rname = bufs->rname.data;
|
||||||
}
|
}
|
||||||
dest = rawmemchr (rname, '\0');
|
dest = rawmemchr (rname, '\0');
|
||||||
start = name;
|
start = name;
|
||||||
@@ -265,7 +250,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
|||||||
for (i = 2; name[i] != '\0' && !ISSLASH (name[i]); )
|
for (i = 2; name[i] != '\0' && !ISSLASH (name[i]); )
|
||||||
i++;
|
i++;
|
||||||
if (name[i] != '\0' /* implies ISSLASH (name[i]) */
|
if (name[i] != '\0' /* implies ISSLASH (name[i]) */
|
||||||
&& i + 1 < rname_buf->length)
|
&& i + 1 < bufs->rname.length)
|
||||||
{
|
{
|
||||||
prefix_len = i;
|
prefix_len = i;
|
||||||
memcpy (dest, name + 2, i - 2 + 1);
|
memcpy (dest, name + 2, i - 2 + 1);
|
||||||
@@ -275,7 +260,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
|||||||
{
|
{
|
||||||
/* Either name = '\\server'; this is an invalid file name.
|
/* Either name = '\\server'; this is an invalid file name.
|
||||||
Or name = '\\server\...' and server is more than
|
Or name = '\\server\...' and server is more than
|
||||||
rname_buf->length - 4 bytes long. In either
|
bufs->rname.length - 4 bytes long. In either
|
||||||
case, stop the UNC processing. */
|
case, stop the UNC processing. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,13 +305,13 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
|||||||
if (!ISSLASH (dest[-1]))
|
if (!ISSLASH (dest[-1]))
|
||||||
*dest++ = '/';
|
*dest++ = '/';
|
||||||
|
|
||||||
while (rname + rname_buf->length - dest
|
while (rname + bufs->rname.length - dest
|
||||||
< startlen + sizeof dir_suffix)
|
< startlen + sizeof dir_suffix)
|
||||||
{
|
{
|
||||||
idx_t dest_offset = dest - rname;
|
idx_t dest_offset = dest - rname;
|
||||||
if (!scratch_buffer_grow_preserve (rname_buf))
|
if (!scratch_buffer_grow_preserve (&bufs->rname))
|
||||||
xalloc_die ();
|
xalloc_die ();
|
||||||
rname = rname_buf->data;
|
rname = bufs->rname.data;
|
||||||
dest = rname + dest_offset;
|
dest = rname + dest_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,12 +324,12 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
buf = link_buffer.data;
|
buf = bufs->link.data;
|
||||||
idx_t bufsize = link_buffer.length;
|
idx_t bufsize = bufs->link.length;
|
||||||
n = readlink (rname, buf, bufsize - 1);
|
n = readlink (rname, buf, bufsize - 1);
|
||||||
if (n < bufsize - 1)
|
if (n < bufsize - 1)
|
||||||
break;
|
break;
|
||||||
if (!scratch_buffer_grow (&link_buffer))
|
if (!scratch_buffer_grow (&bufs->link))
|
||||||
xalloc_die ();
|
xalloc_die ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -383,18 +368,18 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
|||||||
|
|
||||||
buf[n] = '\0';
|
buf[n] = '\0';
|
||||||
|
|
||||||
char *extra_buf = extra_buffer.data;
|
char *extra_buf = bufs->extra.data;
|
||||||
idx_t end_idx IF_LINT (= 0);
|
idx_t end_idx IF_LINT (= 0);
|
||||||
if (end_in_extra_buffer)
|
if (end_in_extra_buffer)
|
||||||
end_idx = end - extra_buf;
|
end_idx = end - extra_buf;
|
||||||
size_t len = strlen (end);
|
size_t len = strlen (end);
|
||||||
if (INT_ADD_OVERFLOW (len, n))
|
if (INT_ADD_OVERFLOW (len, n))
|
||||||
xalloc_die ();
|
xalloc_die ();
|
||||||
while (extra_buffer.length <= len + n)
|
while (bufs->extra.length <= len + n)
|
||||||
{
|
{
|
||||||
if (!scratch_buffer_grow_preserve (&extra_buffer))
|
if (!scratch_buffer_grow_preserve (&bufs->extra))
|
||||||
xalloc_die ();
|
xalloc_die ();
|
||||||
extra_buf = extra_buffer.data;
|
extra_buf = bufs->extra.data;
|
||||||
}
|
}
|
||||||
if (end_in_extra_buffer)
|
if (end_in_extra_buffer)
|
||||||
end = extra_buf + end_idx;
|
end = extra_buf + end_idx;
|
||||||
@@ -453,20 +438,15 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
|||||||
error:
|
error:
|
||||||
if (ht)
|
if (ht)
|
||||||
hash_free (ht);
|
hash_free (ht);
|
||||||
scratch_buffer_free (&extra_buffer);
|
|
||||||
scratch_buffer_free (&link_buffer);
|
|
||||||
|
|
||||||
if (failed)
|
if (failed)
|
||||||
{
|
|
||||||
scratch_buffer_free (rname_buf);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
*dest++ = '\0';
|
*dest++ = '\0';
|
||||||
char *result = scratch_buffer_dupfree (rname_buf, dest - rname);
|
char *result = malloc (dest - rname);
|
||||||
if (!result)
|
if (!result)
|
||||||
xalloc_die ();
|
xalloc_die ();
|
||||||
return result;
|
return memcpy (result, rname, dest - rname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the canonical absolute name of file NAME, while treating
|
/* Return the canonical absolute name of file NAME, while treating
|
||||||
@@ -479,10 +459,13 @@ error:
|
|||||||
char *
|
char *
|
||||||
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
|
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
|
||||||
{
|
{
|
||||||
#ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR
|
struct realpath_bufs bufs;
|
||||||
#warning "GCC might issue a bogus -Wreturn-local-addr warning here."
|
scratch_buffer_init (&bufs.rname);
|
||||||
#warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."
|
scratch_buffer_init (&bufs.extra);
|
||||||
#endif
|
scratch_buffer_init (&bufs.link);
|
||||||
struct scratch_buffer rname_buffer;
|
char *result = canonicalize_filename_mode_stk (name, can_mode, &bufs);
|
||||||
return canonicalize_filename_mode_stk (name, can_mode, &rname_buffer);
|
scratch_buffer_free (&bufs.link);
|
||||||
|
scratch_buffer_free (&bufs.extra);
|
||||||
|
scratch_buffer_free (&bufs.rname);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -132,20 +132,4 @@ scratch_buffer_set_array_size (struct scratch_buffer *buffer,
|
|||||||
(buffer, nelem, size));
|
(buffer, nelem, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a copy of *BUFFER's first SIZE bytes as a heap-allocated block,
|
|
||||||
deallocating *BUFFER if it was heap-allocated. SIZE must be at
|
|
||||||
most *BUFFER's size. Return NULL (setting errno) on memory
|
|
||||||
exhaustion. */
|
|
||||||
void *__libc_scratch_buffer_dupfree (struct scratch_buffer *buffer,
|
|
||||||
size_t size);
|
|
||||||
libc_hidden_proto (__libc_scratch_buffer_dupfree)
|
|
||||||
|
|
||||||
/* Alias for __libc_scratch_dupfree. */
|
|
||||||
static __always_inline void *
|
|
||||||
scratch_buffer_dupfree (struct scratch_buffer *buffer, size_t size)
|
|
||||||
{
|
|
||||||
void *r = __libc_scratch_buffer_dupfree (buffer, size);
|
|
||||||
return __glibc_likely (r != NULL) ? r : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* _SCRATCH_BUFFER_H */
|
#endif /* _SCRATCH_BUFFER_H */
|
||||||
|
@@ -1,41 +0,0 @@
|
|||||||
/* Variable-sized buffer with on-stack default allocation.
|
|
||||||
Copyright (C) 2020-2022 Free Software Foundation, Inc.
|
|
||||||
This file is part of the GNU C Library.
|
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
The GNU C Library 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
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with the GNU C Library; if not, see
|
|
||||||
<https://www.gnu.org/licenses/>. */
|
|
||||||
|
|
||||||
#ifndef _LIBC
|
|
||||||
# include <libc-config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <scratch_buffer.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
void *
|
|
||||||
__libc_scratch_buffer_dupfree (struct scratch_buffer *buffer, size_t size)
|
|
||||||
{
|
|
||||||
void *data = buffer->data;
|
|
||||||
if (data == buffer->__space.__c)
|
|
||||||
{
|
|
||||||
void *copy = malloc (size);
|
|
||||||
return copy != NULL ? memcpy (copy, data, size) : NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
void *copy = realloc (data, size);
|
|
||||||
return copy != NULL ? copy : data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
libc_hidden_def (__libc_scratch_buffer_dupfree)
|
|
@@ -98,20 +98,10 @@ extern bool scratch_buffer_set_array_size (struct scratch_buffer *buffer,
|
|||||||
size_t nelem, size_t size);
|
size_t nelem, size_t size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Return a copy of *BUFFER's first SIZE bytes as a heap-allocated block,
|
|
||||||
deallocating *BUFFER if it was heap-allocated. SIZE must be at
|
|
||||||
most *BUFFER's size. Return NULL (setting errno) on memory
|
|
||||||
exhaustion. */
|
|
||||||
#if 0
|
|
||||||
extern void *scratch_buffer_dupfree (struct scratch_buffer *buffer,
|
|
||||||
size_t size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* The implementation is imported from glibc. */
|
/* The implementation is imported from glibc. */
|
||||||
|
|
||||||
/* Avoid possible conflicts with symbols exported by the GNU libc. */
|
/* Avoid possible conflicts with symbols exported by the GNU libc. */
|
||||||
#define __libc_scratch_buffer_dupfree gl_scratch_buffer_dupfree
|
|
||||||
#define __libc_scratch_buffer_grow gl_scratch_buffer_grow
|
#define __libc_scratch_buffer_grow gl_scratch_buffer_grow
|
||||||
#define __libc_scratch_buffer_grow_preserve gl_scratch_buffer_grow_preserve
|
#define __libc_scratch_buffer_grow_preserve gl_scratch_buffer_grow_preserve
|
||||||
#define __libc_scratch_buffer_set_array_size gl_scratch_buffer_set_array_size
|
#define __libc_scratch_buffer_set_array_size gl_scratch_buffer_set_array_size
|
||||||
|
@@ -19,7 +19,6 @@ lib/stat.c
|
|||||||
lib/canonicalize-lgpl.c
|
lib/canonicalize-lgpl.c
|
||||||
lib/scratch_buffer.h
|
lib/scratch_buffer.h
|
||||||
lib/malloc/scratch_buffer.h
|
lib/malloc/scratch_buffer.h
|
||||||
lib/malloc/scratch_buffer_dupfree.c
|
|
||||||
lib/malloc/scratch_buffer_grow.c
|
lib/malloc/scratch_buffer_grow.c
|
||||||
lib/malloc/scratch_buffer_grow_preserve.c
|
lib/malloc/scratch_buffer_grow_preserve.c
|
||||||
lib/malloc/scratch_buffer_set_array_size.c
|
lib/malloc/scratch_buffer_set_array_size.c
|
||||||
|
@@ -4,7 +4,6 @@ Variable-sized buffer with on-stack default allocation.
|
|||||||
Files:
|
Files:
|
||||||
lib/scratch_buffer.h
|
lib/scratch_buffer.h
|
||||||
lib/malloc/scratch_buffer.h
|
lib/malloc/scratch_buffer.h
|
||||||
lib/malloc/scratch_buffer_dupfree.c
|
|
||||||
lib/malloc/scratch_buffer_grow.c
|
lib/malloc/scratch_buffer_grow.c
|
||||||
lib/malloc/scratch_buffer_grow_preserve.c
|
lib/malloc/scratch_buffer_grow_preserve.c
|
||||||
lib/malloc/scratch_buffer_set_array_size.c
|
lib/malloc/scratch_buffer_set_array_size.c
|
||||||
@@ -37,8 +36,7 @@ malloc/scratch_buffer.gl.h: malloc/scratch_buffer.h
|
|||||||
$(AM_V_at)mv $@-t $@
|
$(AM_V_at)mv $@-t $@
|
||||||
MOSTLYCLEANFILES += malloc/scratch_buffer.gl.h malloc/scratch_buffer.gl.h-t
|
MOSTLYCLEANFILES += malloc/scratch_buffer.gl.h malloc/scratch_buffer.gl.h-t
|
||||||
|
|
||||||
lib_SOURCES += malloc/scratch_buffer_dupfree.c \
|
lib_SOURCES += malloc/scratch_buffer_grow.c \
|
||||||
malloc/scratch_buffer_grow.c \
|
|
||||||
malloc/scratch_buffer_grow_preserve.c \
|
malloc/scratch_buffer_grow_preserve.c \
|
||||||
malloc/scratch_buffer_set_array_size.c
|
malloc/scratch_buffer_set_array_size.c
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user