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>
This commit is contained in:
parent
d7fa500fb5
commit
71064e3f86
@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* The size parameter specifies the available space, i.e. includes
|
* The size parameter specifies the available space, i.e. includes
|
||||||
* the trailing NUL byte; but Windows's vsnprintf expects the
|
* the trailing NUL byte; but Windows's vsnprintf uses the entire
|
||||||
* number of characters to write, and does not necessarily write the
|
* buffer and avoids the trailing NUL, should the buffer be exactly
|
||||||
* trailing NUL.
|
* 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
|
#ifndef SNPRINTF_SIZE_CORR
|
||||||
#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4
|
#if defined(WIN32) && (!defined(__GNUC__) || __GNUC__ < 4)
|
||||||
#define SNPRINTF_SIZE_CORR 1
|
#define SNPRINTF_SIZE_CORR 1
|
||||||
#else
|
#else
|
||||||
#define SNPRINTF_SIZE_CORR 0
|
#define SNPRINTF_SIZE_CORR 0
|
||||||
|
2
help.c
2
help.c
@ -126,7 +126,7 @@ static int is_executable(const char *name)
|
|||||||
!S_ISREG(st.st_mode))
|
!S_ISREG(st.st_mode))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef WIN32
|
||||||
{ /* cannot trust the executable bit, peek into the file instead */
|
{ /* cannot trust the executable bit, peek into the file instead */
|
||||||
char buf[3] = { 0 };
|
char buf[3] = { 0 };
|
||||||
int n;
|
int n;
|
||||||
|
4
pager.c
4
pager.c
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
static int spawned_pager;
|
static int spawned_pager;
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
#ifndef WIN32
|
||||||
static void pager_preexec(void)
|
static void pager_preexec(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -72,7 +72,7 @@ void setup_pager(void)
|
|||||||
static const char *env[] = { "LESS=FRSX", NULL };
|
static const char *env[] = { "LESS=FRSX", NULL };
|
||||||
pager_process.env = env;
|
pager_process.env = env;
|
||||||
}
|
}
|
||||||
#ifndef __MINGW32__
|
#ifndef WIN32
|
||||||
pager_process.preexec_cb = pager_preexec;
|
pager_process.preexec_cb = pager_preexec;
|
||||||
#endif
|
#endif
|
||||||
if (start_command(&pager_process))
|
if (start_command(&pager_process))
|
||||||
|
@ -75,7 +75,7 @@ fail_pipe:
|
|||||||
|
|
||||||
trace_argv_printf(cmd->argv, "trace: run_command:");
|
trace_argv_printf(cmd->argv, "trace: run_command:");
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
#ifndef WIN32
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
cmd->pid = fork();
|
cmd->pid = fork();
|
||||||
if (!cmd->pid) {
|
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);
|
return run_command(&cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef WIN32
|
||||||
static unsigned __stdcall run_thread(void *data)
|
static unsigned __stdcall run_thread(void *data)
|
||||||
{
|
{
|
||||||
struct async *async = data;
|
struct async *async = data;
|
||||||
@ -331,7 +331,7 @@ int start_async(struct async *async)
|
|||||||
return error("cannot create pipe: %s", strerror(errno));
|
return error("cannot create pipe: %s", strerror(errno));
|
||||||
async->out = pipe_out[0];
|
async->out = pipe_out[0];
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
#ifndef WIN32
|
||||||
/* Flush stdio before fork() to avoid cloning buffers */
|
/* Flush stdio before fork() to avoid cloning buffers */
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
|
|
||||||
@ -360,7 +360,7 @@ int start_async(struct async *async)
|
|||||||
|
|
||||||
int finish_async(struct async *async)
|
int finish_async(struct async *async)
|
||||||
{
|
{
|
||||||
#ifndef __MINGW32__
|
#ifndef WIN32
|
||||||
int ret = wait_or_whine(async->pid, "child process", 0);
|
int ret = wait_or_whine(async->pid, "child process", 0);
|
||||||
#else
|
#else
|
||||||
DWORD ret = 0;
|
DWORD ret = 0;
|
||||||
|
@ -70,7 +70,7 @@ struct async {
|
|||||||
int (*proc)(int fd, void *data);
|
int (*proc)(int fd, void *data);
|
||||||
void *data;
|
void *data;
|
||||||
int out; /* caller reads from here and closes it */
|
int out; /* caller reads from here and closes it */
|
||||||
#ifndef __MINGW32__
|
#ifndef WIN32
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
#else
|
#else
|
||||||
HANDLE tid;
|
HANDLE tid;
|
||||||
|
2
setup.c
2
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)
|
const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
|
||||||
{
|
{
|
||||||
static char path[PATH_MAX];
|
static char path[PATH_MAX];
|
||||||
#ifndef __MINGW32__
|
#ifndef WIN32
|
||||||
if (!pfx || !*pfx || is_absolute_path(arg))
|
if (!pfx || !*pfx || is_absolute_path(arg))
|
||||||
return arg;
|
return arg;
|
||||||
memcpy(path, pfx, pfx_len);
|
memcpy(path, pfx, pfx_len);
|
||||||
|
Loading…
Reference in New Issue
Block a user