diff options
author | Max Kellermann <max@duempel.org> | 2015-06-22 18:55:49 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-06-22 22:12:08 +0200 |
commit | bc8542503d5b99c1bf2d5d2748e49d9257e3fd25 (patch) | |
tree | 6e3662dd151fe9395cd680c5bf6664312214b498 /src | |
parent | a6aea4ba5859099eb6456f33a917c728b8558805 (diff) |
fs/Glob: use fnmatch() if available
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/Glob.hxx | 22 |
1 files changed, 21 insertions, 1 deletions
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 <string> +#include <fnmatch.h> +#elif defined(HAVE_GLIB) #define HAVE_CLASS_GLOB #include <glib.h> #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 } }; |