Skip to content

Commit a6ca8c6

Browse files
Marius Storm-Olsengitster
authored andcommitted
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>
1 parent 3f83bf3 commit a6ca8c6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

compat/mingw.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include <conio.h>
44
#include "../strbuf.h"
55

6-
unsigned int _CRT_fmode = _O_BINARY;
7-
86
static int err_win_to_posix(DWORD winerr)
97
{
108
int error = ENOSYS;

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,17 @@ void free_environ(char **env);
227227

228228
/*
229229
* 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
230231
*/
231232

232233
#define main(c,v) dummy_decl_mingw_main(); \
233234
static int mingw_main(); \
234235
int main(int argc, const char **argv) \
235236
{ \
237+
_fmode = _O_BINARY; \
238+
_setmode(_fileno(stdin), _O_BINARY); \
239+
_setmode(_fileno(stdout), _O_BINARY); \
240+
_setmode(_fileno(stderr), _O_BINARY); \
236241
argv[0] = xstrdup(_pgmptr); \
237242
return mingw_main(argc, argv); \
238243
} \

0 commit comments

Comments
 (0)