From ee9c42bbf5b11392731867077a12d1260b4043f9 Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Wed, 5 Mar 2014 22:28:38 +0100
Subject: [PATCH] Support both MinGW and MinGW-w64.
---
src/cl65/main.c | 18 +++++++++++++++---
src/cl65/spawn-amiga.inc | 2 +-
src/cl65/spawn-unix.inc | 4 ++--
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/cl65/main.c b/src/cl65/main.c
index 7c8149660..b9b191dcd 100644
--- a/src/cl65/main.c
+++ b/src/cl65/main.c
@@ -41,8 +41,20 @@
#else
# define NEED_SPAWN 1
#endif
-#if defined(_MSC_VER)
-# pragma warning(disable : 4996)
+
+/* GCC strictly follows http://c-faq.com/ansi/constmismatch.html and issues an
+ * 'incompatible pointer type' warning - that can't be suppressed via #pragma.
+ * The spawnvp() prototype of MinGW (http://www.mingw.org/) differs from the
+ * one of MinGW-w64 (http://mingw-w64.sourceforge.net/) regarding constness.
+ * So there's no alternative to actually distinguish these environments :-(
+ */
+#define SPAWN_ARGV_CONST_CAST
+#if defined(__MINGW32__)
+# include <_mingw.h>
+# if !defined(__MINGW64_VERSION_MAJOR)
+# undef SPAWN_ARGV_CONST_CAST
+# define SPAWN_ARGV_CONST_CAST (const char* const *)
+# endif
#endif
@@ -375,7 +387,7 @@ static void ExecProgram (CmdDesc* Cmd)
}
/* Call the program */
- Status = spawnvp (P_WAIT, Cmd->Name, (const char* const *) Cmd->Args);
+ Status = spawnvp (P_WAIT, Cmd->Name, SPAWN_ARGV_CONST_CAST Cmd->Args);
/* Check the result code */
if (Status < 0) {
diff --git a/src/cl65/spawn-amiga.inc b/src/cl65/spawn-amiga.inc
index f8a230950..5d1b60ea3 100644
--- a/src/cl65/spawn-amiga.inc
+++ b/src/cl65/spawn-amiga.inc
@@ -54,7 +54,7 @@
int spawnvp (int Mode attribute ((unused)),
const char* File attribute ((unused)),
- const char* const argv [])
+ char* const argv [])
/* Execute the given program searching and wait til it terminates. The Mode
* argument is ignored (compatibility only). The result of the function is
* the return code of the program. The function will terminate the program
diff --git a/src/cl65/spawn-unix.inc b/src/cl65/spawn-unix.inc
index 558f2428d..fc5125c34 100644
--- a/src/cl65/spawn-unix.inc
+++ b/src/cl65/spawn-unix.inc
@@ -62,7 +62,7 @@
-int spawnvp (int Mode attribute ((unused)), const char* File, const char* const argv [])
+int spawnvp (int Mode attribute ((unused)), const char* File, char* const argv [])
/* Execute the given program searching and wait til it terminates. The Mode
* argument is ignored (compatibility only). The result of the function is
* the return code of the program. The function will terminate the program
@@ -81,7 +81,7 @@ int spawnvp (int Mode attribute ((unused)), const char* File, const char* const
} else if (pid == 0) {
/* The son - exec the program */
- if (execvp (File, (char* const *) argv) < 0) {
+ if (execvp (File, argv) < 0) {
Error ("Cannot exec `%s': %s", File, strerror (errno));
}
--
2.39.5