aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-02-27 12:51:01 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-02-27 12:51:01 +0200
commitde4655a2b8deeade908920dacc2dbb54232e3e07 (patch)
treed68333f382c18dcfbbeb72086af3b3f62753cc18
parent5b2e0bc7fd53e3329cad75b8d8361daaa8bd2465 (diff)
Escape backslashes in GNU options file on Windows
-rw-r--r--build2/cc/link-rule.cxx24
1 files changed, 22 insertions, 2 deletions
diff --git a/build2/cc/link-rule.cxx b/build2/cc/link-rule.cxx
index 4a81874..6c6aa0d 100644
--- a/build2/cc/link-rule.cxx
+++ b/build2/cc/link-rule.cxx
@@ -2493,11 +2493,31 @@ namespace build2
// Both Microsoft and GNU support a space-separated list of
// potentially-quoted arguments. GNU also supports backslash-
- // escaping but whether Microsoft supports it is unclear.
+ // escaping (whether Microsoft supports it is unclear; but it
+ // definitely doesn't need it for backslashes themselves, for
+ // example, in paths).
//
+ bool e (tsys != "win32-msvc"); // Assume GNU if not MSVC.
+ string b;
+
for (size_t i (args_input), n (args.size () - 1); i != n; ++i)
{
- ofs << (i != args_input ? " " : "") << quote (args[i]);
+ const char* a (args[i]);
+
+ if (e) // We will most likely have backslashes so just do it.
+ {
+ for (b.clear (); *a != '\0'; ++a)
+ {
+ if (*a != '\\')
+ b += *a;
+ else
+ b += "\\\\";
+ }
+
+ a = b.c_str ();
+ }
+
+ ofs << (i != args_input ? " " : "") << quote (a);
}
ofs << '\n';