From: Marius Storm-Olsen Date: Tue, 15 Sep 2009 13:44:07 GMT Subject: [PATCH 04/14] Set _O_BINARY as default fmode for both MinGW and MSVC Message-ID: In-Reply-To: <6e6345fb3fbc19b1a2467e33e1633fe9025e547b.1253021728.git.mstormo@gmail.com> 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 --- compat/mingw.c | 2 -- compat/mingw.h | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 5478b74..5a8fae8 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -3,8 +3,6 @@ #include #include "../strbuf.h" -unsigned int _CRT_fmode = _O_BINARY; - static int err_win_to_posix(DWORD winerr) { int error = ENOSYS; diff --git a/compat/mingw.h b/compat/mingw.h index c43917c..384b667 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -229,10 +229,18 @@ void free_environ(char **env); * A replacement of main() that ensures that argv[0] has a path */ +extern int _fmode; #define main(c,v) dummy_decl_mingw_main(); \ static int mingw_main(); \ int main(int argc, const char **argv) \ { \ + _fmode = _O_BINARY; \ + if (stdin) \ + _setmode(_fileno(stdin), _O_BINARY); \ + if (stdout) \ + _setmode(_fileno(stdout), _O_BINARY); \ + if (stderr) \ + _setmode(_fileno(stderr), _O_BINARY); \ argv[0] = xstrdup(_pgmptr); \ return mingw_main(argc, argv); \ } \ -- 1.6.2.1.418.g33d56.dirty