add a compatible memrchr() function if the platform does not support it (e.g. old...
authorAndreas Steffen <andreas.steffen@strongswan.org>
Fri, 9 Jan 2009 01:19:45 +0000 (01:19 -0000)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Fri, 9 Jan 2009 01:19:45 +0000 (01:19 -0000)
configure.in
src/libstrongswan/Makefile.am
src/libstrongswan/utils/lexparser.c
src/libstrongswan/utils/memrchr.c [new file with mode: 0644]

index ff1c25e..45dc829 100644 (file)
@@ -707,6 +707,7 @@ dnl ==========================================
 AC_HAVE_LIBRARY(dl)
 AC_CHECK_FUNCS(backtrace)
 AC_CHECK_FUNCS(dladdr)
+AC_REPLACE_FUNCS(memrchr)
 
 AC_MSG_CHECKING([for gcc atomic operations])
 AC_TRY_RUN(
index 1463d41..aa0e1d8 100644 (file)
@@ -47,6 +47,7 @@ utils/identification.c utils/identification.h \
 utils/iterator.h \
 utils/lexparser.c utils/lexparser.h \
 utils/linked_list.c utils/linked_list.h \
+utils/memrchr.c \
 utils/hashtable.c utils/hashtable.h \
 utils/enumerator.c utils/enumerator.h \
 utils/optionsfrom.c utils/optionsfrom.h \
index 34eb340..c351e7e 100644 (file)
@@ -20,6 +20,9 @@
 
 #include "lexparser.h"
 
+#ifndef HAVE_MEMRCHR
+void *memrchr(const void *s, int c, size_t n);
+#endif
 
 /**
  * eat whitespace
diff --git a/src/libstrongswan/utils/memrchr.c b/src/libstrongswan/utils/memrchr.c
new file mode 100644 (file)
index 0000000..efcd03a
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2008 Thomas Jarosch
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+#ifndef HAVE_MEMRCHR
+
+#include <string.h>
+
+void *memrchr(const void *s, int c, size_t n)
+{
+       unsigned char *reverse_search;
+
+       if (s == NULL || n == 0)
+       {
+               return NULL;
+       }
+
+       reverse_search = s + n;
+
+       for (;;)
+       {
+               if (*reverse_search == (unsigned char)c)
+               {
+                       return reverse_search;
+               }
+               else if (reverse_search == s)
+               {
+                       break;
+               }
+               reverse_search--;
+       }
+       return NULL;
+}
+
+#endif