summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d7fa500)
raw | patch | inline | side by side (parent: d7fa500)
author | Frank Li <lznuaa@gmail.com> | |
Wed, 16 Sep 2009 08:20:22 +0000 (10:20 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 19 Sep 2009 03:00:42 +0000 (20:00 -0700) |
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>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/snprintf.c | patch | blob | history | |
help.c | patch | blob | history | |
pager.c | patch | blob | history | |
run-command.c | patch | blob | history | |
run-command.h | patch | blob | history | |
setup.c | patch | blob | history |
diff --git a/compat/snprintf.c b/compat/snprintf.c
index 4d07087abd4f956b4dbe209236e6abafd459b1e4..e1e0e7543d9414726122c121b7909bf73809a81a 100644 (file)
--- a/compat/snprintf.c
+++ b/compat/snprintf.c
/*
* 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
index fd51b8e8ef748a146676de6192e0fb9170ed8836..e8db31f60f010887ccb3a943344da566e0937403 100644 (file)
--- a/help.c
+++ b/help.c
!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;
index f416d38ac26042d7ed6dbf87f21bf5339e481a2e..86facec7b417b26a7dbd9b3c1338149fcecd5588 100644 (file)
--- a/pager.c
+++ b/pager.c
static int spawned_pager;
-#ifndef __MINGW32__
+#ifndef WIN32
static void pager_preexec(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 bb76750cd063a05483856f1f744f79c04ed80352..cf2d8f7fae1356e50736cb9d599625df79738a2a 100644 (file)
--- a/run-command.c
+++ b/run-command.c
trace_argv_printf(cmd->argv, "trace: run_command:");
-#ifndef __MINGW32__
+#ifndef WIN32
fflush(NULL);
cmd->pid = fork();
if (!cmd->pid) {
return run_command(&cmd);
}
-#ifdef __MINGW32__
+#ifdef WIN32
static unsigned __stdcall run_thread(void *data)
{
struct async *async = data;
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);
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 0c00b25ff2ea8710a1d963619d633a9be1a6f626..fb342090e3cac49f41689f9610bfe2d6c87c87c1 100644 (file)
--- a/run-command.h
+++ b/run-command.h
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;
index e3781b656d77be94e04c5229e6a190c5fc496490..029371e5844a1069d62456c6bb51028efbb671c4 100644 (file)
--- a/setup.c
+++ b/setup.c
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);