Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/compat/stat.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / compat / stat.c` 48 lines ยท 1150 bytes Raw Blame History 1 #define _POSIX_C_SOURCE 200112L 2 #include /* *stat, S_IS* */ 3 #include /* mode_t */ 4 5 static inline mode_t mode_native_to_git(mode_t native_mode) 6 { 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. */ 23 return perm_bits; 24 } 25 26 int git_stat(const char *path, struct stat *buf) 27 { 28 int rc = stat(path, buf); 29 if (rc == 0) 30 buf->st_mode = mode_native_to_git(buf->st_mode); 31 return rc; 32 } 33 34 int git_fstat(int fd, struct stat *buf) 35 { 36 int rc = fstat(fd, buf); 37 if (rc == 0) 38 buf->st_mode = mode_native_to_git(buf->st_mode); 39 return rc; 40 } 41 42 int git_lstat(const char *path, struct stat *buf) 43 { 44 int rc = lstat(path, buf); 45 if (rc == 0) 46 buf->st_mode = mode_native_to_git(buf->st_mode); 47 return rc; 48 }