1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
16 #include "os_regex_internal.h"
19 * Go as fast as you can :)
22 * '|' to separate multiple OR patterns
23 * '^' to match the beginning of a string
27 static int _InternalMatch(const char *pattern, const char *str, size_t count) __attribute__((nonnull));
30 /* Search for pattern in the string */
31 int OS_WordMatch(const char *pattern, const char *str)
35 if (*pattern == '\0') {
40 if (pattern[count] == '|') {
41 /* If we match '|' , search with
44 if (_InternalMatch(pattern, str, count)) {
55 } while (pattern[count] != '\0');
57 /* Last check until end of string */
58 return (_InternalMatch(pattern, str, count));
61 static int _InternalMatch(const char *pattern, const char *str, size_t pattern_size)
63 const uchar *pt = (const uchar *)pattern;
64 const uchar *st = (const uchar *)str;
65 const uchar last_char = (const uchar) pattern[pattern_size];
67 if (*pattern == '\0') {
71 /* If '^' specified, just do a strncasecmp */
72 else if (*pattern == '^') {
76 /* Compare two strings */
77 if (strncasecmp(pattern, str, pattern_size) == 0) {
84 else if (*st == '\0') {
88 /* Look to match the first pattern */
91 if (charmap[*st] == charmap[*pt]) {
92 str = (const char *)st++;
95 while (*pt != last_char) {
100 else if (charmap[*pt] != charmap[*st]) {
108 /* Return here if pt == last_char */
112 st = (const uchar *)str;
113 pt = (const uchar *)pattern;
117 } while (*st != '\0');