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