Skip to content

Commit

Permalink
Test for WIN32 instead of __MINGW32_
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lznuaa authored and gitster committed Sep 19, 2009
1 parent d7fa500 commit 71064e3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
10 changes: 6 additions & 4 deletions compat/snprintf.c
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion help.c
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions pager.c
Expand Up @@ -9,7 +9,7 @@

static int spawned_pager;

#ifndef __MINGW32__
#ifndef WIN32
static void pager_preexec(void)
{
/*
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions run-command.c
Expand Up @@ -75,7 +75,7 @@ int start_command(struct child_process *cmd)

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

#ifndef __MINGW32__
#ifndef WIN32
fflush(NULL);
cmd->pid = fork();
if (!cmd->pid) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion run-command.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion setup.c
Expand Up @@ -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);
Expand Down

0 comments on commit 71064e3

Please sign in to comment.