From: Consus Date: Sun, 1 Oct 2023 11:39:47 +0000 (+0300) Subject: common: use fnmatch() for pattern matching X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=3e5b988d38a55f40ad90e56d1f3e9b084c3f792e;p=proto%2Flabwc.git common: use fnmatch() for pattern matching Drop-in POSIX-compliant function that has a nice glob(7) manual page for reference. --- diff --git a/include/common/match.h b/include/common/match.h index c49f2187..477f1ade 100644 --- a/include/common/match.h +++ b/include/common/match.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #ifndef LABWC_MATCH_H #define LABWC_MATCH_H -#include + #include /** @@ -10,6 +10,6 @@ * @string: String to search. * Note: Comparison case-insensitive. */ -bool match_glob(const gchar *pattern, const gchar *string); +bool match_glob(const char *pattern, const char *string); #endif /* LABWC_MATCH_H */ diff --git a/src/common/match.c b/src/common/match.c index 6c573fb9..9bc3cf8b 100644 --- a/src/common/match.c +++ b/src/common/match.c @@ -1,15 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-only -#define _POSIX_C_SOURCE 200809L + +#include #include "common/match.h" bool -match_glob(const gchar *pattern, const gchar *string) +match_glob(const char *pattern, const char *string) { - gchar *p = g_utf8_casefold(pattern, -1); - gchar *s = g_utf8_casefold(string, -1); - bool ret = g_pattern_match_simple(p, s); - g_free(p); - g_free(s); - return ret; + return fnmatch(pattern, string, FNM_CASEFOLD) == 0; } -