summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 23326d1)
raw | patch | inline | side by side (parent: 23326d1)
author | Johannes Sixt <johannes.sixt@telecom.at> | |
Thu, 15 Nov 2007 21:22:47 +0000 (22:22 +0100) | ||
committer | Johannes Sixt <johannes.sixt@telecom.at> | |
Mon, 23 Jun 2008 11:38:07 +0000 (13:38 +0200) |
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>
- 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>
compat/mingw.c | patch | blob | history | |
compat/mingw.h | patch | blob | history |
diff --git a/compat/mingw.c b/compat/mingw.c
index 4e559bdc93dbee413fd574168fd382e4682a0092..f869999a5d6ac7b2a7a78781c0c6e16d3446e98f 100644 (file)
--- a/compat/mingw.c
+++ b/compat/mingw.c
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 a954014ff2a815a931fcb968308aa11739b544c1..901cfa7c82981a1cfdffca3f73334e1dcf6dfed1 100644 (file)
--- a/compat/mingw.h
+++ b/compat/mingw.h
* 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