diff options
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 5604fdda5..cc266462f 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -115,6 +115,40 @@ static int err_win_to_posix(DWORD winerr) | |||
115 | return error; | 115 | return error; |
116 | } | 116 | } |
117 | 117 | ||
118 | #undef open | ||
119 | int mingw_open (const char *filename, int oflags, ...) | ||
120 | { | ||
121 | va_list args; | ||
122 | unsigned mode; | ||
123 | int fd; | ||
124 | |||
125 | va_start(args, oflags); | ||
126 | mode = va_arg(args, int); | ||
127 | va_end(args); | ||
128 | |||
129 | if (oflags & O_NONBLOCK) { | ||
130 | errno = ENOSYS; | ||
131 | return -1; | ||
132 | } | ||
133 | if (!strcmp(filename, "/dev/null")) | ||
134 | filename = "nul"; | ||
135 | fd = open(filename, oflags, mode); | ||
136 | if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) { | ||
137 | DWORD attrs = GetFileAttributes(filename); | ||
138 | if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) | ||
139 | errno = EISDIR; | ||
140 | } | ||
141 | return fd; | ||
142 | } | ||
143 | |||
144 | #undef fopen | ||
145 | FILE *mingw_fopen (const char *filename, const char *mode) | ||
146 | { | ||
147 | if (!strcmp(filename, "/dev/null")) | ||
148 | filename = "nul"; | ||
149 | return fopen(filename, mode); | ||
150 | } | ||
151 | |||
118 | unsigned int sleep (unsigned int seconds) | 152 | unsigned int sleep (unsigned int seconds) |
119 | { | 153 | { |
120 | Sleep(seconds*1000); | 154 | Sleep(seconds*1000); |