1 #define _POSIX_C_SOURCE 200112L
2 #include <sys/stat.h> /* *stat, S_IS* */
3 #include <sys/types.h> /* mode_t */
5 static inline mode_t
mode_native_to_git(mode_t native_mode
)
7 mode_t perm_bits
= native_mode
& 07777;
8 if (S_ISREG(native_mode
))
9 return 0100000 | perm_bits
;
10 if (S_ISDIR(native_mode
))
11 return 0040000 | perm_bits
;
12 if (S_ISLNK(native_mode
))
13 return 0120000 | perm_bits
;
14 if (S_ISBLK(native_mode
))
15 return 0060000 | perm_bits
;
16 if (S_ISCHR(native_mode
))
17 return 0020000 | perm_bits
;
18 if (S_ISFIFO(native_mode
))
19 return 0010000 | perm_bits
;
20 if (S_ISSOCK(native_mode
))
21 return 0140000 | perm_bits
;
22 /* Non-standard type bits were given. */
26 int git_stat(const char *path
, struct stat
*buf
)
28 int rc
= stat(path
, buf
);
30 buf
->st_mode
= mode_native_to_git(buf
->st_mode
);
34 int git_fstat(int fd
, struct stat
*buf
)
36 int rc
= fstat(fd
, buf
);
38 buf
->st_mode
= mode_native_to_git(buf
->st_mode
);
42 int git_lstat(const char *path
, struct stat
*buf
)
44 int rc
= lstat(path
, buf
);
46 buf
->st_mode
= mode_native_to_git(buf
->st_mode
);