The wrapper does two things: - Requests to open /dev/null are redirected to open the nul pseudo file. - A request to open a file that currently exists as a directory on Windows fails with EACCES; this is changed to EISDIR. Signed-off-by: Johannes Sixt <johannes.sixt@xxxxxxxxxx> --- compat/mingw.c | 20 ++++++++++++++++++++ git-compat-util.h | 7 +++++++ 2 files changed, 27 insertions(+), 0 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 0c87e43..faa6df3 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2,6 +2,26 @@ unsigned int _CRT_fmode = _O_BINARY; +#undef open +int mingw_open (const char *filename, int oflags, ...) +{ + va_list args; + unsigned mode; + va_start(args, oflags); + mode = va_arg(args, int); + va_end(args); + + if (!strcmp(filename, "/dev/null")) + filename = "nul"; + int fd = open(filename, oflags, mode); + if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) { + DWORD attrs = GetFileAttributes(filename); + if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) + errno = EISDIR; + } + return fd; +} + unsigned int sleep (unsigned int seconds) { Sleep(seconds*1000); diff --git a/git-compat-util.h b/git-compat-util.h index b1f3f92..672c074 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -577,6 +577,13 @@ struct passwd *getpwuid(int uid); int setitimer(int type, struct itimerval *in, struct itimerval *out); int sigaction(int sig, struct sigaction *in, struct sigaction *out); +/* + * replacements of existing functions + */ + +int mingw_open (const char *filename, int oflags, ...); +#define open mingw_open + #endif /* __MINGW32__ */ #endif -- 1.5.4.1.126.ge5a7d - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html