]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add implementation of memrchr
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 3 Sep 2019 17:43:50 +0000 (13:43 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 3 Sep 2019 18:29:42 +0000 (14:29 -0400)
configure
configure.ac
src/include/autoconf.h.in
src/include/missing-h
src/lib/util/missing.c

index 76853cff755fd15c36e858334d0bdc5a89544685..bfcab913925d6059c71c5d2021ef2dd8be93be18 100755 (executable)
--- a/configure
+++ b/configure
@@ -12498,6 +12498,7 @@ for ac_func in \
   initgroups \
   localtime_r \
   mallopt \
+  memrchr \
   mkdirat \
   openat \
   pthread_sigmask \
index f2d7ecc3f5656649babf33d426bd24fd536395ef..4ca95dd2142f31bb79d86df78c27a1b30d5dfcde 100644 (file)
@@ -1515,6 +1515,7 @@ AC_CHECK_FUNCS( \
   initgroups \
   localtime_r \
   mallopt \
+  memrchr \
   mkdirat \
   openat \
   pthread_sigmask \
index 1a8aba7b3de43fba4444c07b3f20d7ffefb12247..cc1941f99f64d404f3d6dcb197c3cbe8090e669a 100644 (file)
 /* 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 `mkdirat' function. */
 #undef HAVE_MKDIRAT
 
index 3882c0ef8d35f0cbcd8fde720fab0fe37f8b2667..5531e666f721a46ad701fcf01346be777f919663 100644 (file)
@@ -132,6 +132,10 @@ int strncasecmp(char *s1, char *s2, int n);
 int strcasecmp(char *s1, char *s2);
 #endif
 
+#ifndef HAVE_MEMRCHR
+void *memrchr(const void *s, int c, size_t n);
+#endif
+
 #ifndef HAVE_STRSEP
 char *strsep(char **stringp, char const *delim);
 #endif
index e565fc9335c751d85df3e84f521442b365d279e4..16e9715084a29387472a39fc29bf454bcc127218 100644 (file)
@@ -75,6 +75,24 @@ int strcasecmp(char *s1, char *s2)
 }
 #endif
 
+
+#ifndef HAVE_MEMRCHR
+/** GNU libc extension on some platforms
+ *
+ */
+void *memrchr(void const *s, int c, size_t n)
+{
+       uint8_t *p;
+
+       if (n == 0) return NULL;
+
+       memcpy(&p, &s, sizeof(p));      /* defeat const */
+       for (p += (n - 1); p >= (uint8_t const *)s; p--) if (*p == (uint8_t)c) return (void *)p;
+
+       return NULL;
+}
+#endif
+
 #ifndef HAVE_INET_ATON
 int inet_aton(char const *cp, struct in_addr *inp)
 {
@@ -478,4 +496,3 @@ char const *inet_ntop(int af, void const *src, char *dst, size_t cnt)
        return NULL;            /* don't support IPv6 */
 }
 #endif
-