From bc8542503d5b99c1bf2d5d2748e49d9257e3fd25 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 22 Jun 2015 18:55:49 +0200 Subject: fs/Glob: use fnmatch() if available --- src/fs/Glob.hxx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/fs/Glob.hxx b/src/fs/Glob.hxx index 493b3beba..b7307feea 100644 --- a/src/fs/Glob.hxx +++ b/src/fs/Glob.hxx @@ -22,7 +22,11 @@ #include "check.h" -#ifdef HAVE_GLIB +#ifdef HAVE_FNMATCH +#define HAVE_CLASS_GLOB +#include +#include +#elif defined(HAVE_GLIB) #define HAVE_CLASS_GLOB #include #endif @@ -35,9 +39,20 @@ * (asterisk and question mark). */ class Glob { +#ifdef HAVE_FNMATCH + std::string pattern; +#else GPatternSpec *pattern; +#endif public: +#ifdef HAVE_FNMATCH + explicit Glob(const char *_pattern) + :pattern(_pattern) {} + + Glob(Glob &&other) + :pattern(std::move(other.pattern)) {} +#else explicit Glob(const char *_pattern) :pattern(g_pattern_spec_new(_pattern)) {} @@ -49,10 +64,15 @@ public: ~Glob() { g_pattern_spec_free(pattern); } +#endif gcc_pure bool Check(const char *name_fs) const { +#ifdef HAVE_FNMATCH + return fnmatch(pattern.c_str(), name_fs, 0) == 0; +#else return g_pattern_match_string(pattern, name_fs); +#endif } }; -- cgit v1.2.3