HTTPS (almost) everywhere.
[metze/wireshark/wip.git] / wsutil / ws_mempbrk.c
1 /* ws_mempbrk.c
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "config.h"
11
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.
15  */
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
24
25 #include <glib.h>
26 #include "ws_symbol_export.h"
27 #include "ws_mempbrk.h"
28 #include "ws_mempbrk_int.h"
29
30 void
31 ws_mempbrk_compile(ws_mempbrk_pattern* pattern, const gchar *needles)
32 {
33     const gchar *n = needles;
34     while (*n) {
35         pattern->patt[(int)*n] = 1;
36         n++;
37     }
38
39 #ifdef HAVE_SSE4_2
40     ws_mempbrk_sse42_compile(pattern, needles);
41 #endif
42 }
43
44
45 const guint8 *
46 ws_mempbrk_portable_exec(const guint8* haystack, size_t haystacklen, const ws_mempbrk_pattern* pattern, guchar *found_needle)
47 {
48     const guint8 *haystack_end = haystack + haystacklen;
49
50     while (haystack < haystack_end) {
51         if (pattern->patt[*haystack]) {
52             if (found_needle)
53                 *found_needle = *haystack;
54             return haystack;
55         }
56         haystack++;
57     }
58
59     return NULL;
60 }
61
62
63 WS_DLL_PUBLIC const guint8 *
64 ws_mempbrk_exec(const guint8* haystack, size_t haystacklen, const ws_mempbrk_pattern* pattern, guchar *found_needle)
65 {
66 #ifdef HAVE_SSE4_2
67     if (haystacklen >= 16 && pattern->use_sse42)
68         return ws_mempbrk_sse42_exec(haystack, haystacklen, pattern, found_needle);
69 #endif
70
71     return ws_mempbrk_portable_exec(haystack, haystacklen, pattern, found_needle);
72 }
73
74
75 /*
76  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
77  *
78  * Local variables:
79  * c-basic-offset: 8
80  * tab-width: 8
81  * indent-tabs-mode: t
82  * End:
83  *
84  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
85  * :indentSize=8:tabSize=8:noTabs=false:
86  */