path: root/git-compat-util.h
diff options
authorRene Scharfe <>2006-08-11 12:01:45 (GMT)
committerJunio C Hamano <>2006-08-11 23:06:34 (GMT)
commit5bb1cda5f73988963e7470f3cd75a380751f6d99 (patch)
tree550b8a6f962d816b7fa0e796d1c5d1f4037d0375 /git-compat-util.h
parentca9e3b124f6313187da641b5cd55100c4ade6a9a (diff)
drop length argument of has_extension
As Fredrik points out the current interface of has_extension() is potentially confusing. Its parameters include both a nul-terminated string and a length-limited string. This patch drops the length argument, requiring two nul-terminated strings; all callsites are updated. I checked that all of them indeed provide nul-terminated strings. Filenames need to be nul-terminated anyway if they are to be passed to open() etc. The performance penalty of the additional strlen() is negligible compared to the system calls which inevitably surround has_extension() calls. Additionally, change has_extension() to use size_t inside instead of int, as that is the exact type strlen() returns and memcmp() expects. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'git-compat-util.h')
1 files changed, 3 insertions, 2 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index dd92093..b2e18954 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -139,9 +139,10 @@ static inline ssize_t xwrite(int fd, const void *buf, size_t len)
-static inline int has_extension(const char *filename, int len, const char *ext)
+static inline int has_extension(const char *filename, const char *ext)
- int extlen = strlen(ext);
+ size_t len = strlen(filename);
+ size_t extlen = strlen(ext);
return len > extlen && !memcmp(filename + len - extlen, ext, extlen);