public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Clément Chigot" <chigot@adacore.com>
To: binutils@sourceware.org
Subject: [PATCH] windres: add quotes around preprocessor cmd if needed
Date: Tue, 28 Jun 2022 09:35:52 +0200	[thread overview]
Message-ID: <CAJ307EinOMV+ECLDTvkKzTdn39HfDERb28CsWu04BWyJ7+NLeA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 496 bytes --]

This patch ensures that the gcc binary called by windres is quoted if
needed. Otherwise, errors can occur if the gcc is under a folder having
a name containing a space (eg "Program Files").

binutils/
        * resrc.c (DEFAULT_PREPROCESSOR): Split into...
        (DEFAULT_PREPROCESSOR_CMD): that...
        (DEFAULT_PREPROCESSOR_ARGS): and that.
        (look_for_default): Add quotes around the command if needed.
        (read_rc_file): Adapt to new defines.


Thanks,
Clément

[-- Attachment #2: 0001-windres-add-quotes-around-preprocessor-cmd-if-needed.patch --]
[-- Type: text/x-patch, Size: 2870 bytes --]

From 3c6afcd33eed6806df0e632b1d52e946d277cc89 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= <chigot@adacore.com>
Date: Thu, 16 Jun 2022 13:43:26 +0200
Subject: [PATCH] windres: add quotes around preprocessor cmd if needed

This patch ensures that the gcc binary called by windres is quoted if
needed. Otherwise, errors can occur if the gcc is under a folder having
a name containing a space (eg "Program Files").

binutils/
	* resrc.c (DEFAULT_PREPROCESSOR): Split into...
	(DEFAULT_PREPROCESSOR_CMD): that...
	(DEFAULT_PREPROCESSOR_ARGS): and that.
	(look_for_default): Add quotes around the command if needed.
	(read_rc_file): Adapt to new defines.

---
 binutils/resrc.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/binutils/resrc.c b/binutils/resrc.c
index 249eb9a87ed..de39e133a0a 100644
--- a/binutils/resrc.c
+++ b/binutils/resrc.c
@@ -75,7 +75,8 @@
 
 /* The default preprocessor.  */
 
-#define DEFAULT_PREPROCESSOR "gcc -E -xc -DRC_INVOKED"
+#define DEFAULT_PREPROCESSOR_CMD "gcc"
+#define DEFAULT_PREPROCESSOR_ARGS "-E -xc -DRC_INVOKED"
 
 /* We read the directory entries in a cursor or icon file into
    instances of this structure.  */
@@ -378,17 +379,13 @@ static FILE *
 look_for_default (char *cmd, const char *prefix, int end_prefix,
 		  const char *preprocargs, const char *filename)
 {
-  char *space;
   int found;
   struct stat s;
   const char *fnquotes = (filename_need_quotes (filename) ? "\"" : "");
 
   strcpy (cmd, prefix);
 
-  sprintf (cmd + end_prefix, "%s", DEFAULT_PREPROCESSOR);
-  space = strchr (cmd + end_prefix, ' ');
-  if (space)
-    *space = 0;
+  sprintf (cmd + end_prefix, "%s", DEFAULT_PREPROCESSOR_CMD);
 
   if (
 #if defined (__DJGPP__) || defined (__CYGWIN__) || defined (_WIN32)
@@ -410,10 +407,16 @@ look_for_default (char *cmd, const char *prefix, int end_prefix,
 	}
     }
 
-  strcpy (cmd, prefix);
+  if (filename_need_quotes (cmd))
+    {
+      char *cmd_copy = xmalloc (strlen (cmd));
+      strcpy (cmd_copy, cmd);
+      sprintf (cmd, "\"%s\"", cmd_copy);
+      free (cmd_copy);
+    }
 
-  sprintf (cmd + end_prefix, "%s %s %s%s%s",
-	   DEFAULT_PREPROCESSOR, preprocargs, fnquotes, filename, fnquotes);
+  sprintf (cmd + strlen (cmd), " %s %s %s%s%s",
+	   DEFAULT_PREPROCESSOR_ARGS, preprocargs, fnquotes, filename, fnquotes);
 
   if (verbose)
     fprintf (stderr, _("Using `%s'\n"), cmd);
@@ -490,10 +493,9 @@ read_rc_file (const char *filename, const char *preprocessor,
     {
       char *dash, *slash, *cp;
 
-      preprocessor = DEFAULT_PREPROCESSOR;
-
       cmd = xmalloc (strlen (program_name)
-		     + strlen (preprocessor)
+		     + strlen (DEFAULT_PREPROCESSOR_CMD)
+		     + strlen (DEFAULT_PREPROCESSOR_ARGS)
 		     + strlen (preprocargs)
 		     + strlen (filename)
 		     + strlen (fnquotes) * 2
-- 
2.25.1


             reply	other threads:[~2022-06-28  7:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28  7:35 Clément Chigot [this message]
2022-06-28  9:00 ` Jan Beulich
2022-06-28  9:37   ` Clément Chigot
2022-06-28 10:16     ` Jan Beulich
2022-06-28 11:57       ` Clément Chigot
2022-06-28 12:26     ` Clément Chigot
2022-06-28 13:51       ` Jan Beulich
2022-06-28 14:18         ` Clément Chigot
2022-06-28 14:40           ` Jan Beulich
2022-06-28 14:55             ` Clément Chigot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJ307EinOMV+ECLDTvkKzTdn39HfDERb28CsWu04BWyJ7+NLeA@mail.gmail.com \
    --to=chigot@adacore.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).