Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-11-21 01:10:13 +0300
committerChristopher Faylor <me@cgf.cx>2000-11-21 01:10:13 +0300
commit9784d54da8326f03d7719fb6dc30fd158fc25083 (patch)
tree3d803bfbf108f3c2826b3d6acb54b9fa3642ef92 /winsup/cygwin/spawn.cc
parent099efae038316c57af95c01abddaf246e3b6028d (diff)
* spawn.cc (spawn_guts): Quoting was still wrong. Keep trying to fix it.
Diffstat (limited to 'winsup/cygwin/spawn.cc')
-rw-r--r--winsup/cygwin/spawn.cc26
1 files changed, 20 insertions, 6 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 211c15c04..030e6b6ab 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -480,17 +480,31 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
else
{
one_line.add ("\"", 1);
+ /* Handle embedded special characters " and \.
+ A " is always preceded by a \.
+ A \ is not special unless it precedes a ". If it does,
+ then all preceding \'s must be doubled to avoid having
+ the Windows command line parser interpret the \ as quoting
+ the ". This rule applies to a string of \'s before the end
+ of the string, since cygwin/windows uses a " to delimit the
+ argument. */
for (; (p = strpbrk (a, "\"\\")); a = ++p)
{
one_line.add (a, p - a);
- if (*p == '\\' && p[1] == '\\')
+ /* Find length of string of backslashes */
+ int n = strspn (p, "\\");
+ if (!n)
+ one_line.add ("\\\"", 2); /* No backslashes, so it must be a ".
+ The " has to be protected with a backslash. */
+ else
{
- one_line.add ("\\\\\\", 3);
- p++;
+ one_line.add (p, n); /* Add the run of backslashes */
+ /* Need to double up all of the preceding
+ backslashes if they precede a quote or EOS. */
+ if (!p[n] || p[n] == '"')
+ one_line.add (p, n);
+ p += n - 1; /* Point to last backslash */
}
- else if ((*p == '\\' && p[1] == '"') || *p == '"')
- one_line.add ("\\", 1);
- one_line.add (p, 1);
}
if (*a)
one_line.add (a);