extern const char *unix_lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_NONNULL(1);
+/* A dirname () that is always compiled in. */
+
+extern char *ldirname (const char *) ATTRIBUTE_NONNULL(1);
+
+/* Same, but assumes DOS semantics regardless of host. */
+
+extern char *dos_ldirname (const char *) ATTRIBUTE_NONNULL(1);
+
+/* Same, but assumes Unix semantics regardless of host. */
+
+extern char *unix_ldirname (const char *) ATTRIBUTE_NONNULL(1);
+
/* A well-defined realpath () that is always compiled in. */
extern char *lrealpath (const char *);
extern int ffs(int);
#endif
+#if defined (HAVE_DECL_MKSTEMPS) && !HAVE_DECL_MKSTEMPS
+extern int mkstemps(char *, int);
+#endif
+
+/* Make memrchr available on systems that do not have it. */
+#if !defined (__GNU_LIBRARY__ ) && !defined (__linux__) && \
+ !defined (HAVE_MEMRCHR)
+extern void *memrchr(const void *, int, size_t);
+#endif
+
/* Get the working directory. The result is cached, so don't call
chdir() between calls to getpwd(). */
+2025-05-13 Andreas Schwab <schwab@suse.de>
+
+ * regex.c (regex_compile): Don't write beyond array bounds when
+ collecting range expression.
+
+2025-03-29 Iain Sandoe <iain@sandoe.co.uk>
+
+ PR cobol/119283
+ * Makefile.in: Add memrchr build rules.
+ * config.in: Regenerate.
+ * configure: Regenerate.
+ * configure.ac: Check for memrchr.
+ * functions.texi: Document memrchr.
+ * memrchr.c: New file.
+
+2025-03-25 Iain Sandoe <iain@sandoe.co.uk>
+
+ PR other/119218
+ * config.in: Regenerate.
+ * configure: Regenerate.
+ * configure.ac: Append <libgen.h> to AC_INCLUDES_DEFAULT
+ when checking for the 'basename' decl.
+
+2025-03-18 Jose E. Marchesi <jose.marchesi@oracle.com>
+
+ * ldirname.c: New file.
+ * Makefile.in (CFILES): Add ldirname.c.
+ (REQUIRED_OFILES): Add ldirname.$(objext).
+ (./ldirname.$(objext)): New rule.
+ * makefile.vms (OBJS): Add ldirname.obj.
+ * configure.com (FILES): Add ldirname.
+
+2024-12-11 Matthieu Longo <matthieu.longo@arm.com>
+
+ * configure: Regenerate.
+ * configure.ac: Fix autoupdate warnings.
+
+2024-12-11 Sangamesh Mallayya <swamy.sangamesh@gmail.com>
+
+ * getopt.c: Remove _NO_PROTO block
+
2024-11-19 Evgeny Karpov <evgeny.karpov@microsoft.com>
* simple-object-coff.c: Add aarch64.
hashtab.c hex.c \
index.c insque.c \
lbasename.c \
+ ldirname.c \
lrealpath.c \
make-relative-prefix.c \
- make-temp-file.c md5.c memchr.c memcmp.c memcpy.c memmem.c \
- memmove.c mempcpy.c memset.c mkstemps.c \
+ make-temp-file.c md5.c memchr.c memrchr.c memcmp.c memcpy.c \
+ memmem.c memmove.c mempcpy.c memset.c mkstemps.c \
objalloc.c obstack.c \
partition.c pexecute.c \
pex-common.c pex-djgpp.c pex-msdos.c pex-one.c \
./fnmatch.$(objext) ./fopen_unlocked.$(objext) \
./getopt.$(objext) ./getopt1.$(objext) ./getpwd.$(objext) \
./getruntime.$(objext) ./hashtab.$(objext) ./hex.$(objext) \
- ./lbasename.$(objext) ./lrealpath.$(objext) \
+ ./lbasename.$(objext) ./ldirname.$(objext) ./lrealpath.$(objext)\
./make-relative-prefix.$(objext) ./make-temp-file.$(objext) \
./objalloc.$(objext) \
./obstack.$(objext) \
./getcwd.$(objext) ./getpagesize.$(objext) \
./gettimeofday.$(objext) \
./index.$(objext) ./insque.$(objext) \
- ./memchr.$(objext) ./memcmp.$(objext) ./memcpy.$(objext) \
- ./memmem.$(objext) ./memmove.$(objext) \
+ ./memchr.$(objext) ./memrchr.$(objext) ./memcmp.$(objext) \
+ ./memcpy.$(objext) ./memmem.$(objext) ./memmove.$(objext) \
./mempcpy.$(objext) ./memset.$(objext) ./mkstemps.$(objext) \
./pex-djgpp.$(objext) ./pex-msdos.$(objext) \
./pex-unix.$(objext) ./pex-win32.$(objext) \
else true; fi
$(COMPILE.c) $(srcdir)/lbasename.c $(OUTPUT_OPTION)
+./ldirname.$(objext): $(srcdir)/ldirname.c config.h $(INCDIR)/ansidecl.h \
+ $(INCDIR)/filenames.h $(INCDIR)/hashtab.h $(INCDIR)/libiberty.h \
+ $(INCDIR)/safe-ctype.h
+ if [ x"$(PICFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(srcdir)/ldirname.c -o pic/$@; \
+ else true; fi
+ if [ x"$(NOASANFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/ldirname.c -o noasan/$@; \
+ else true; fi
+ $(COMPILE.c) $(srcdir)/ldirname.c $(OUTPUT_OPTION)
+
./lrealpath.$(objext): $(srcdir)/lrealpath.c config.h $(INCDIR)/ansidecl.h \
$(INCDIR)/libiberty.h
if [ x"$(PICFLAG)" != x ]; then \
else true; fi
$(COMPILE.c) $(srcdir)/memchr.c $(OUTPUT_OPTION)
+./memrchr.$(objext): $(srcdir)/memrchr.c $(INCDIR)/ansidecl.h
+ if [ x"$(PICFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(srcdir)/memrchr.c -o pic/$@; \
+ else true; fi
+ if [ x"$(NOASANFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/memrchr.c -o noasan/$@; \
+ else true; fi
+ $(COMPILE.c) $(srcdir)/memrchr.c $(OUTPUT_OPTION)
+
./memcmp.$(objext): $(srcdir)/memcmp.c $(INCDIR)/ansidecl.h
if [ x"$(PICFLAG)" != x ]; then \
$(COMPILE.c) $(PICFLAG) $(srcdir)/memcmp.c -o pic/$@; \
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
+/* Define to 1 if you have the <libgen.h> header file. */
+#undef HAVE_LIBGEN_H
+
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
+/* Define to 1 if you have the `memrchr' function. */
+#undef HAVE_MEMRCHR
+
/* Define to 1 if you have the `memset' function. */
#undef HAVE_MEMSET
# It's OK to check for header files. Although the compiler may not be
# able to link anything, it had better be able to at least compile
# something.
-for ac_header in sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h sys/prctl.h spawn.h
+for ac_header in sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h sys/prctl.h spawn.h libgen.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_preproc "$LINENO" "$ac_header" "$as_ac_Header"
funcs="$funcs index"
funcs="$funcs insque"
funcs="$funcs memchr"
+funcs="$funcs memrchr"
funcs="$funcs memcmp"
funcs="$funcs memcpy"
funcs="$funcs memmem"
ffs __fsetlocking \
getcwd getpagesize getrlimit getrusage getsysinfo gettimeofday \
index insque \
- memchr memcmp memcpy memmem memmove memset mkstemps \
+ memchr memrchr memcmp memcpy memmem memmove memset mkstemps \
on_exit \
pipe2 posix_spawn posix_spawnp psignal \
pstat_getdynamic pstat_getstatic putenv \
for f in atexit basename bcmp bcopy bsearch bzero calloc clock ffs \
getcwd getpagesize getrusage gettimeofday \
- index insque memchr memcmp memcpy memmove memset psignal \
+ index insque memchr memrchr memcmp memcpy memmove memset psignal \
putenv random rename rindex sbrk setenv stpcpy strcasecmp \
strchr strdup strerror strncasecmp strrchr strstr strtod \
strtol strtoul sysconf times tmpnam vfprintf vprintf \
done
as_ac_Symbol=`$as_echo "ac_cv_have_decl_basename(char *)" | $as_tr_sh`
-ac_fn_c_check_decl "$LINENO" "basename(char *)" "$as_ac_Symbol" "$ac_includes_default"
+ac_fn_c_check_decl "$LINENO" "basename(char *)" "$as_ac_Symbol" "
+$ac_includes_default
+#ifdef HAVE_LIBGEN_H
+# include <libgen.h>
+#endif
+"
if eval test \"x\$"$as_ac_Symbol"\" = x"yes"; then :
ac_have_decl=1
else
cat >>confdefs.h <<_ACEOF
#define HAVE_DECL_BASENAME $ac_have_decl
_ACEOF
-ac_fn_c_check_decl "$LINENO" "ffs" "ac_cv_have_decl_ffs" "$ac_includes_default"
+
+ ac_fn_c_check_decl "$LINENO" "ffs" "ac_cv_have_decl_ffs" "$ac_includes_default"
if test "x$ac_cv_have_decl_ffs" = xyes; then :
ac_have_decl=1
else
# It's OK to check for header files. Although the compiler may not be
# able to link anything, it had better be able to at least compile
# something.
-AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h sys/prctl.h spawn.h)
+AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h sys/prctl.h spawn.h libgen.h)
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
funcs="$funcs index"
funcs="$funcs insque"
funcs="$funcs memchr"
+funcs="$funcs memrchr"
funcs="$funcs memcmp"
funcs="$funcs memcpy"
funcs="$funcs memmem"
ffs __fsetlocking \
getcwd getpagesize getrlimit getrusage getsysinfo gettimeofday \
index insque \
- memchr memcmp memcpy memmem memmove memset mkstemps \
+ memchr memrchr memcmp memcpy memmem memmove memset mkstemps \
on_exit \
pipe2 posix_spawn posix_spawnp psignal \
pstat_getdynamic pstat_getstatic putenv \
for f in atexit basename bcmp bcopy bsearch bzero calloc clock ffs \
getcwd getpagesize getrusage gettimeofday \
- index insque memchr memcmp memcpy memmove memset psignal \
+ index insque memchr memrchr memcmp memcpy memmove memset psignal \
putenv random rename rindex sbrk setenv stpcpy strcasecmp \
strchr strdup strerror strncasecmp strrchr strstr strtod \
strtol strtoul sysconf times tmpnam vfprintf vprintf \
[AC_MSG_RESULT([no])])
AC_CHECK_FUNCS($checkfuncs)
- AC_CHECK_DECLS([basename(char *), ffs, asprintf, vasprintf, snprintf, vsnprintf])
+ AC_CHECK_DECLS([basename(char *)], [], [], [
+AC_INCLUDES_DEFAULT
+#ifdef HAVE_LIBGEN_H
+# include <libgen.h>
+#endif])
+ AC_CHECK_DECLS([ffs, asprintf, vasprintf, snprintf, vsnprintf])
AC_CHECK_DECLS([calloc, getenv, getopt, malloc, realloc])
case "${host}" in
*-*-darwin*) ;; # Darwin's sbrk implementation is deprecated.
$ FILES="getopt,obstack,xexit,xmalloc,hex,getopt1,cplus-dem,cp-demangle,"+-
"cp-demint,asprintf,vasprintf,mkstemps,concat,getruntime,getpagesize,"+-
"getpwd,xstrerror,xmemdup,xstrdup,xatexit,choose-temp,fnmatch,objalloc,"+-
- "safe-ctype,hashtab,lbasename,argv,lrealpath,make-temp-file,"+-
+ "safe-ctype,hashtab,lbasename,ldirname,argv,lrealpath,make-temp-file,"+-
"stpcpy,unlink-if-ordinary"
$ OPT="/noopt/debug/warnings=disable=(missingreturn)"
$ CFLAGS=OPT + "/include=([],[-.include])/name=(as_is,shortened)" +-
@end deftypefn
+@c memrchr.c:3
+@deftypefn Supplemental void* memrchr (const void *@var{s}, int @var{c}, @
+ size_t @var{n})
+
+This function searches memory for the character @var{c} in reverse order,
+starting at @code{*@var{s}+@var{n}-1} . The search only ends with
+the first occurrence of @var{c}, or when the start us reached; in particular,
+a null character does not terminate the search. If the character @var{c} is
+found within @var{length} characters of @code{*@var{s}}, a pointer
+to the character is returned. If @var{c} is not found, then @code{NULL} is
+returned.
+
+@end deftypefn
+
@c memcmp.c:6
@deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, @
size_t @var{count})
--- /dev/null
+/* Libiberty dirname. Like dirname, but is not overridden by the
+ system C library.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+/*
+
+@deftypefn Replacement {char*} ldirname (const char *@var{name})
+
+Given a pointer to a string containing a typical pathname
+(@samp{/usr/src/cmd/ls/ls.c} for example), returns a string containing the
+passed string up to, but not including, the final directory separator.
+
+If the given pathname doesn't contain a directory separator then this funtion
+returns the empty string; this includes an empty given pathname. @code{NULL}
+is returned on memory allocation error.
+
+@end deftypefn
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "ansidecl.h"
+#include "libiberty.h"
+#include "safe-ctype.h"
+#include "filenames.h"
+
+/* For malloc. */
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+/* For memcpy. */
+# if HAVE_STRING_H
+# include <string.h>
+# else
+# if HAVE_STRINGS_H
+# include <strings.h>
+# endif
+# endif
+
+#define LDIRNAME(FPREFIX,DIRSEP) \
+ char *FPREFIX##_ldirname (const char *name) \
+ { \
+ /* Note that lbasename guarantees that the returned */ \
+ /* pointer lies within the passed string. */ \
+ const char *basename = FPREFIX##_lbasename (name); \
+ size_t size = basename - name; \
+ char *res = NULL; \
+ \
+ res = (char*) malloc (size + 1); \
+ if (res != NULL) \
+ { \
+ if (size > 0) \
+ { \
+ if (IS_DIR_SEPARATOR_1 ((DIRSEP),name[size - 1])) \
+ size -= 1; \
+ memcpy (res, name, size); \
+ } \
+ res[size] = '\0'; \
+ } \
+ \
+ return res; \
+ }
+
+LDIRNAME(dos,1)
+LDIRNAME(unix,0)
+
+char *
+ldirname (const char *name)
+{
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+ return dos_ldirname (name);
+#else
+ return unix_ldirname (name);
+#endif
+}
asprintf.obj vasprintf.obj,mkstemps.obj,filename_cmp.obj,\
concat.obj,getruntime.obj,getpagesize.obj,getpwd.obj,xstrerror.obj,\
xmemdup.obj,xstrdup.obj,xatexit.obj,choose-temp.obj,fnmatch.obj,\
- objalloc.obj,safe-ctype.obj,hashtab.obj,lbasename.obj,argv.obj,\
+ objalloc.obj,safe-ctype.obj,hashtab.obj,lbasename.obj,ldirname.obj,argv.obj,\
lrealpath.obj,make-temp-file.obj,stpcpy.obj,unlink-if-ordinary.obj,\
dwarfnames.obj
--- /dev/null
+/*
+
+@deftypefn Supplemental void* memrchr (const void *@var{s}, int @var{c}, @
+ size_t @var{n})
+
+This function searches memory for the character @var{c} in reverse order,
+starting at @code{*@var{s}+@var{n}-1} . The search only ends with
+the first occurrence of @var{c}, or when the start us reached; in particular,
+a null character does not terminate the search. If the character @var{c} is
+found within @var{length} characters of @code{*@var{s}}, a pointer
+to the character is returned. If @var{c} is not found, then @code{NULL} is
+returned.
+
+@end deftypefn
+
+*/
+
+#include <ansidecl.h>
+#include <stddef.h>
+
+void *
+memrchr (const void *src_void, int c, size_t length)
+{
+ if (length == 0)
+ return NULL;
+
+ const unsigned char *p = (const unsigned char*)src_void;
+ p += length;
+ while (*--p != (unsigned char)c)
+ if (src_void == p)
+ return NULL;
+ return (void *)p;
+}
PATFETCH (c);
if ((c == '.' && *p == ']') || p == pend)
break;
- if (c1 < sizeof (str))
+ if (c1 < sizeof (str) - 1)
str[c1++] = c;
else
/* This is in any case an invalid class name. */