git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / 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 06/15] Test for WIN32 instead of __MINGW32_
Date: Wed, 16 Sep 2009 10:20:22 +0200	[thread overview]
Message-ID: <28e3400f29353cf8f93b4ca054b87f083f9e33e1.1253088099.git.mstormo@gmail.com> (raw)
In-Reply-To: <eec2b652c5a8e3e21348a8211d336fce66cb21a5.1253088099.git.mstormo@gmail.com>
In-Reply-To: <cover.1253088099.git.mstormo@gmail.com>


From: Frank Li <lznuaa@gmail.com>

The code which is conditional on MinGW32 is actually conditional on Windows.
Use the WIN32 symbol, which is defined by the MINGW32 and MSVC environments,
but not by Cygwin.

Define SNPRINTF_SIZE_CORR=1 for MSVC too, as its vsnprintf function does
not add NUL at the end of the buffer if the result fits the buffer size
exactly.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/snprintf.c |   10 ++++++----
 help.c            |    2 +-
 pager.c           |    4 ++--
 run-command.c     |    8 ++++----
 run-command.h     |    2 +-
 setup.c           |    2 +-
 6 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/compat/snprintf.c b/compat/snprintf.c
index 4d07087..e1e0e75 100644
--- a/compat/snprintf.c
+++ b/compat/snprintf.c
@@ -2,12 +2,14 @@
 
 /*
  * The size parameter specifies the available space, i.e. includes
- * the trailing NUL byte; but Windows's vsnprintf expects the
- * number of characters to write, and does not necessarily write the
- * trailing NUL.
+ * the trailing NUL byte; but Windows's vsnprintf uses the entire
+ * buffer and avoids the trailing NUL, should the buffer be exactly
+ * big enough for the result. Defining SNPRINTF_SIZE_CORR to 1 will
+ * therefore remove 1 byte from the reported buffer size, so we
+ * always have room for a trailing NUL byte.
  */
 #ifndef SNPRINTF_SIZE_CORR
-#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4
+#if defined(WIN32) && (!defined(__GNUC__) || __GNUC__ < 4)
 #define SNPRINTF_SIZE_CORR 1
 #else
 #define SNPRINTF_SIZE_CORR 0
diff --git a/help.c b/help.c
index fd51b8e..e8db31f 100644
--- a/help.c
+++ b/help.c
@@ -126,7 +126,7 @@ static int is_executable(const char *name)
 	    !S_ISREG(st.st_mode))
 		return 0;
 
-#ifdef __MINGW32__
+#ifdef WIN32
 {	/* cannot trust the executable bit, peek into the file instead */
 	char buf[3] = { 0 };
 	int n;
diff --git a/pager.c b/pager.c
index f416d38..86facec 100644
--- a/pager.c
+++ b/pager.c
@@ -9,7 +9,7 @@
 
 static int spawned_pager;
 
-#ifndef __MINGW32__
+#ifndef WIN32
 static void pager_preexec(void)
 {
 	/*
@@ -72,7 +72,7 @@ void setup_pager(void)
 		static const char *env[] = { "LESS=FRSX", NULL };
 		pager_process.env = env;
 	}
-#ifndef __MINGW32__
+#ifndef WIN32
 	pager_process.preexec_cb = pager_preexec;
 #endif
 	if (start_command(&pager_process))
diff --git a/run-command.c b/run-command.c
index bb76750..cf2d8f7 100644
--- a/run-command.c
+++ b/run-command.c
@@ -75,7 +75,7 @@ fail_pipe:
 
 	trace_argv_printf(cmd->argv, "trace: run_command:");
 
-#ifndef __MINGW32__
+#ifndef WIN32
 	fflush(NULL);
 	cmd->pid = fork();
 	if (!cmd->pid) {
@@ -315,7 +315,7 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
 	return run_command(&cmd);
 }
 
-#ifdef __MINGW32__
+#ifdef WIN32
 static unsigned __stdcall run_thread(void *data)
 {
 	struct async *async = data;
@@ -331,7 +331,7 @@ int start_async(struct async *async)
 		return error("cannot create pipe: %s", strerror(errno));
 	async->out = pipe_out[0];
 
-#ifndef __MINGW32__
+#ifndef WIN32
 	/* Flush stdio before fork() to avoid cloning buffers */
 	fflush(NULL);
 
@@ -360,7 +360,7 @@ int start_async(struct async *async)
 
 int finish_async(struct async *async)
 {
-#ifndef __MINGW32__
+#ifndef WIN32
 	int ret = wait_or_whine(async->pid, "child process", 0);
 #else
 	DWORD ret = 0;
diff --git a/run-command.h b/run-command.h
index 0c00b25..fb34209 100644
--- a/run-command.h
+++ b/run-command.h
@@ -70,7 +70,7 @@ struct async {
 	int (*proc)(int fd, void *data);
 	void *data;
 	int out;	/* caller reads from here and closes it */
-#ifndef __MINGW32__
+#ifndef WIN32
 	pid_t pid;
 #else
 	HANDLE tid;
diff --git a/setup.c b/setup.c
index e3781b6..029371e 100644
--- a/setup.c
+++ b/setup.c
@@ -41,7 +41,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
 const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
 {
 	static char path[PATH_MAX];
-#ifndef __MINGW32__
+#ifndef WIN32
 	if (!pfx || !*pfx || is_absolute_path(arg))
 		return arg;
 	memcpy(path, pfx, pfx_len);
-- 
1.6.2.1.418.g33d56.dirty

  reply	other threads:[~2009-09-16  8:21 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           ` Marius Storm-Olsen [this message]
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
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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=28e3400f29353cf8f93b4ca054b87f083f9e33e1.1253088099.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).