aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils/utils.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2014-02-25 12:45:38 +0100
committerTobias Brunner <tobias@strongswan.org>2014-02-26 11:05:07 +0100
commit2ed241aeb3329f661bb3898ed8d5d579bedd3b8f (patch)
tree412afa7e784f03dbec95b46377a62756a37e90f5 /src/libstrongswan/utils/utils.c
parent625fc6015438cee2340b79aeeae8c2d65bed56ff (diff)
downloadstrongswan-2ed241aeb3329f661bb3898ed8d5d579bedd3b8f.tar.bz2
strongswan-2ed241aeb3329f661bb3898ed8d5d579bedd3b8f.tar.xz
utils: Add memrchr(3) replacement for platforms that don't support it
For instance, on Mac OS X memrchr(3) is not provided by the C library.
Diffstat (limited to 'src/libstrongswan/utils/utils.c')
-rw-r--r--src/libstrongswan/utils/utils.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c
index 406c5c811..fe80edb82 100644
--- a/src/libstrongswan/utils/utils.c
+++ b/src/libstrongswan/utils/utils.c
@@ -103,7 +103,7 @@ void memwipe_noinline(void *ptr, size_t n)
*/
void *memstr(const void *haystack, const char *needle, size_t n)
{
- unsigned const char *pos = haystack;
+ const u_char *pos = haystack;
size_t l;
if (!haystack || !needle || (l = strlen(needle)) == 0)
@@ -123,6 +123,28 @@ void *memstr(const void *haystack, const char *needle, size_t n)
/**
* Described in header.
*/
+void *utils_memrchr(const void *s, int c, size_t n)
+{
+ const u_char *pos;
+
+ if (!s || !n)
+ {
+ return NULL;
+ }
+
+ for (pos = s + n - 1; pos >= (u_char*)s; pos--)
+ {
+ if (*pos == (u_char)c)
+ {
+ return (void*)pos;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * Described in header.
+ */
char* translate(char *str, const char *from, const char *to)
{
char *pos = str;