1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (compat_fnmatch.c).
5 * ---------------------------------------------------------------------------------------
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include <compat/fnmatch.h>
27 /* Implemnentation of fnmatch(3) so it can be
28 * distributed to non *nix platforms.
30 * No flags are implemented ATM.
31 * We don't use them. Add flags as needed. */
33 int rl_fnmatch(const char *pattern, const char *string, int flags)
39 for (c = pattern; *c != '\0'; c++)
41 /* String ended before pattern */
42 if ((*c != '*') && (*string == '\0'))
47 /* Match any number of unknown chars */
49 /* Find next node in the pattern
50 * ignoring multiple asterixes
58 /* Match the remaining pattern
59 * ignoring more and more characters. */
61 /* We reached the end of the string without a
62 * match. There is a way to optimize this by
63 * calculating the minimum chars needed to
64 * match the remaining pattern but I don't
65 * think it is worth the work ATM.
70 rv = rl_fnmatch(c, string, flags);
75 /* Match char from list */
78 for (c++; *c != ']'; c++)
84 /* Match already found */
92 /* No match in list */
98 /* Has any character */
102 /* Match following character verbatim */
105 /* Dangling escape at end of pattern.
106 * FIXME: Was c == '\0' (makes no sense).
107 * Not sure if c == NULL or *c == '\0'
108 * is intended. Assuming *c due to c++ right before. */
118 /* End of string and end of pattend */