Set _O_BINARY as default fmode for both MinGW and MSVC
MinGW set the _CRT_fmode to set both the default fmode and _O_BINARY on stdin/stdout/stderr. Rather use the main() define in mingw.h to set this for both MinGW and MSVC. This will ensure that a MinGW and MSVC build will handle input and output identically. Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Marius Storm-Olsen committed
Sep 16, 2009 at 10:20 UTC
a6ca8c62467570d5d227eba4f2b838ce4b9940e8
2 files changed
+5
-2
compat/mingw.c
-2
@@ -3,8 +3,6 @@
3
#include <conio.h>
4
#include "../strbuf.h"
5
6
-unsigned int _CRT_fmode = _O_BINARY;
7
-
6
static int err_win_to_posix(DWORD winerr)
7
{
8
int error = ENOSYS;
compat/mingw.h
+5
@@ -227,12 +227,17 @@ void free_environ(char **env);
227
228
/*
229
* A replacement of main() that ensures that argv[0] has a path
230
+ * and that default fmode and std(in|out|err) are in binary mode
231
*/
232
233
#define main(c,v) dummy_decl_mingw_main(); \
234
static int mingw_main(); \
235
int main(int argc, const char **argv) \
236
{ \
237
+ _fmode = _O_BINARY; \
238
+ _setmode(_fileno(stdin), _O_BINARY); \
239
+ _setmode(_fileno(stdout), _O_BINARY); \
240
+ _setmode(_fileno(stderr), _O_BINARY); \
241
argv[0] = xstrdup(_pgmptr); \
242
return mingw_main(argc, argv); \
243
} \