diff options
author | James Ross-Gowan <rossymiles@gmail.com> | 2015-03-24 15:40:35 +1100 |
---|---|---|
committer | James Ross-Gowan <rossymiles@gmail.com> | 2015-03-24 15:53:36 +1100 |
commit | 603a0f733f5b343f52f1354483a9f9e1b53604c2 (patch) | |
tree | 5525d87fab15c3f47468029e7eb7c183be51bac7 /osdep/subprocess-win.c | |
parent | 54cc610fde7cfa86848200db2f5dde6a5b11980e (diff) | |
download | mpv-603a0f733f5b343f52f1354483a9f9e1b53604c2.tar.bz2 mpv-603a0f733f5b343f52f1354483a9f9e1b53604c2.tar.xz |
subprocess-win: clarify argument escaping logic
This bit always seemed confusing to me.
Diffstat (limited to 'osdep/subprocess-win.c')
-rw-r--r-- | osdep/subprocess-win.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/osdep/subprocess-win.c b/osdep/subprocess-win.c index 7ea6d39cba..6c9ccf2382 100644 --- a/osdep/subprocess-win.c +++ b/osdep/subprocess-win.c @@ -54,22 +54,22 @@ static void write_arg(bstr *cmdline, char *arg) for (int pos = 0; arg[pos]; pos++) { switch (arg[pos]) { case '\\': - // Count backslashes that appear in a row + // Count consecutive backslashes num_slashes++; break; case '"': + // Write the argument up to the point before the quote bstr_xappend(NULL, cmdline, (struct bstr){arg, pos}); + arg += pos; + pos = 0; - // Double preceding slashes + // Double backslashes preceding the quote for (int i = 0; i < num_slashes; i++) bstr_xappend(NULL, cmdline, bstr0("\\")); + num_slashes = 0; - // Escape the following quote + // Escape the quote itself bstr_xappend(NULL, cmdline, bstr0("\\")); - - arg += pos; - pos = 0; - num_slashes = 0; break; default: num_slashes = 0; @@ -79,7 +79,7 @@ static void write_arg(bstr *cmdline, char *arg) // Write the rest of the argument bstr_xappend(NULL, cmdline, bstr0(arg)); - // Double slashes that appear at the end of the string + // Double backslashes at the end of the argument for (int i = 0; i < num_slashes; i++) bstr_xappend(NULL, cmdline, bstr0("\\")); |