diff options
author | Johannes Sixt <johannes.sixt@telecom.at> | 2007-11-15 22:22:47 +0100 |
---|---|---|
committer | Johannes Sixt <johannes.sixt@telecom.at> | 2008-06-23 13:38:07 +0200 |
commit | 3e4a1ba07b65506c36f7f40fa76fcee26c400a5c (patch) | |
tree | b17b947348df45d0c1b44d315a119a04c0430cbb /compat/mingw.c | |
parent | 23326d14edbd16469453f6c3ecdd98ab90e6efb7 (diff) | |
download | git-3e4a1ba07b65506c36f7f40fa76fcee26c400a5c.tar.gz git-3e4a1ba07b65506c36f7f40fa76fcee26c400a5c.tar.xz |
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 <johannes.sixt@telecom.at>
Diffstat (limited to 'compat/mingw.c')
-rw-r--r-- | compat/mingw.c | 20 |
1 files changed, 20 insertions, 0 deletions
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); |