[filesystem.c] Add a cast to aviod a warning with VisualStudio 2017.
[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  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include "config.h"
23
24 /* see bug 10798: there is a bug in the compiler the buildbots use for Mac OSX
25    and SSE4.2, so we're not going to use SSE4.2 with Mac OSX right now, for
26    older Mac OSX compilers.
27  */
28 #ifdef __APPLE__
29 #if defined(__clang__) && (__clang_major__ >= 6)
30 /* allow HAVE_SSE4_2 to be used for clang 6.0+ case because we know it works */
31 #else
32 /* don't allow it otherwise, for Mac OSX */
33 #undef HAVE_SSE4_2
34 #endif
35 #endif
36
37 #include <glib.h>
38 #include "ws_symbol_export.h"
39 #include "ws_mempbrk.h"
40 #include "ws_mempbrk_int.h"
41
42 void
43 ws_mempbrk_compile(ws_mempbrk_pattern* pattern, const gchar *needles)
44 {
45     const gchar *n = needles;
46     while (*n) {
47         pattern->patt[(int)*n] = 1;
48         n++;
49     }
50
51 #ifdef HAVE_SSE4_2
52     ws_mempbrk_sse42_compile(pattern, needles);
53 #endif
54 }
55
56
57 const guint8 *
58 ws_mempbrk_portable_exec(const guint8* haystack, size_t haystacklen, const ws_mempbrk_pattern* pattern, guchar *found_needle)
59 {
60     const guint8 *haystack_end = haystack + haystacklen;
61
62     while (haystack < haystack_end) {
63         if (pattern->patt[*haystack]) {
64             if (found_needle)
65                 *found_needle = *haystack;
66             return haystack;
67         }
68         haystack++;
69     }
70
71     return NULL;
72 }
73
74
75 WS_DLL_PUBLIC const guint8 *
76 ws_mempbrk_exec(const guint8* haystack, size_t haystacklen, const ws_mempbrk_pattern* pattern, guchar *found_needle)
77 {
78 #ifdef HAVE_SSE4_2
79     if (haystacklen >= 16 && pattern->use_sse42)
80         return ws_mempbrk_sse42_exec(haystack, haystacklen, pattern, found_needle);
81 #endif
82
83     return ws_mempbrk_portable_exec(haystack, haystacklen, pattern, found_needle);
84 }
85
86
87 /*
88  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
89  *
90  * Local variables:
91  * c-basic-offset: 8
92  * tab-width: 8
93  * indent-tabs-mode: t
94  * End:
95  *
96  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
97  * :indentSize=8:tabSize=8:noTabs=false:
98  */