t4200: use cut instead of sed
[git/peff.git] / compat / fopen.c
blobccb9e89fa46144744fa530930d8db7644ab2da74
1 #include "../git-compat-util.h"
2 #undef fopen
3 FILE *git_fopen(const char *path, const char *mode)
5 FILE *fp;
6 struct stat st;
8 if (mode[0] == 'w' || mode[0] == 'a')
9 return fopen(path, mode);
11 if (!(fp = fopen(path, mode)))
12 return NULL;
14 if (fstat(fileno(fp), &st)) {
15 fclose(fp);
16 return NULL;
19 if (S_ISDIR(st.st_mode)) {
20 fclose(fp);
21 errno = EISDIR;
22 return NULL;
25 return fp;