@matheusbsbs / matheus-bagliano / commits / 71064e3f86
Fork 0

Test for WIN32 instead of __MINGW32_

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>

Frank Li committed Sep 16, 2009 at 10:20 UTC 71064e3f86fbf2eb5c2b55a3024051f9542ae229
6 files changed +15 -13
compat/snprintf.c
+6 -4
@@ -2,12 +2,14 @@
2
3 /*
4 * The size parameter specifies the available space, i.e. includes
5 - * the trailing NUL byte; but Windows's vsnprintf expects the
6 - * number of characters to write, and does not necessarily write the
7 - * trailing NUL.
5 + * the trailing NUL byte; but Windows's vsnprintf uses the entire
6 + * buffer and avoids the trailing NUL, should the buffer be exactly
7 + * big enough for the result. Defining SNPRINTF_SIZE_CORR to 1 will
8 + * therefore remove 1 byte from the reported buffer size, so we
9 + * always have room for a trailing NUL byte.
10 */
11 #ifndef SNPRINTF_SIZE_CORR
10 -#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4
12 +#if defined(WIN32) && (!defined(__GNUC__) || __GNUC__ < 4)
13 #define SNPRINTF_SIZE_CORR 1
14 #else
15 #define SNPRINTF_SIZE_CORR 0
help.c
+1 -1
@@ -126,7 +126,7 @@ static int is_executable(const char *name)
126 !S_ISREG(st.st_mode))
127 return 0;
128
129 -#ifdef __MINGW32__
129 +#ifdef WIN32
130 { /* cannot trust the executable bit, peek into the file instead */
131 char buf[3] = { 0 };
132 int n;
pager.c
+2 -2
@@ -9,7 +9,7 @@
9
10 static int spawned_pager;
11
12 -#ifndef __MINGW32__
12 +#ifndef WIN32
13 static void pager_preexec(void)
14 {
15 /*
@@ -72,7 +72,7 @@ void setup_pager(void)
72 static const char *env[] = { "LESS=FRSX", NULL };
73 pager_process.env = env;
74 }
75 -#ifndef __MINGW32__
75 +#ifndef WIN32
76 pager_process.preexec_cb = pager_preexec;
77 #endif
78 if (start_command(&pager_process))
run-command.c
+4 -4
@@ -75,7 +75,7 @@ fail_pipe:
75
76 trace_argv_printf(cmd->argv, "trace: run_command:");
77
78 -#ifndef __MINGW32__
78 +#ifndef WIN32
79 fflush(NULL);
80 cmd->pid = fork();
81 if (!cmd->pid) {
@@ -315,7 +315,7 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
315 return run_command(&cmd);
316 }
317
318 -#ifdef __MINGW32__
318 +#ifdef WIN32
319 static unsigned __stdcall run_thread(void *data)
320 {
321 struct async *async = data;
@@ -331,7 +331,7 @@ int start_async(struct async *async)
331 return error("cannot create pipe: %s", strerror(errno));
332 async->out = pipe_out[0];
333
334 -#ifndef __MINGW32__
334 +#ifndef WIN32
335 /* Flush stdio before fork() to avoid cloning buffers */
336 fflush(NULL);
337
@@ -360,7 +360,7 @@ int start_async(struct async *async)
360
361 int finish_async(struct async *async)
362 {
363 -#ifndef __MINGW32__
363 +#ifndef WIN32
364 int ret = wait_or_whine(async->pid, "child process", 0);
365 #else
366 DWORD ret = 0;
run-command.h
+1 -1
@@ -70,7 +70,7 @@ struct async {
70 int (*proc)(int fd, void *data);
71 void *data;
72 int out; /* caller reads from here and closes it */
73 -#ifndef __MINGW32__
73 +#ifndef WIN32
74 pid_t pid;
75 #else
76 HANDLE tid;
setup.c
+1 -1
@@ -41,7 +41,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
41 const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
42 {
43 static char path[PATH_MAX];
44 -#ifndef __MINGW32__
44 +#ifndef WIN32
45 if (!pfx || !*pfx || is_absolute_path(arg))
46 return arg;
47 memcpy(path, pfx, pfx_len);