1#include "../git-compat-util.h"
2#undef fopen
3FILE *git_fopen(const char *path, const char *mode)
4{
5FILE *fp;
6struct stat st;
78
if (mode[0] == 'w' || mode[0] == 'a')
9return fopen(path, mode);
1011
if (!(fp = fopen(path, mode)))
12return NULL;
1314
if (fstat(fileno(fp), &st)) {
15fclose(fp);
16return NULL;
17}
1819
if (S_ISDIR(st.st_mode)) {
20fclose(fp);
21errno = EISDIR;
22return NULL;
23}
2425
return fp;
26}