summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-11-02 18:14:15 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2022-11-02 18:15:10 -0700
commitddfcbc95a6be3ddc588a93f21edb69cc7c214d9c (patch)
treed85e36b38c4b4b350684df0a402a902e58d45557
parent1c3da1d369d6a204222c747cc91f590adad7cfe1 (diff)
downloadgnulib-ddfcbc95a6be3ddc588a93f21edb69cc7c214d9c.tar.gz
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.
-rw-r--r--ChangeLog27
-rwxr-xr-xbuild-aux/depcomp4
-rwxr-xr-xbuild-aux/install-reloc2
-rw-r--r--config/srclist.txt1
-rw-r--r--doc/make-stds.texi4
-rw-r--r--lib/canonicalize-lgpl.c122
-rw-r--r--lib/canonicalize.c91
-rw-r--r--lib/malloc/scratch_buffer.h16
-rw-r--r--lib/malloc/scratch_buffer_dupfree.c41
-rw-r--r--lib/scratch_buffer.h10
-rw-r--r--modules/relocatable-prog-wrapper1
-rw-r--r--modules/scratch_buffer4
12 files changed, 129 insertions, 194 deletions
diff --git a/ChangeLog b/ChangeLog
index 3dc7d8966f..0defe2469e 100644
--- a/ChangeLog
+++ b/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>
relocatable-script: Relax license.
diff --git a/build-aux/depcomp b/build-aux/depcomp
index 75323b7392..703eed2750 100755
--- a/build-aux/depcomp
+++ b/build-aux/depcomp
@@ -1,7 +1,7 @@
#! /bin/sh
# 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.
@@ -197,7 +197,7 @@ gcc3)
;;
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.
## (see the conditional assignment to $gccflag above).
## There are various ways to get dependency output from gcc. Here's
diff --git a/build-aux/install-reloc b/build-aux/install-reloc
index 63aeb9af1c..22739681ae 100755
--- a/build-aux/install-reloc
+++ b/build-aux/install-reloc
@@ -237,7 +237,6 @@ func_create_wrapper ()
"$srcdir"/readlink.c \
"$srcdir"/stat.c \
"$srcdir"/canonicalize-lgpl.c \
- "$srcdir"/malloc/scratch_buffer_dupfree.c \
"$srcdir"/malloc/scratch_buffer_grow.c \
"$srcdir"/malloc/scratch_buffer_grow_preserve.c \
"$srcdir"/malloc/scratch_buffer_set_array_size.c \
@@ -263,7 +262,6 @@ func_create_wrapper ()
readlink.o \
stat.o \
canonicalize-lgpl.o \
- scratch_buffer_dupfree.o \
scratch_buffer_grow.o \
scratch_buffer_grow_preserve.o \
scratch_buffer_set_array_size.o \
diff --git a/config/srclist.txt b/config/srclist.txt
index b4e36845be..bff6a02d8e 100644
--- a/config/srclist.txt
+++ b/config/srclist.txt
@@ -59,7 +59,6 @@ $LIBCSRC include/filename.h lib
#$LIBCSRC malloc/dynarray_resize.c lib/malloc
#$LIBCSRC malloc/dynarray_resize_clear.c 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_preserve.c lib/malloc
$LIBCSRC malloc/scratch_buffer_set_array_size.c lib/malloc
diff --git a/doc/make-stds.texi b/doc/make-stds.texi
index b0745a8a3e..132476c7a3 100644
--- a/doc/make-stds.texi
+++ b/doc/make-stds.texi
@@ -160,7 +160,7 @@ installation should not use any utilities directly except these:
@c mkfifo mknod tee uname
@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
@end example
@@ -1135,7 +1135,7 @@ programs except for these:
@example
[ 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
mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
test touch true uname xargs yes
diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
index 8c3d7f7cf8..870a663505 100644
--- a/lib/canonicalize-lgpl.c
+++ b/lib/canonicalize-lgpl.c
@@ -47,6 +47,7 @@
#else
# define __canonicalize_file_name canonicalize_file_name
# define __realpath realpath
+# define __strdup strdup
# include "pathmax.h"
# define __faccessat faccessat
# 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;
}
-/* Act like __realpath (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 __GNUC_PREREQ (10, 1)
-# if defined GCC_LINT || defined lint
-__attribute__ ((__noinline__))
-# elif __OPTIMIZE__ && !__NO_INLINE__
-# define GCC_BOGUS_WRETURN_LOCAL_ADDR
-# endif
-# endif
+/* Scratch buffers used by realpath_stk and managed by __realpath. */
+struct realpath_bufs
+{
+ struct scratch_buffer rname;
+ struct scratch_buffer extra;
+ struct scratch_buffer link;
+};
+
static char *
-realpath_stk (const char *name, char *resolved,
- struct scratch_buffer *rname_buf)
+realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
{
char *dest;
char const *start;
@@ -224,12 +214,7 @@ realpath_stk (const char *name, char *resolved,
return NULL;
}
- struct scratch_buffer extra_buffer, link_buffer;
- 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;
+ char *rname = bufs->rname.data;
bool end_in_extra_buffer = false;
bool failed = true;
@@ -239,16 +224,16 @@ realpath_stk (const char *name, char *resolved,
if (!IS_ABSOLUTE_FILE_NAME (name))
{
- while (!__getcwd (rname, rname_buf->length))
+ while (!__getcwd (bufs->rname.data, bufs->rname.length))
{
if (errno != ERANGE)
{
dest = rname;
goto error;
}
- if (!scratch_buffer_grow (rname_buf))
- goto error_nomem;
- rname = rname_buf->data;
+ if (!scratch_buffer_grow (&bufs->rname))
+ return NULL;
+ rname = bufs->rname.data;
}
dest = __rawmemchr (rname, '\0');
start = name;
@@ -302,13 +287,13 @@ realpath_stk (const char *name, char *resolved,
if (!ISSLASH (dest[-1]))
*dest++ = '/';
- while (rname + rname_buf->length - dest
+ while (rname + bufs->rname.length - dest
< startlen + sizeof dir_suffix)
{
idx_t dest_offset = dest - rname;
- if (!scratch_buffer_grow_preserve (rname_buf))
- goto error_nomem;
- rname = rname_buf->data;
+ if (!scratch_buffer_grow_preserve (&bufs->rname))
+ return NULL;
+ rname = bufs->rname.data;
dest = rname + dest_offset;
}
@@ -319,13 +304,13 @@ realpath_stk (const char *name, char *resolved,
ssize_t n;
while (true)
{
- buf = link_buffer.data;
- idx_t bufsize = link_buffer.length;
+ buf = bufs->link.data;
+ idx_t bufsize = bufs->link.length;
n = __readlink (rname, buf, bufsize - 1);
if (n < bufsize - 1)
break;
- if (!scratch_buffer_grow (&link_buffer))
- goto error_nomem;
+ if (!scratch_buffer_grow (&bufs->link))
+ return NULL;
}
if (0 <= n)
{
@@ -337,7 +322,7 @@ realpath_stk (const char *name, char *resolved,
buf[n] = '\0';
- char *extra_buf = extra_buffer.data;
+ char *extra_buf = bufs->extra.data;
idx_t end_idx IF_LINT (= 0);
if (end_in_extra_buffer)
end_idx = end - extra_buf;
@@ -345,13 +330,13 @@ realpath_stk (const char *name, char *resolved,
if (INT_ADD_OVERFLOW (len, n))
{
__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))
- goto error_nomem;
- extra_buf = extra_buffer.data;
+ if (!scratch_buffer_grow_preserve (&bufs->extra))
+ return NULL;
+ extra_buf = bufs->extra.data;
}
if (end_in_extra_buffer)
end = extra_buf + end_idx;
@@ -403,20 +388,30 @@ realpath_stk (const char *name, char *resolved,
error:
*dest++ = '\0';
- if (resolved != NULL && dest - rname <= get_path_max ())
- rname = strcpy (resolved, rname);
-
-error_nomem:
- scratch_buffer_free (&extra_buffer);
- scratch_buffer_free (&link_buffer);
-
- if (failed || rname == resolved)
+ if (resolved != NULL)
+ {
+ /* Copy the full result on success or partial result if failure was due
+ 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
{
- scratch_buffer_free (rname_buf);
- return failed ? NULL : resolved;
+ 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
@@ -433,12 +428,15 @@ error_nomem:
char *
__realpath (const char *name, char *resolved)
{
- #ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR
- #warning "GCC might issue a bogus -Wreturn-local-addr warning here."
- #warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."
- #endif
- struct scratch_buffer rname_buffer;
- return realpath_stk (name, resolved, &rname_buffer);
+ struct realpath_bufs bufs;
+ scratch_buffer_init (&bufs.rname);
+ scratch_buffer_init (&bufs.extra);
+ scratch_buffer_init (&bufs.link);
+ char *result = realpath_stk (name, resolved, &bufs);
+ scratch_buffer_free (&bufs.link);
+ scratch_buffer_free (&bufs.extra);
+ scratch_buffer_free (&bufs.rname);
+ return result;
}
libc_hidden_def (__realpath)
versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index e331e3ff1b..3342f70140 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -162,28 +162,18 @@ seen_triple (Hash_table **ht, char const *filename, struct stat const *st)
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 *
canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
- struct scratch_buffer *rname_buf)
+ struct realpath_bufs *bufs)
{
char *dest;
char const *start;
@@ -211,12 +201,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
return NULL;
}
- struct scratch_buffer extra_buffer, link_buffer;
- 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;
+ char *rname = bufs->rname.data;
bool end_in_extra_buffer = false;
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))
{
- while (!getcwd (rname, rname_buf->length))
+ while (!getcwd (bufs->rname.data, bufs->rname.length))
{
switch (errno)
{
case ERANGE:
- if (scratch_buffer_grow (rname_buf))
+ if (scratch_buffer_grow (&bufs->rname))
break;
FALLTHROUGH;
case ENOMEM:
@@ -241,7 +226,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
dest = rname;
goto error;
}
- rname = rname_buf->data;
+ rname = bufs->rname.data;
}
dest = rawmemchr (rname, '\0');
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]); )
i++;
if (name[i] != '\0' /* implies ISSLASH (name[i]) */
- && i + 1 < rname_buf->length)
+ && i + 1 < bufs->rname.length)
{
prefix_len = i;
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.
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. */
}
}
@@ -320,13 +305,13 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
if (!ISSLASH (dest[-1]))
*dest++ = '/';
- while (rname + rname_buf->length - dest
+ while (rname + bufs->rname.length - dest
< startlen + sizeof dir_suffix)
{
idx_t dest_offset = dest - rname;
- if (!scratch_buffer_grow_preserve (rname_buf))
+ if (!scratch_buffer_grow_preserve (&bufs->rname))
xalloc_die ();
- rname = rname_buf->data;
+ rname = bufs->rname.data;
dest = rname + dest_offset;
}
@@ -339,12 +324,12 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
{
while (true)
{
- buf = link_buffer.data;
- idx_t bufsize = link_buffer.length;
+ buf = bufs->link.data;
+ idx_t bufsize = bufs->link.length;
n = readlink (rname, buf, bufsize - 1);
if (n < bufsize - 1)
break;
- if (!scratch_buffer_grow (&link_buffer))
+ if (!scratch_buffer_grow (&bufs->link))
xalloc_die ();
}
}
@@ -383,18 +368,18 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
buf[n] = '\0';
- char *extra_buf = extra_buffer.data;
+ char *extra_buf = bufs->extra.data;
idx_t end_idx IF_LINT (= 0);
if (end_in_extra_buffer)
end_idx = end - extra_buf;
size_t len = strlen (end);
if (INT_ADD_OVERFLOW (len, n))
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 ();
- extra_buf = extra_buffer.data;
+ extra_buf = bufs->extra.data;
}
if (end_in_extra_buffer)
end = extra_buf + end_idx;
@@ -453,20 +438,15 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
error:
if (ht)
hash_free (ht);
- scratch_buffer_free (&extra_buffer);
- scratch_buffer_free (&link_buffer);
if (failed)
- {
- scratch_buffer_free (rname_buf);
- return NULL;
- }
+ return NULL;
*dest++ = '\0';
- char *result = scratch_buffer_dupfree (rname_buf, dest - rname);
+ char *result = malloc (dest - rname);
if (!result)
xalloc_die ();
- return result;
+ return memcpy (result, rname, dest - rname);
}
/* Return the canonical absolute name of file NAME, while treating
@@ -479,10 +459,13 @@ error:
char *
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
{
- #ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR
- #warning "GCC might issue a bogus -Wreturn-local-addr warning here."
- #warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."
- #endif
- struct scratch_buffer rname_buffer;
- return canonicalize_filename_mode_stk (name, can_mode, &rname_buffer);
+ struct realpath_bufs bufs;
+ scratch_buffer_init (&bufs.rname);
+ scratch_buffer_init (&bufs.extra);
+ scratch_buffer_init (&bufs.link);
+ char *result = canonicalize_filename_mode_stk (name, can_mode, &bufs);
+ scratch_buffer_free (&bufs.link);
+ scratch_buffer_free (&bufs.extra);
+ scratch_buffer_free (&bufs.rname);
+ return result;
}
diff --git a/lib/malloc/scratch_buffer.h b/lib/malloc/scratch_buffer.h
index e4c5c8a85d..a9bdcadec2 100644
--- a/lib/malloc/scratch_buffer.h
+++ b/lib/malloc/scratch_buffer.h
@@ -132,20 +132,4 @@ scratch_buffer_set_array_size (struct scratch_buffer *buffer,
(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 */
diff --git a/lib/malloc/scratch_buffer_dupfree.c b/lib/malloc/scratch_buffer_dupfree.c
deleted file mode 100644
index eb3b95c1b1..0000000000
--- a/lib/malloc/scratch_buffer_dupfree.c
+++ /dev/null
@@ -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)
diff --git a/lib/scratch_buffer.h b/lib/scratch_buffer.h
index f4fe5e8d34..c0aa21630f 100644
--- a/lib/scratch_buffer.h
+++ b/lib/scratch_buffer.h
@@ -98,20 +98,10 @@ extern bool scratch_buffer_set_array_size (struct scratch_buffer *buffer,
size_t nelem, size_t size);
#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. */
/* 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_preserve gl_scratch_buffer_grow_preserve
#define __libc_scratch_buffer_set_array_size gl_scratch_buffer_set_array_size
diff --git a/modules/relocatable-prog-wrapper b/modules/relocatable-prog-wrapper
index a60aa24d67..052499c1ad 100644
--- a/modules/relocatable-prog-wrapper
+++ b/modules/relocatable-prog-wrapper
@@ -19,7 +19,6 @@ lib/stat.c
lib/canonicalize-lgpl.c
lib/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_preserve.c
lib/malloc/scratch_buffer_set_array_size.c
diff --git a/modules/scratch_buffer b/modules/scratch_buffer
index 921c8f5497..ace8a34d2c 100644
--- a/modules/scratch_buffer
+++ b/modules/scratch_buffer
@@ -4,7 +4,6 @@ Variable-sized buffer with on-stack default allocation.
Files:
lib/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_preserve.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 $@
MOSTLYCLEANFILES += malloc/scratch_buffer.gl.h malloc/scratch_buffer.gl.h-t
-lib_SOURCES += malloc/scratch_buffer_dupfree.c \
- malloc/scratch_buffer_grow.c \
+lib_SOURCES += malloc/scratch_buffer_grow.c \
malloc/scratch_buffer_grow_preserve.c \
malloc/scratch_buffer_set_array_size.c