{"thread":{"id":"33708","subject":"[PATCH v2 1/2] mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE","startedAt":"2013-05-02T19:26:08Z","lastAt":"2013-05-02T19:26:08Z","messageCount":1,"participants":["Ramsay Jones"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"216308","messageId":"5182BDD0.8000607@ramsay1.demon.co.uk","threadId":"33708","inReplyTo":null,"subject":"[PATCH v2 1/2] mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2013-05-02T19:26:08Z","receivedAt":"2013-05-02T19:26:08Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nThroughout git, it is assumed that the WIN32 preprocessor symbol is\ndefined on native Windows setups (mingw and msvc) and not on Cygwin.\nOn Cygwin, most of the time git can pretend this is just another Unix\nmachine, and Windows-specific magic is generally counterproductive.\n\nUnfortunately Cygwin *does* define the WIN32 symbol in some headers.\nBest to rely on a new git-specific symbol GIT_WINDOWS_NATIVE instead,\ndefined as follows:\n\n\t#if defined(WIN32) && !defined(__CYGWIN__)\n\t# define GIT_WINDOWS_NATIVE\n\t#endif\n\nAfter this change, it should be possible to drop the\nCYGWIN_V15_WIN32API setting without any negative effect.\n\n[rj: %s/WINDOWS_NATIVE/GIT_WINDOWS_NATIVE/g ]\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n abspath.c         |  2 +-\n compat/terminal.c |  4 ++--\n compat/win32.h    |  2 +-\n diff-no-index.c   |  2 +-\n git-compat-util.h |  3 ++-\n help.c            |  2 +-\n run-command.c     | 10 +++++-----\n test-chmtime.c    |  2 +-\n thread-utils.c    |  2 +-\n 9 files changed, 15 insertions(+), 14 deletions(-)\n\ndiff --git a/abspath.c b/abspath.c\nindex 40cdc46..64adbe2 100644\n--- a/abspath.c\n+++ b/abspath.c\n@@ -216,7 +216,7 @@ const char *absolute_path(const char *path)\n const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)\n {\n \tstatic char path[PATH_MAX];\n-#ifndef WIN32\n+#ifndef GIT_WINDOWS_NATIVE\n \tif (!pfx_len || is_absolute_path(arg))\n \t\treturn arg;\n \tmemcpy(path, pfx, pfx_len);\ndiff --git a/compat/terminal.c b/compat/terminal.c\nindex 9b5e3d1..313897d 100644\n--- a/compat/terminal.c\n+++ b/compat/terminal.c\n@@ -3,7 +3,7 @@\n #include \"sigchain.h\"\n #include \"strbuf.h\"\n \n-#if defined(HAVE_DEV_TTY) || defined(WIN32)\n+#if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE)\n \n static void restore_term(void);\n \n@@ -53,7 +53,7 @@ error:\n \treturn -1;\n }\n \n-#elif defined(WIN32)\n+#elif defined(GIT_WINDOWS_NATIVE)\n \n #define INPUT_PATH \"CONIN$\"\n #define OUTPUT_PATH \"CONOUT$\"\ndiff --git a/compat/win32.h b/compat/win32.h\nindex 8ce9104..a97e880 100644\n--- a/compat/win32.h\n+++ b/compat/win32.h\n@@ -2,7 +2,7 @@\n #define WIN32_H\n \n /* common Win32 functions for MinGW and Cygwin */\n-#ifndef WIN32         /* Not defined by Cygwin */\n+#ifndef GIT_WINDOWS_NATIVE\t/* Not defined for Cygwin */\n #include <windows.h>\n #endif\n \ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex 74da659..e66fdf3 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -45,7 +45,7 @@ static int get_mode(const char *path, int *mode)\n \n \tif (!path || !strcmp(path, \"/dev/null\"))\n \t\t*mode = 0;\n-#ifdef _WIN32\n+#ifdef GIT_WINDOWS_NATIVE\n \telse if (!strcasecmp(path, \"nul\"))\n \t\t*mode = 0;\n #endif\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex e955bb5..eeed506 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -85,13 +85,14 @@\n #define _NETBSD_SOURCE 1\n #define _SGI_SOURCE 1\n \n-#ifdef WIN32 /* Both MinGW and MSVC */\n+#if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */\n # if defined (_MSC_VER)\n #  define _WIN32_WINNT 0x0502\n # endif\n #define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */\n #include <winsock2.h>\n #include <windows.h>\n+#define GIT_WINDOWS_NATIVE\n #endif\n \n #include <unistd.h>\ndiff --git a/help.c b/help.c\nindex 02ba043..3d70d7a 100644\n--- a/help.c\n+++ b/help.c\n@@ -106,7 +106,7 @@ static int is_executable(const char *name)\n \t    !S_ISREG(st.st_mode))\n \t\treturn 0;\n \n-#if defined(WIN32) || defined(__CYGWIN__)\n+#if defined(GIT_WINDOWS_NATIVE) || defined(__CYGWIN__)\n #if defined(__CYGWIN__)\n if ((st.st_mode & S_IXUSR) == 0)\n #endif\ndiff --git a/run-command.c b/run-command.c\nindex 1b32a12..aece872 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -72,7 +72,7 @@ static inline void close_pair(int fd[2])\n \tclose(fd[1]);\n }\n \n-#ifndef WIN32\n+#ifndef GIT_WINDOWS_NATIVE\n static inline void dup_devnull(int to)\n {\n \tint fd = open(\"/dev/null\", O_RDWR);\n@@ -159,7 +159,7 @@ static const char **prepare_shell_cmd(const char **argv)\n \t\tdie(\"BUG: shell command is empty\");\n \n \tif (strcspn(argv[0], \"|&;<>()$`\\\\\\\"' \\t\\n*?[#~=%\") != strlen(argv[0])) {\n-#ifndef WIN32\n+#ifndef GIT_WINDOWS_NATIVE\n \t\tnargv[nargc++] = SHELL_PATH;\n #else\n \t\tnargv[nargc++] = \"sh\";\n@@ -182,7 +182,7 @@ static const char **prepare_shell_cmd(const char **argv)\n \treturn nargv;\n }\n \n-#ifndef WIN32\n+#ifndef GIT_WINDOWS_NATIVE\n static int execv_shell_cmd(const char **argv)\n {\n \tconst char **nargv = prepare_shell_cmd(argv);\n@@ -193,7 +193,7 @@ static int execv_shell_cmd(const char **argv)\n }\n #endif\n \n-#ifndef WIN32\n+#ifndef GIT_WINDOWS_NATIVE\n static int child_err = 2;\n static int child_notifier = -1;\n \n@@ -334,7 +334,7 @@ fail_pipe:\n \ttrace_argv_printf(cmd->argv, \"trace: run_command:\");\n \tfflush(NULL);\n \n-#ifndef WIN32\n+#ifndef GIT_WINDOWS_NATIVE\n {\n \tint notify_pipe[2];\n \tif (pipe(notify_pipe))\ndiff --git a/test-chmtime.c b/test-chmtime.c\nindex 02b42ba..1cffa12 100644\n--- a/test-chmtime.c\n+++ b/test-chmtime.c\n@@ -87,7 +87,7 @@ int main(int argc, const char *argv[])\n \t\t\treturn -1;\n \t\t}\n \n-#ifdef WIN32\n+#ifdef GIT_WINDOWS_NATIVE\n \t\tif (!(sb.st_mode & S_IWUSR) &&\n \t\t\t\tchmod(argv[i], sb.st_mode | S_IWUSR)) {\n \t\t\tfprintf(stderr, \"Could not make user-writable %s: %s\",\ndiff --git a/thread-utils.c b/thread-utils.c\nindex 7f4b76a..97396a7 100644\n--- a/thread-utils.c\n+++ b/thread-utils.c\n@@ -24,7 +24,7 @@ int online_cpus(void)\n \tlong ncpus;\n #endif\n \n-#ifdef _WIN32\n+#ifdef GIT_WINDOWS_NATIVE\n \tSYSTEM_INFO info;\n \tGetSystemInfo(&info);\n \n-- \n1.8.2\n"}]}