dcerpc-nt: add UNION_ALIGN_TO... helpers
[wireshark-sm.git] / wsutil / ws_mempbrk.c
blob55334242f805ac48b2beb47ef89db6967c27941e
1 /* ws_mempbrk.c
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include "config.h"
12 /* see bug 10798: there is a bug in the compiler the buildbots use for Mac OSX
13 and SSE4.2, so we're not going to use SSE4.2 with Mac OSX right now, for
14 older Mac OSX compilers.
16 #ifdef __APPLE__
17 #if defined(__clang__) && (__clang_major__ >= 6)
18 /* allow HAVE_SSE4_2 to be used for clang 6.0+ case because we know it works */
19 #else
20 /* don't allow it otherwise, for Mac OSX */
21 #undef HAVE_SSE4_2
22 #endif
23 #endif
25 #include "ws_mempbrk.h"
26 #include "ws_mempbrk_int.h"
28 #include <string.h>
30 void
31 ws_mempbrk_compile(ws_mempbrk_pattern* pattern, const char *needles)
33 const char *n = needles;
34 memset(pattern->patt, 0, 256);
35 while (*n) {
36 pattern->patt[(int)*n] = 1;
37 n++;
40 #ifdef HAVE_SSE4_2
41 ws_mempbrk_sse42_compile(pattern, needles);
42 #endif
46 const uint8_t *
47 ws_mempbrk_portable_exec(const uint8_t* haystack, size_t haystacklen, const ws_mempbrk_pattern* pattern, unsigned char *found_needle)
49 const uint8_t *haystack_end = haystack + haystacklen;
51 while (haystack < haystack_end) {
52 if (pattern->patt[*haystack]) {
53 if (found_needle)
54 *found_needle = *haystack;
55 return haystack;
57 haystack++;
60 return NULL;
64 WS_DLL_PUBLIC const uint8_t *
65 ws_mempbrk_exec(const uint8_t* haystack, size_t haystacklen, const ws_mempbrk_pattern* pattern, unsigned char *found_needle)
67 #ifdef HAVE_SSE4_2
68 if (haystacklen >= 16 && pattern->use_sse42)
69 return ws_mempbrk_sse42_exec(haystack, haystacklen, pattern, found_needle);
70 #endif
72 return ws_mempbrk_portable_exec(haystack, haystacklen, pattern, found_needle);
75 WS_DLL_PUBLIC const uint8_t *
76 ws_memrpbrk_exec(const uint8_t* haystack, size_t haystacklen, const ws_mempbrk_pattern* pattern, unsigned char *found_needle)
78 const uint8_t *haystack_end = haystack + haystacklen;
80 while (haystack_end > haystack) {
81 if (pattern->patt[*(--haystack_end)]) {
82 if (found_needle)
83 *found_needle = *haystack_end;
84 return haystack_end;
88 return NULL;
92 * Editor modelines - https://www.wireshark.org/tools/modelines.html
94 * Local variables:
95 * c-basic-offset: 8
96 * tab-width: 8
97 * indent-tabs-mode: t
98 * End:
100 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
101 * :indentSize=8:tabSize=8:noTabs=false: