All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marius Storm-Olsen <mstormo@gmail.com>
To: git@vger.kernel.org
Cc: Johannes.Schindelin@gmx.de, msysgit@googlegroups.com,
	gitster@pobox.com, j6t@kdbg.org, lznuaa@gmail.com,
	raa.lkml@gmail.com, snaury@gmail.com,
	Marius Storm-Olsen <mstormo@gmail.com>
Subject: [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC
Date: Thu, 17 Sep 2009 13:04:29 +0200	[thread overview]
Message-ID: <6e9b7c953e20a984bb519f3fe374cef03ca144a7.1253185334.git.mstormo@gmail.com> (raw)
In-Reply-To: <4AB212FA.9080102@viscovery.netm>

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.

Alexey Borzenkov:
Include git-compat-util.h from the test-genrandom.c so
that the application also will use the main() define,
and thus the stdout mode is set correctly and generated
data stays the same.

Johannes Sixt:
Before, since the test-genrandom application would link
against libgit.a, the MinGW process initialization code
would pick up the definition of _CRT_fmode from mingw.c
that is initialized to _O_BINARY. After this patch,
however, the _CRT_fmode symbol is no longer present in
libgit.a, so MinGWs process initialization code will not
set the correct std(in|out|err) mode. So, the include is
needed to override main() and explicitly set the mode.

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 Gaaaaah! Sorry for not reading Alexey's patch properly.
 Multitasking is not working to my advantage these days..

 compat/mingw.c   |    2 --
 compat/mingw.h   |    5 +++++
 test-genrandom.c |    3 +--
 3 files changed, 6 insertions(+), 4 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 <conio.h>
 #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..bcd23b0 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -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); \
 } \
diff --git a/test-genrandom.c b/test-genrandom.c
index 8ad276d..b3c28d9 100644
--- a/test-genrandom.c
+++ b/test-genrandom.c
@@ -4,8 +4,7 @@
  * Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
+#include "git-compat-util.h"
 
 int main(int argc, char *argv[])
 {
-- 
1.6.2.1.418.g33d56.dirty

  parent reply	other threads:[~2009-09-17 11:04 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-16  8:20 [PATCH v4 00/15] Build Git with MSVC Marius Storm-Olsen
2009-09-16  8:20 ` [PATCH 01/15] Avoid declaration after statement Marius Storm-Olsen
2009-09-16  8:20   ` [PATCH 02/15] Add define guards to compat/win32.h Marius Storm-Olsen
2009-09-16  8:20     ` [PATCH 03/15] Change regerror() declaration from K&R style to ANSI C (C89) Marius Storm-Olsen
2009-09-16  8:20       ` [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC Marius Storm-Olsen
2009-09-16  8:20         ` [PATCH 05/15] Fix __stdcall placement and function prototype Marius Storm-Olsen
2009-09-16  8:20           ` [PATCH 06/15] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
2009-09-16  8:20             ` [PATCH 07/15] Add empty header files for MSVC port Marius Storm-Olsen
2009-09-16  8:20               ` [PATCH 08/15] Add MinGW header files to build git with MSVC Marius Storm-Olsen
2009-09-16  8:20                 ` [PATCH 09/15] Add platform files for MSVC porting Marius Storm-Olsen
2009-09-16  8:20                   ` [PATCH 10/15] Make usage of windows.h lean and mean Marius Storm-Olsen
2009-09-16  8:20                     ` [PATCH 11/15] Define strncasecmp and ftruncate for MSVC Marius Storm-Olsen
2009-09-16  8:20                       ` [PATCH 12/15] Add MSVC to Makefile Marius Storm-Olsen
2009-09-16  8:20                         ` [PATCH 13/15] Add README for MSVC build Marius Storm-Olsen
2009-09-16  8:20                           ` [PATCH 14/15] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Marius Storm-Olsen
2009-09-16  8:20                             ` [RFC 15/15] Tag GIT_VERSION when Git is built with MSVC Marius Storm-Olsen
2009-09-17 20:18                               ` Johannes Sixt
2009-09-18  6:44                                 ` Marius Storm-Olsen
2009-09-17 20:28                             ` [PATCH 14/15] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Johannes Sixt
2009-09-18  6:59                               ` Marius Storm-Olsen
2009-09-18  8:21                                 ` Johannes Sixt
2009-09-23 15:04                             ` Sebastian Schuberth
2009-09-23 20:37                               ` Johannes Schindelin
2009-09-24  6:05                                 ` Marius Storm-Olsen
2009-09-23 10:03                 ` Add MinGW header files to build git with MSVC Sebastian Schuberth
2009-09-23 11:29                   ` Marius Storm-Olsen
2009-09-25  0:18                     ` [msysGit] " Frank Li
2009-09-16 16:14         ` [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC Johannes Sixt
2009-09-16 20:00           ` Alexey Borzenkov
2009-09-17  7:11             ` Johannes Sixt
2009-09-17  7:25               ` Junio C Hamano
2009-09-17  7:27               ` Marius Storm-Olsen
2009-09-17  7:36                 ` Johannes Sixt
2009-09-17  7:53                   ` Marius Storm-Olsen
2009-09-17  8:10                     ` Johannes Sixt
2009-09-17  8:14                       ` Marius Storm-Olsen
2009-09-17  8:39                       ` Alexey Borzenkov
2009-09-17  8:45                         ` Marius Storm-Olsen
2009-09-17  8:57                           ` Alexey Borzenkov
2009-09-17  9:03                         ` Johannes Sixt
2009-09-17  9:28                           ` Marius Storm-Olsen
2009-09-17 13:02                           ` Alexey Borzenkov
2009-09-17 13:30                             ` Johannes Sixt
2009-09-17  8:02         ` Marius Storm-Olsen
2009-09-17 10:44           ` Johannes Sixt
     [not found]             ` <4AB212FA.9080102@viscovery.netm>
2009-09-17 11:04               ` Marius Storm-Olsen [this message]
2009-09-16  9:42     ` [msysGit] [PATCH 02/15] Add define guards to compat/win32.h Erik Faye-Lund
2009-09-16 10:10       ` Marius Storm-Olsen
2009-09-23  9:44   ` Avoid declaration after statement Sebastian Schuberth
2009-09-25 13:34     ` Erik Faye-Lund

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e9b7c953e20a984bb519f3fe374cef03ca144a7.1253185334.git.mstormo@gmail.com \
    --to=mstormo@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=lznuaa@gmail.com \
    --cc=msysgit@googlegroups.com \
    --cc=raa.lkml@gmail.com \
    --cc=snaury@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.