From: Johannes Sixt Date: Thu, 15 Nov 2007 21:22:47 +0000 (+0100) Subject: Windows: Implement a wrapper of the open() function. X-Git-Tag: v1.6.0-rc0~159^2~29 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3e4a1ba07b65506c36f7f40fa76fcee26c400a5c;p=git.git Windows: Implement a wrapper of the open() function. 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 --- diff --git a/compat/mingw.c b/compat/mingw.c index 4e559bdc9..f869999a5 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/compat/mingw.h b/compat/mingw.h index a954014ff..901cfa7c8 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -137,6 +137,9 @@ 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 + char *mingw_getcwd(char *pointer, int len); #define getcwd mingw_getcwd