fileops: add convenience function is_dot_or_dotdot() Signed-off-by: schu <schu-github@schulog.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/fileops.c b/src/fileops.c
index 52aeb41..edde3aa 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -231,13 +231,8 @@ int git_futils_direach(
size_t de_len;
int result;
- /* always skip '.' and '..' */
- if (de->d_name[0] == '.') {
- if (de->d_name[1] == '\0')
- continue;
- if (de->d_name[1] == '.' && de->d_name[2] == '\0')
- continue;
- }
+ if (is_dot_or_dotdot(de->d_name))
+ continue;
de_len = strlen(de->d_name);
if (path_sz < wd_len + de_len + 1) {
diff --git a/src/fileops.h b/src/fileops.h
index 4bfebe9..cc88682 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -102,6 +102,14 @@ extern int git_futils_mv_withpath(const char *from, const char *to);
*/
extern git_off_t git_futils_filesize(git_file fd);
+/* Taken from git.git */
+static inline int is_dot_or_dotdot(const char *name)
+{
+ return (name[0] == '.' &&
+ (name[1] == '\0' ||
+ (name[1] == '.' && name[2] == '\0')));
+}
+
/**
* Read-only map all or part of a file into memory.
* When possible this function should favor a virtual memory