Skip to content

Commit

Permalink
mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE
Browse files Browse the repository at this point in the history
Throughout git, it is assumed that the WIN32 preprocessor symbol is
defined on native Windows setups (mingw and msvc) and not on Cygwin.
On Cygwin, most of the time git can pretend this is just another Unix
machine, and Windows-specific magic is generally counterproductive.

Unfortunately Cygwin *does* define the WIN32 symbol in some headers.
Best to rely on a new git-specific symbol GIT_WINDOWS_NATIVE instead,
defined as follows:

	#if defined(WIN32) && !defined(__CYGWIN__)
	# define GIT_WINDOWS_NATIVE
	#endif

After this change, it should be possible to drop the
CYGWIN_V15_WIN32API setting without any negative effect.

[rj: %s/WINDOWS_NATIVE/GIT_WINDOWS_NATIVE/g ]

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
jrn authored and gitster committed May 8, 2013
1 parent b75cdfa commit 380395d
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion abspath.c
Expand Up @@ -216,7 +216,7 @@ const char *absolute_path(const char *path)
const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
{
static char path[PATH_MAX];
#ifndef WIN32
#ifndef GIT_WINDOWS_NATIVE
if (!pfx_len || is_absolute_path(arg))
return arg;
memcpy(path, pfx, pfx_len);
Expand Down
4 changes: 2 additions & 2 deletions compat/terminal.c
Expand Up @@ -3,7 +3,7 @@
#include "sigchain.h"
#include "strbuf.h"

#if defined(HAVE_DEV_TTY) || defined(WIN32)
#if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE)

static void restore_term(void);

Expand Down Expand Up @@ -53,7 +53,7 @@ static int disable_echo(void)
return -1;
}

#elif defined(WIN32)
#elif defined(GIT_WINDOWS_NATIVE)

#define INPUT_PATH "CONIN$"
#define OUTPUT_PATH "CONOUT$"
Expand Down
2 changes: 1 addition & 1 deletion compat/win32.h
Expand Up @@ -2,7 +2,7 @@
#define WIN32_H

/* common Win32 functions for MinGW and Cygwin */
#ifndef WIN32 /* Not defined by Cygwin */
#ifndef GIT_WINDOWS_NATIVE /* Not defined for Cygwin */
#include <windows.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion diff-no-index.c
Expand Up @@ -45,7 +45,7 @@ static int get_mode(const char *path, int *mode)

if (!path || !strcmp(path, "/dev/null"))
*mode = 0;
#ifdef _WIN32
#ifdef GIT_WINDOWS_NATIVE
else if (!strcasecmp(path, "nul"))
*mode = 0;
#endif
Expand Down
3 changes: 2 additions & 1 deletion git-compat-util.h
Expand Up @@ -85,13 +85,14 @@
#define _NETBSD_SOURCE 1
#define _SGI_SOURCE 1

#ifdef WIN32 /* Both MinGW and MSVC */
#if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */
# if defined (_MSC_VER)
# define _WIN32_WINNT 0x0502
# endif
#define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */
#include <winsock2.h>
#include <windows.h>
#define GIT_WINDOWS_NATIVE
#endif

#include <unistd.h>
Expand Down
2 changes: 1 addition & 1 deletion help.c
Expand Up @@ -106,7 +106,7 @@ static int is_executable(const char *name)
!S_ISREG(st.st_mode))
return 0;

#if defined(WIN32) || defined(__CYGWIN__)
#if defined(GIT_WINDOWS_NATIVE) || defined(__CYGWIN__)
#if defined(__CYGWIN__)
if ((st.st_mode & S_IXUSR) == 0)
#endif
Expand Down
10 changes: 5 additions & 5 deletions run-command.c
Expand Up @@ -72,7 +72,7 @@ static inline void close_pair(int fd[2])
close(fd[1]);
}

#ifndef WIN32
#ifndef GIT_WINDOWS_NATIVE
static inline void dup_devnull(int to)
{
int fd = open("/dev/null", O_RDWR);
Expand Down Expand Up @@ -159,7 +159,7 @@ static const char **prepare_shell_cmd(const char **argv)
die("BUG: shell command is empty");

if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) {
#ifndef WIN32
#ifndef GIT_WINDOWS_NATIVE
nargv[nargc++] = SHELL_PATH;
#else
nargv[nargc++] = "sh";
Expand All @@ -182,7 +182,7 @@ static const char **prepare_shell_cmd(const char **argv)
return nargv;
}

#ifndef WIN32
#ifndef GIT_WINDOWS_NATIVE
static int execv_shell_cmd(const char **argv)
{
const char **nargv = prepare_shell_cmd(argv);
Expand All @@ -193,7 +193,7 @@ static int execv_shell_cmd(const char **argv)
}
#endif

#ifndef WIN32
#ifndef GIT_WINDOWS_NATIVE
static int child_err = 2;
static int child_notifier = -1;

Expand Down Expand Up @@ -334,7 +334,7 @@ int start_command(struct child_process *cmd)
trace_argv_printf(cmd->argv, "trace: run_command:");
fflush(NULL);

#ifndef WIN32
#ifndef GIT_WINDOWS_NATIVE
{
int notify_pipe[2];
if (pipe(notify_pipe))
Expand Down
2 changes: 1 addition & 1 deletion test-chmtime.c
Expand Up @@ -87,7 +87,7 @@ int main(int argc, const char *argv[])
return -1;
}

#ifdef WIN32
#ifdef GIT_WINDOWS_NATIVE
if (!(sb.st_mode & S_IWUSR) &&
chmod(argv[i], sb.st_mode | S_IWUSR)) {
fprintf(stderr, "Could not make user-writable %s: %s",
Expand Down
2 changes: 1 addition & 1 deletion thread-utils.c
Expand Up @@ -24,7 +24,7 @@ int online_cpus(void)
long ncpus;
#endif

#ifdef _WIN32
#ifdef GIT_WINDOWS_NATIVE
SYSTEM_INFO info;
GetSystemInfo(&info);

Expand Down

0 comments on commit 380395d

Please sign in to comment.