1#define COMPAT_CODE_ACCESS 2#include"../git-compat-util.h" 3 4/* Do the same thing access(2) does, but use the effective uid, 5 * and don't make the mistake of telling root that any file is 6 * executable. This version uses stat(2). 7 */ 8intgit_access(const char*path,int mode) 9{ 10struct stat st; 11 12/* do not interfere a normal user */ 13if(geteuid()) 14returnaccess(path, mode); 15 16if(stat(path, &st) <0) 17return-1; 18 19/* Root can read or write any file. */ 20if(!(mode & X_OK)) 21return0; 22 23/* Root can execute any file that has any one of the execute 24 * bits set. 25 */ 26if(st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) 27return0; 28 29 errno = EACCES; 30return-1; 31}