diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-06-22 16:52:30 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-06-26 18:18:11 +0200 |
| commit | 63f91e1ce856da0a6cfd7ec70f24b087a30ef358 (patch) | |
| tree | 0f6cf49a95e246d46b15ad32df5506bca2f393f0 /src/util.c | |
| parent | f8f3feb0d3e98542b6f7a4ac214a65e7f9950d5b (diff) | |
| download | libgit2-63f91e1ce856da0a6cfd7ec70f24b087a30ef358.tar.gz | |
Add git.git's fnmatch, which is really GNU's and the git__fnmatch wrapper
If the strings match, git__fnmatch returns GIT_SUCCESS and
GIT_ENOMATCH on failure to match.
MSVC fixes: Added a test for _MSC_VER and (in that case) defined
HAVE_STRING_H to 1 so it doesn't try to include <strings.h> which
doesn't exist in the MSVC world. Moved the function declarations to
use the modern inline ones so MSVC doesn't have a fit. Added casts
everywhere so MSVC doesn't crap its pants.
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index f36cce5fe..ecbed9012 100644 --- a/src/util.c +++ b/src/util.c @@ -1,10 +1,17 @@ #define GIT__NO_HIDE_MALLOC #include <git2.h> #include "common.h" +#include "fnmatch.h" #include <stdarg.h> #include <stdio.h> #include <ctype.h> +#ifdef _MSV_VER +# include <Shlwapi.h> +#else +# include <fnmatch.h> +#endif + void git_libgit2_version(int *major, int *minor, int *rev) { *major = LIBGIT2_VER_MAJOR; @@ -21,6 +28,21 @@ void git_strarray_free(git_strarray *array) free(array->strings); } +int git__fnmatch(const char *pattern, const char *name, int flags) +{ + int ret; + + ret = fnmatch(pattern, name, flags); + switch (ret) { + case 0: + return GIT_SUCCESS; + case FNM_NOMATCH: + return GIT_ENOMATCH; + default: + return git__throw(GIT_EOSERR, "Error trying to match path"); + } +} + int git__strtol32(long *result, const char *nptr, const char **endptr, int base) { const char *p; |
