Skip to content

Commit 71064e3

Browse files
lznuaagitster
authored andcommitted
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 <[email protected]> Signed-off-by: Marius Storm-Olsen <[email protected]> Acked-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7fa500 commit 71064e3

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

compat/snprintf.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
/*
44
* 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.
810
*/
911
#ifndef SNPRINTF_SIZE_CORR
10-
#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4
12+
#if defined(WIN32) && (!defined(__GNUC__) || __GNUC__ < 4)
1113
#define SNPRINTF_SIZE_CORR 1
1214
#else
1315
#define SNPRINTF_SIZE_CORR 0

help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int is_executable(const char *name)
126126
!S_ISREG(st.st_mode))
127127
return 0;
128128

129-
#ifdef __MINGW32__
129+
#ifdef WIN32
130130
{ /* cannot trust the executable bit, peek into the file instead */
131131
char buf[3] = { 0 };
132132
int n;

pager.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
static int spawned_pager;
1111

12-
#ifndef __MINGW32__
12+
#ifndef WIN32
1313
static void pager_preexec(void)
1414
{
1515
/*
@@ -72,7 +72,7 @@ void setup_pager(void)
7272
static const char *env[] = { "LESS=FRSX", NULL };
7373
pager_process.env = env;
7474
}
75-
#ifndef __MINGW32__
75+
#ifndef WIN32
7676
pager_process.preexec_cb = pager_preexec;
7777
#endif
7878
if (start_command(&pager_process))

run-command.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int start_command(struct child_process *cmd)
7575

7676
trace_argv_printf(cmd->argv, "trace: run_command:");
7777

78-
#ifndef __MINGW32__
78+
#ifndef WIN32
7979
fflush(NULL);
8080
cmd->pid = fork();
8181
if (!cmd->pid) {
@@ -315,7 +315,7 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
315315
return run_command(&cmd);
316316
}
317317

318-
#ifdef __MINGW32__
318+
#ifdef WIN32
319319
static unsigned __stdcall run_thread(void *data)
320320
{
321321
struct async *async = data;
@@ -331,7 +331,7 @@ int start_async(struct async *async)
331331
return error("cannot create pipe: %s", strerror(errno));
332332
async->out = pipe_out[0];
333333

334-
#ifndef __MINGW32__
334+
#ifndef WIN32
335335
/* Flush stdio before fork() to avoid cloning buffers */
336336
fflush(NULL);
337337

@@ -360,7 +360,7 @@ int start_async(struct async *async)
360360

361361
int finish_async(struct async *async)
362362
{
363-
#ifndef __MINGW32__
363+
#ifndef WIN32
364364
int ret = wait_or_whine(async->pid, "child process", 0);
365365
#else
366366
DWORD ret = 0;

run-command.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct async {
7070
int (*proc)(int fd, void *data);
7171
void *data;
7272
int out; /* caller reads from here and closes it */
73-
#ifndef __MINGW32__
73+
#ifndef WIN32
7474
pid_t pid;
7575
#else
7676
HANDLE tid;

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
4141
const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
4242
{
4343
static char path[PATH_MAX];
44-
#ifndef __MINGW32__
44+
#ifndef WIN32
4545
if (!pfx || !*pfx || is_absolute_path(arg))
4646
return arg;
4747
memcpy(path, pfx, pfx_len);

0 commit comments

Comments
 (0)