summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2018-05-22 15:21:08 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2018-05-22 15:27:29 +0200
commit02c80ad75d3c3d2246f4f36660281d73648d79aa (patch)
treee40e8faae52cf68882b1c527a9dc97804854e56f /src
parenta145f2b642e41dec3522dc449a2ef947ccd7a337 (diff)
downloadlibgit2-02c80ad75d3c3d2246f4f36660281d73648d79aa.tar.gz
path: accept the name length as a parameter
We may take in names from the middle of a string so we want the caller to let us know how long the path component is that we should be checking.
Diffstat (limited to 'src')
-rw-r--r--src/path.c52
-rw-r--r--src/path.h27
2 files changed, 43 insertions, 36 deletions
diff --git a/src/path.c b/src/path.c
index f8231e505..0f410cba4 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1635,10 +1635,8 @@ GIT_INLINE(bool) only_spaces_and_dots(const char *path)
return true;
}
-GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, const char *dotgit_name, const char *shortname_pfix)
+GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const char *dotgit_name, size_t dotgit_len, const char *shortname_pfix)
{
- size_t len = strlen(name);
- size_t dotgit_len = strlen(dotgit_name);
int i, saw_tilde;
if (name[0] == '.' && len >= dotgit_len &&
@@ -1842,64 +1840,64 @@ int git_path_normalize_slashes(git_buf *out, const char *path)
return 0;
}
-static int verify_dotgit_generic(const char *name, const char *dotgit_name, const char *shortname_pfix)
+static int verify_dotgit_generic(const char *name, size_t len, const char *dotgit_name, size_t dotgit_len, const char *shortname_pfix)
{
- if (!verify_dotgit_ntfs_generic(name, dotgit_name, shortname_pfix))
+ if (!verify_dotgit_ntfs_generic(name, len, dotgit_name, dotgit_len, shortname_pfix))
return false;
- return verify_dotgit_hfs_generic(name, strlen(name), dotgit_name, strlen(dotgit_name));
+ return verify_dotgit_hfs_generic(name, len, dotgit_name, dotgit_len);
}
-int git_path_is_ntfs_dotgit_modules(const char *name)
+int git_path_is_ntfs_dotgit_modules(const char *name, size_t len)
{
- return !verify_dotgit_ntfs_generic(name, "gitmodules", "gi7eba");
+ return !verify_dotgit_ntfs_generic(name, len, "gitmodules", CONST_STRLEN("gitmodules"), "gi7eba");
}
-int git_path_is_hfs_dotgit_modules(const char *name)
+int git_path_is_hfs_dotgit_modules(const char *name, size_t len)
{
- return !verify_dotgit_hfs_generic(name, strlen(name), "gitmodules", CONST_STRLEN("gitmodules"));
+ return !verify_dotgit_hfs_generic(name, len, "gitmodules", CONST_STRLEN("gitmodules"));
}
-int git_path_is_dotgit_modules(const char *name)
+int git_path_is_dotgit_modules(const char *name, size_t len)
{
- if (git_path_is_hfs_dotgit_modules(name))
+ if (git_path_is_hfs_dotgit_modules(name, len))
return 1;
- return git_path_is_ntfs_dotgit_modules(name);
+ return git_path_is_ntfs_dotgit_modules(name, len);
}
-int git_path_is_ntfs_dotgit_ignore(const char *name)
+int git_path_is_ntfs_dotgit_ignore(const char *name, size_t len)
{
- return !verify_dotgit_ntfs_generic(name, "gitignore", "gi250a");
+ return !verify_dotgit_ntfs_generic(name, len, "gitignore", CONST_STRLEN("gitignore"), "gi250a");
}
-int git_path_is_hfs_dotgit_ignore(const char *name)
+int git_path_is_hfs_dotgit_ignore(const char *name, size_t len)
{
- return !verify_dotgit_hfs_generic(name, strlen(name), "gitignore", CONST_STRLEN("gitignore"));
+ return !verify_dotgit_hfs_generic(name, len, "gitignore", CONST_STRLEN("gitignore"));
}
-int git_path_is_dotgit_ignore(const char *name)
+int git_path_is_dotgit_ignore(const char *name, size_t len)
{
- if (git_path_is_hfs_dotgit_ignore(name))
+ if (git_path_is_hfs_dotgit_ignore(name, len))
return 1;
- return git_path_is_ntfs_dotgit_ignore(name);
+ return git_path_is_ntfs_dotgit_ignore(name, len);
}
-int git_path_is_hfs_dotgit_attributes(const char *name)
+int git_path_is_hfs_dotgit_attributes(const char *name, size_t len)
{
- return !verify_dotgit_hfs_generic(name, strlen(name), "gitattributes", CONST_STRLEN("gitattributes"));
+ return !verify_dotgit_hfs_generic(name, len, "gitattributes", CONST_STRLEN("gitattributes"));
}
-int git_path_is_ntfs_dotgit_attributes(const char *name)
+int git_path_is_ntfs_dotgit_attributes(const char *name, size_t len)
{
- return !verify_dotgit_ntfs_generic(name, "gitattributes", "gi7d29");
+ return !verify_dotgit_ntfs_generic(name, len, "gitattributes", CONST_STRLEN("gitattributes"), "gi7d29");
}
-int git_path_is_dotgit_attributes(const char *name)
+int git_path_is_dotgit_attributes(const char *name, size_t len)
{
- if (git_path_is_hfs_dotgit_attributes(name))
+ if (git_path_is_hfs_dotgit_attributes(name, len))
return 1;
- return git_path_is_ntfs_dotgit_attributes(name);
+ return git_path_is_ntfs_dotgit_attributes(name, len);
}
diff --git a/src/path.h b/src/path.h
index e0812ec29..698cf4b55 100644
--- a/src/path.h
+++ b/src/path.h
@@ -648,63 +648,72 @@ int git_path_normalize_slashes(git_buf *out, const char *path);
* Check whether a path component corresponds to a .gitmodules file
*
* @param name the path component to check
+ * @param len the length of `name`
*/
-extern int git_path_is_dotgit_modules(const char *name);
+extern int git_path_is_dotgit_modules(const char *name, size_t len);
/**
* Check whether a path component corresponds to a .gitmodules file in NTFS
*
* @param name the path component to check
+ * @param len the length of `name`
*/
-extern int git_path_is_ntfs_dotgit_modules(const char *name);
+extern int git_path_is_ntfs_dotgit_modules(const char *name, size_t len);
/**
* Check whether a path component corresponds to a .gitmodules file in HFS+
*
* @param name the path component to check
+ * @param len the length of `name`
*/
-extern int git_path_is_hfs_dotgit_modules(const char *name);
+extern int git_path_is_hfs_dotgit_modules(const char *name, size_t len);
/**
* Check whether a path component corresponds to a .gitignore file
*
* @param name the path component to check
+ * @param len the length of `name`
*/
-extern int git_path_is_dotgit_ignore(const char *name);
+extern int git_path_is_dotgit_ignore(const char *name, size_t len);
/**
* Check whether a path component corresponds to a .gitignore file in NTFS
*
* @param name the path component to check
+ * @param len the length of `name`
*/
-extern int git_path_is_ntfs_dotgit_ignore(const char *name);
+extern int git_path_is_ntfs_dotgit_ignore(const char *name, size_t len);
/**
* Check whether a path component corresponds to a .gitignore file in HFS+
*
* @param name the path component to check
+ * @param len the length of `name`
*/
-extern int git_path_is_hfs_dotgit_ignore(const char *name);
+extern int git_path_is_hfs_dotgit_ignore(const char *name, size_t len);
/**
* Check whether a path component corresponds to a .gitignore file
*
* @param name the path component to check
+ * @param len the length of `name`
*/
-extern int git_path_is_dotgit_attributes(const char *name);
+extern int git_path_is_dotgit_attributes(const char *name, size_t len);
/**
* Check whether a path component corresponds to a .gitattributes file in NTFS
*
* @param name the path component to check
+ * @param len the length of `name`
*/
-extern int git_path_is_ntfs_dotgit_attributes(const char *name);
+extern int git_path_is_ntfs_dotgit_attributes(const char *name, size_t len);
/**
* Check whether a path component corresponds to a .gitattributes file in HFS+
*
* @param name the path component to check
+ * @param len the length of `name`
*/
-extern int git_path_is_hfs_dotgit_attributes(const char *name);
+extern int git_path_is_hfs_dotgit_attributes(const char *name, size_t len);
#endif