Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
938 B

* The order of the following two lines is important.
* SUPPRESS_FOPEN_REDEFINITION is defined before including git-compat-util.h
* to avoid the redefinition of fopen within git-compat-util.h. This is
* necessary since fopen is a macro on some platforms which may be set
* based on compiler options. For example, on AIX fopen is set to fopen64
* when _LARGE_FILES is defined. The previous technique of merely undefining
* fopen after including git-compat-util.h is inadequate in this case.
#include "../git-compat-util.h"
FILE *git_fopen(const char *path, const char *mode)
FILE *fp;
struct stat st;
if (mode[0] == 'w' || mode[0] == 'a')
return fopen(path, mode);
if (!(fp = fopen(path, mode)))
return NULL;
if (fstat(fileno(fp), &st)) {
return NULL;
if (S_ISDIR(st.st_mode)) {
errno = EISDIR;
return NULL;
return fp;