util: remove memrchr

As its only usage got rustified
pull/16338/head
Philippe Antoine 4 months ago committed by Victor Julien
parent cd347f012a
commit ecb1179b27

@ -207,7 +207,7 @@
AC_FUNC_MMAP
AC_FUNC_STRTOD
AC_CHECK_FUNCS([memmem memset memchr memrchr memmove])
AC_CHECK_FUNCS([memmem memset memchr memmove])
AC_CHECK_FUNCS([strcasecmp strchr strrchr strdup strndup strncasecmp strtol strstr strpbrk strtoull strtoumax])
AC_CHECK_FUNCS([strerror])
AC_CHECK_FUNCS([gethostname inet_ntoa uname])

@ -540,7 +540,6 @@ noinst_HEADERS = \
util-mem.h \
util-memcmp.h \
util-memcpy.h \
util-memrchr.h \
util-misc.h \
util-mpm-ac-ks.h \
util-mpm-ac-queue.h \
@ -1098,7 +1097,6 @@ libsuricata_c_a_SOURCES = \
util-magic.c \
util-mem.c \
util-memcmp.c \
util-memrchr.c \
util-misc.c \
util-mpm-ac-ks-small.c \
util-mpm-ac-ks.c \

@ -29,10 +29,6 @@
#include "app-layer-htp.h"
#include "app-layer-htp-xff.h"
#ifndef HAVE_MEMRCHR
#include "util-memrchr.h"
#endif
#include "util-misc.h"
#include "util-unittest.h"

@ -92,7 +92,6 @@
#include "util-proto-name.h"
#include "util-macset.h"
#include "util-flow-rate.h"
#include "util-memrchr.h"
#include "util-mpm-ac.h"
#include "util-mpm-hs.h"
@ -209,7 +208,6 @@ static void RegisterUnittests(void)
DetectPortTests();
DetectEngineAlertRegisterTests();
SCAtomicRegisterTests();
MemrchrRegisterTests();
AppLayerUnittestsRegister();
StreamingBufferRegisterTests();
MacSetRegisterTests();

@ -1,77 +0,0 @@
/* Copyright (C) 2007-2013 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* \file
*
* \author Victor Julien <victor@inliniac.net>
*
*/
#include "suricata-common.h"
#include "util-unittest.h"
#include "util-memrchr.h"
#if !defined(HAVE_MEMRCHR) || defined(UNITTESTS)
static void *SCMemrchrFallback(const void *s, int c, size_t n)
{
const unsigned char *p = (const unsigned char *)s + n;
const unsigned char uc = (unsigned char)c;
while (p > (const unsigned char *)s) {
p--;
if (*p == uc)
return (void *)p;
}
return NULL;
}
#endif
#ifndef HAVE_MEMRCHR
void *memrchr(const void *s, int c, size_t n)
{
return SCMemrchrFallback(s, c, n);
}
#endif /* HAVE_MEMRCHR */
#ifdef UNITTESTS
static int MemrchrTest01 (void)
{
char buf[] = { 'x', 'y', 'z' };
char one_byte[] = { 'q' };
char dup[] = { 'a', 'b', 'a' };
unsigned char high_byte[] = { 0x80, 'x', 0x80 };
FAIL_IF(SCMemrchrFallback(buf, 'x', sizeof(buf)) != &buf[0]);
FAIL_IF(SCMemrchrFallback(buf, 'z', sizeof(buf)) != &buf[2]);
FAIL_IF(SCMemrchrFallback(buf, 'y', sizeof(buf)) != &buf[1]);
FAIL_IF(SCMemrchrFallback(buf, 'a', sizeof(buf)) != NULL);
FAIL_IF(SCMemrchrFallback(one_byte, 'q', sizeof(one_byte)) != &one_byte[0]);
FAIL_IF(SCMemrchrFallback(one_byte, 'q', 0) != NULL);
FAIL_IF(SCMemrchrFallback(dup, 'a', sizeof(dup)) != &dup[2]);
FAIL_IF(SCMemrchrFallback(high_byte, 0x80, sizeof(high_byte)) != &high_byte[2]);
PASS;
}
#endif
void MemrchrRegisterTests(void)
{
#ifdef UNITTESTS
UtRegisterTest("MemrchrTest01", MemrchrTest01);
#endif
}

@ -1,30 +0,0 @@
/* Copyright (C) 2007-2010 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* \file
*
*/
#ifndef SURICATA_UTIL_MEMRCHR_H
#define SURICATA_UTIL_MEMRCHR_H
void *memrchr(const void *s, int c, size_t n);
void MemrchrRegisterTests(void);
#endif /* SURICATA_UTIL_MEMRCHR_H */
Loading…
Cancel
Save