Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2013-10-10 02:26:42 +0400
committerEdward Thomson <ethomson@microsoft.com>2013-10-17 00:20:24 +0400
commitc929d6b727cb35a681152ae2c7d6dfbaf971f829 (patch)
treee45734363923b2dbb240a93a027fe2abf6fa8db3 /src/path.h
parent7fa73de16378ecfa484747d1b61656282923a88a (diff)
Move path prefixed help to path.h
Diffstat (limited to 'src/path.h')
-rw-r--r--src/path.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/path.h b/src/path.h
index eaf94d486..17f4f7726 100644
--- a/src/path.h
+++ b/src/path.h
@@ -358,6 +358,34 @@ extern int git_path_dirload_with_stat(
const char *end_stat,
git_vector *contents);
+enum { GIT_PATH_NOTEQUAL = 0, GIT_PATH_EQUAL = 1, GIT_PATH_PREFIX = 2 };
+
+/*
+ * Determines if a path is equal to or potentially a child of another.
+ * @param parent The possible parent
+ * @param child The possible child
+ */
+GIT_INLINE(int) git_path_equal_or_prefixed(
+ const char *parent,
+ const char *child)
+{
+ const char *p = parent, *c = child;
+
+ while (*p && *c) {
+ if (*p++ != *c++)
+ return GIT_PATH_NOTEQUAL;
+ }
+
+ if (*p != '\0')
+ return GIT_PATH_NOTEQUAL;
+ if (*c == '\0')
+ return GIT_PATH_EQUAL;
+ if (*c == '/')
+ return GIT_PATH_PREFIX;
+
+ return GIT_PATH_NOTEQUAL;
+}
+
/* translate errno to libgit2 error code and set error message */
extern int git_path_set_error(
int errno_value, const char *path, const char *action);