Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  *  The order of the following two lines is important.  | 
3  |  |  *  | 
4  |  |  *  SUPPRESS_FOPEN_REDEFINITION is defined before including git-compat-util.h  | 
5  |  |  *  to avoid the redefinition of fopen within git-compat-util.h. This is  | 
6  |  |  *  necessary since fopen is a macro on some platforms which may be set  | 
7  |  |  *  based on compiler options. For example, on AIX fopen is set to fopen64  | 
8  |  |  *  when _LARGE_FILES is defined. The previous technique of merely undefining  | 
9  |  |  *  fopen after including git-compat-util.h is inadequate in this case.  | 
10  |  |  */  | 
11  |  | #define SUPPRESS_FOPEN_REDEFINITION  | 
12  |  | #include "../git-compat-util.h"  | 
13  |  |  | 
14  |  | FILE *git_fopen(const char *path, const char *mode)  | 
15  | 0  | { | 
16  | 0  |   FILE *fp;  | 
17  | 0  |   struct stat st;  | 
18  |  | 
  | 
19  | 0  |   if (mode[0] == 'w' || mode[0] == 'a')  | 
20  | 0  |     return fopen(path, mode);  | 
21  |  |  | 
22  | 0  |   if (!(fp = fopen(path, mode)))  | 
23  | 0  |     return NULL;  | 
24  |  |  | 
25  | 0  |   if (fstat(fileno(fp), &st)) { | 
26  | 0  |     fclose(fp);  | 
27  | 0  |     return NULL;  | 
28  | 0  |   }  | 
29  |  |  | 
30  | 0  |   if (S_ISDIR(st.st_mode)) { | 
31  | 0  |     fclose(fp);  | 
32  | 0  |     errno = EISDIR;  | 
33  | 0  |     return NULL;  | 
34  | 0  |   }  | 
35  |  |  | 
36  | 0  |   return fp;  | 
37  | 0  | }  |