#endif
+/* Define to 1 if you have the `memrchr' function. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_MEMRCHR
+#endif
+
+
/* Define to 1 if you have the `mmap' function. */
#ifndef USED_FOR_TARGET
#undef HAVE_MMAP
popen sysconf strsignal getrusage nl_langinfo \
gettimeofday mbstowcs wcswidth mmap posix_fallocate setlocale \
clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked madvise mallinfo mallinfo2 fstatat getauxval \
- clock_gettime munmap msync get_current_dir_name
+ clock_gettime munmap msync get_current_dir_name memrchr
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"
popen sysconf strsignal getrusage nl_langinfo \
gettimeofday mbstowcs wcswidth mmap posix_fallocate setlocale \
gcc_UNLOCKED_FUNCS madvise mallinfo mallinfo2 fstatat getauxval \
- clock_gettime munmap msync get_current_dir_name)
+ clock_gettime munmap msync get_current_dir_name memrchr)
# At least for glibc, clock_gettime is in librt. But don't pull that
# in if it still doesn't give us the function we want.
extern int mkstemps(char *, 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(). */
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 \
./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)/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 <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
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 \
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 \
@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
+/*
+
+@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;
+}