Skip to content

Commit

Permalink
Set _O_BINARY as default fmode for both MinGW and MSVC
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Marius Storm-Olsen authored and gitster committed Sep 19, 2009
1 parent 3f83bf3 commit a6ca8c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 0 additions & 2 deletions compat/mingw.c
Expand Up @@ -3,8 +3,6 @@
#include <conio.h>
#include "../strbuf.h"

unsigned int _CRT_fmode = _O_BINARY;

static int err_win_to_posix(DWORD winerr)
{
int error = ENOSYS;
Expand Down
5 changes: 5 additions & 0 deletions compat/mingw.h
Expand Up @@ -227,12 +227,17 @@ void free_environ(char **env);

/*
* A replacement of main() that ensures that argv[0] has a path
* and that default fmode and std(in|out|err) are in binary mode
*/

#define main(c,v) dummy_decl_mingw_main(); \
static int mingw_main(); \
int main(int argc, const char **argv) \
{ \
_fmode = _O_BINARY; \
_setmode(_fileno(stdin), _O_BINARY); \
_setmode(_fileno(stdout), _O_BINARY); \
_setmode(_fileno(stderr), _O_BINARY); \
argv[0] = xstrdup(_pgmptr); \
return mingw_main(argc, argv); \
} \
Expand Down

0 comments on commit a6ca8c6

Please sign in to comment.