summaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorDavid Michael <fedora.dm0@gmail.com>2014-12-04 02:24:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-12-04 19:58:36 (GMT)
commitd543d9c0f44a89f30ec1670f16c698b5da801476 (patch)
treea4b23afa1f7297104e9a56ff13c78f467d668eb9 /git-compat-util.h
parent7fa1365c54c28b3cd9375539f381b54061a1880d (diff)
downloadgit-d543d9c0f44a89f30ec1670f16c698b5da801476.zip
git-d543d9c0f44a89f30ec1670f16c698b5da801476.tar.gz
git-d543d9c0f44a89f30ec1670f16c698b5da801476.tar.bz2
compat: convert modes to use portable file type values
This adds simple wrapper functions around calls to stat(), fstat(), and lstat() that translate the operating system's native file type bits to those used by most operating systems. It also rewrites the S_IF* macros to the common values, so all file type processing is performed using the translated modes. This makes projects portable across operating systems that use different file type definitions. Only the file type bits may be affected by these compatibility functions; the file permission bits are assumed to be 07777 and are passed through unchanged. Signed-off-by: David Michael <fedora.dm0@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index f587749..9dfefb2 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -455,6 +455,40 @@ extern int git_munmap(void *start, size_t length);
#define on_disk_bytes(st) ((st).st_blocks * 512)
#endif
+#ifdef NEEDS_MODE_TRANSLATION
+#undef S_IFMT
+#undef S_IFREG
+#undef S_IFDIR
+#undef S_IFLNK
+#undef S_IFBLK
+#undef S_IFCHR
+#undef S_IFIFO
+#undef S_IFSOCK
+#define S_IFMT 0170000
+#define S_IFREG 0100000
+#define S_IFDIR 0040000
+#define S_IFLNK 0120000
+#define S_IFBLK 0060000
+#define S_IFCHR 0020000
+#define S_IFIFO 0010000
+#define S_IFSOCK 0140000
+#ifdef stat
+#undef stat
+#endif
+#define stat(path, buf) git_stat(path, buf)
+extern int git_stat(const char *, struct stat *);
+#ifdef fstat
+#undef fstat
+#endif
+#define fstat(fd, buf) git_fstat(fd, buf)
+extern int git_fstat(int, struct stat *);
+#ifdef lstat
+#undef lstat
+#endif
+#define lstat(path, buf) git_lstat(path, buf)
+extern int git_lstat(const char *, struct stat *);
+#endif
+
#define DEFAULT_PACKED_GIT_LIMIT \
((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))