]> git.mdlowis.com Git - proto/labwc.git/commitdiff
common: use fnmatch() for pattern matching
authorConsus <consus@ftml.net>
Sun, 1 Oct 2023 11:39:47 +0000 (14:39 +0300)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 1 Oct 2023 13:17:29 +0000 (14:17 +0100)
Drop-in POSIX-compliant function that has a nice glob(7) manual page for
reference.

include/common/match.h
src/common/match.c

index c49f2187d219aa0937deb7117123b1136bb73273..477f1adef9ebf10d0ae8a072cee35d1a742c79ae 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 #ifndef LABWC_MATCH_H
 #define LABWC_MATCH_H
-#include <glib.h>
+
 #include <stdbool.h>
 
 /**
@@ -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 */
index 6c573fb957d24e6648e25b92f56dbf0cc789f5c4..9bc3cf8ba303fee2ef87c2f3ef2745d31cbcd809 100644 (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;
 }
-