suricata
util-memrchr.c
Go to the documentation of this file.
1
/* Copyright (C) 2007-2013 Open Information Security Foundation
2
*
3
* You can copy, redistribute or modify this Program under the terms of
4
* the GNU General Public License version 2 as published by the Free
5
* Software Foundation.
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* version 2 along with this program; if not, write to the Free Software
14
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
* 02110-1301, USA.
16
*/
17
18
/**
19
* \file
20
*
21
* \author Victor Julien <victor@inliniac.net>
22
*
23
*/
24
25
#include "
suricata-common.h
"
26
#include "
util-unittest.h
"
27
#include "
util-memrchr.h
"
28
29
#ifndef HAVE_MEMRCHR
30
void
*
memrchr
(
const
void
*s,
int
c,
size_t
n)
31
{
32
const
char
*end = s + n;
33
34
while
(end > (
const
char
*)s) {
35
if
(*end == (
char
)c)
36
return
(
void
*)end;
37
end--;
38
}
39
return
NULL;
40
}
41
#endif
/* HAVE_MEMRCHR */
42
43
#ifdef UNITTESTS
44
static
int
MemrchrTest01 (
void
)
45
{
46
const
char
*haystack =
"abcabc"
;
47
char
needle =
'b'
;
48
49
char
*ptr =
memrchr
(haystack, needle, strlen(haystack));
50
if
(ptr == NULL)
51
return
0;
52
53
if
(strlen(ptr) != 2)
54
return
0;
55
56
if
(strcmp(ptr,
"bc"
) != 0)
57
return
0;
58
59
return
1;
60
}
61
#endif
62
63
void
MemrchrRegisterTests
(
void
)
64
{
65
#ifdef UNITTESTS
66
UtRegisterTest
(
"MemrchrTest01"
, MemrchrTest01);
67
#endif
68
}
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition:
util-unittest.c:103
MemrchrRegisterTests
void MemrchrRegisterTests(void)
Definition:
util-memrchr.c:63
util-unittest.h
memrchr
void * memrchr(const void *s, int c, size_t n)
Definition:
util-memrchr.c:30
suricata-common.h
util-memrchr.h
src
util-memrchr.c
Generated on Tue Dec 17 2024 23:30:38 for suricata by
1.8.18