common: use fnmatch() for pattern matching

Drop-in POSIX-compliant function that has a nice glob(7) manual page for
reference.
This commit is contained in:
Consus 2023-10-01 14:39:47 +03:00 committed by Johan Malm
parent e864419194
commit 3e5b988d38
2 changed files with 6 additions and 11 deletions

View file

@ -1,15 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-only
#define _POSIX_C_SOURCE 200809L
#include <fnmatch.h>
#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;
}