do not operate on strongswan-padlock on non-x86
[strongswan.git] / src / libstrongswan / utils / memrchr.c
1 /*
2 * Copyright (C) 2008 Thomas Jarosch
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #ifndef HAVE_MEMRCHR
16
17 #include <string.h>
18
19 void *memrchr(const void *s, int c, size_t n)
20 {
21 unsigned char *reverse_search;
22
23 if (s == NULL || n == 0)
24 {
25 return NULL;
26 }
27
28 reverse_search = s + n;
29
30 for (;;)
31 {
32 if (*reverse_search == (unsigned char)c)
33 {
34 return reverse_search;
35 }
36 else if (reverse_search == s)
37 {
38 break;
39 }
40 reverse_search--;
41 }
42 return NULL;
43 }
44
45 #endif