summaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-01-09 16:02:42 -0800
committerRussell Belfer <rb@github.com>2013-01-15 09:51:35 -0800
commit23594c1dae08c9a53f571dbf9de7ff0b6a6a0d45 (patch)
tree15b1395fcabbdefba9fa24051d6a49a998685cc0 /src/path.c
parent851ad65081793bb5fd65052907bf1c3c4e7e5729 (diff)
downloadlibgit2-23594c1dae08c9a53f571dbf9de7ff0b6a6a0d45.tar.gz
Add git_path_icmp to case-insensitive path cmp
This adds git_path_icmp to complement git_path_cmp.
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c
index 0fd367eaf..5de58cce7 100644
--- a/src/path.c
+++ b/src/path.c
@@ -701,6 +701,30 @@ int git_path_cmp(
return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
}
+int git_path_icmp(
+ const char *name1, size_t len1, int isdir1,
+ const char *name2, size_t len2, int isdir2)
+{
+ unsigned char c1, c2;
+ size_t len = len1 < len2 ? len1 : len2;
+ int cmp;
+
+ cmp = strncasecmp(name1, name2, len);
+ if (cmp)
+ return cmp;
+
+ c1 = name1[len];
+ c2 = name2[len];
+
+ if (c1 == '\0' && isdir1)
+ c1 = '/';
+
+ if (c2 == '\0' && isdir2)
+ c2 = '/';
+
+ return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
+}
+
int git_path_direach(
git_buf *path,
int (*fn)(void *, git_buf *),