diff mbox series

Properly restore the old behaviour regarding the --preprocess option in windres

Message ID 20210510195351.376323-1-martin@martin.st
State New
Headers show
Series Properly restore the old behaviour regarding the --preprocess option in windres | expand

Commit Message

Martin Storsjo May 10, 2021, 7:53 p.m. UTC
749c700282097cf679ff019a9674d7c762f48619 reverted the wrong change,
reinstate the changes from cc3edc52747fd8b184ee48f1b0cc1ac0aca7832e,
and revert 21c33bcbe36377abf01614fb1b9be439a3b6de20, which is the
one that should have been reverted to restore the old behaviour
of the --preprocessor argument.

        PR 4356
        PR 26865
        PR 27594
---
 binutils/windres.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

-- 
2.25.1
diff mbox series

Patch

diff --git a/binutils/windres.c b/binutils/windres.c
index 2b626a29fb6..b37b40ef296 100644
--- a/binutils/windres.c
+++ b/binutils/windres.c
@@ -710,13 +710,37 @@  quot (const char *string)
       buf = (char *) xmalloc (buflen);
     }
 
+#if defined (_WIN32) && !defined (__CYGWIN__)
+  /* For Windows shells, quote "like this".   */
+  {
+    bool quoted = false;
+
+    dest = buf;
+    if (strchr (string, ' '))
+      {
+	quoted = true;
+	*dest++ = '"';
+      }
+
+    for (src = string; *src; src++, dest++)
+      {
+	/* Escape-protect embedded double quotes.  */
+	if (quoted && *src == '"')
+	  *dest++ = '\\';
+	*dest = *src;
+      }
+
+    if (quoted)
+      *dest++ = '"';
+  }
+#else
   for (src = string, dest = buf; *src; src++, dest++)
     {
       if (*src == '(' || *src == ')' || *src == ' ')
 	*dest++ = '\\';
       *dest = *src;
     }
-
+#endif
   *dest = 0;
   return buf;
 }
@@ -884,13 +908,7 @@  main (int argc, char **argv)
 	  break;
 
 	case OPTION_PREPROCESSOR:
-	  if (strchr (optarg, ' '))
-	    {
-	      if (asprintf (& preprocessor, "\"%s\"", optarg) == -1)
-		preprocessor = optarg;
-	    }
-	  else
-	    preprocessor = optarg;	    
+	  preprocessor = optarg;
 	  break;
 
 	case OPTION_PREPROCESSOR_ARG: