diff options
author | wtc%netscape.com <devnull@localhost> | 2002-07-17 01:47:10 +0000 |
---|---|---|
committer | wtc%netscape.com <devnull@localhost> | 2002-07-17 01:47:10 +0000 |
commit | 918392fd0d7f5819b91235547209eeebccbe28c3 (patch) | |
tree | f4909bc399e3fce22f41a3f9f297af0df89888ef | |
parent | ad451f67def65af7d041ee3bd84023020d2ddc2f (diff) | |
download | nspr-hg-918392fd0d7f5819b91235547209eeebccbe28c3.tar.gz |
Merged the fix for bug 157347 from the tip (rev. 3.15) to
NSPRPUB_PRE_4_2_CLIENT_BRANCH. r=wtc. a=asa.
-rw-r--r-- | pr/src/md/os2/os2misc.c | 75 |
1 files changed, 9 insertions, 66 deletions
diff --git a/pr/src/md/os2/os2misc.c b/pr/src/md/os2/os2misc.c index 7acaa830..c27b0614 100644 --- a/pr/src/md/os2/os2misc.c +++ b/pr/src/md/os2/os2misc.c @@ -118,85 +118,28 @@ PR_Now(void) static int assembleCmdLine(char *const *argv, char **cmdLine) { char *const *arg; - char *p, *q; int cmdLineSize; - int numBackslashes; - int i; /* * Find out how large the command line buffer should be. */ cmdLineSize = 0; for (arg = argv+1; *arg; arg++) { - /* - * \ and " need to be escaped by a \. In the worst case, - * every character is a \ or ", so the string of length - * may double. If we quote an argument, that needs two ". - * Finally, we need a space between arguments, a null between - * the EXE name and the arguments, and 2 nulls at the end - * of command line. - */ - cmdLineSize += 2 * strlen(*arg) /* \ and " need to be escaped */ - + 4; /* space in between, or final nulls */ - } - p = *cmdLine = PR_MALLOC(cmdLineSize); - if (p == NULL) { + cmdLineSize += strlen(*arg) + 1; /* space in between, or final null */ + } + *cmdLine = PR_MALLOC(cmdLineSize); + if (*cmdLine == NULL) { return -1; } - for (arg = argv+1; *arg; arg++) { - /* Add a space to separates the arguments */ - if (arg > argv + 1) { - *p++ = ' '; - } - q = *arg; - numBackslashes = 0; - - while (*q) { - if (*q == '\\') { - numBackslashes++; - q++; - } else if (*q == '"') { - if (numBackslashes) { - /* - * Double the backslashes since they are followed - * by a quote - */ - for (i = 0; i < 2 * numBackslashes; i++) { - *p++ = '\\'; - } - numBackslashes = 0; - } - /* To escape the quote */ - *p++ = '\\'; - *p++ = *q++; - } else { - if (numBackslashes) { - /* - * Backslashes are not followed by a quote, so - * don't need to double the backslashes. - */ - for (i = 0; i < numBackslashes; i++) { - *p++ = '\\'; - } - numBackslashes = 0; - } - *p++ = *q++; - } - } + (*cmdLine)[0] = '\0'; - /* Now we are at the end of this argument */ - if (numBackslashes) { - for (i = 0; i < numBackslashes; i++) { - *p++ = '\\'; - } + for (arg = argv+1; *arg; arg++) { + if (arg > argv +1) { + strcat(*cmdLine, " "); } - if(arg == argv) - *p++ = ' '; + strcat(*cmdLine, *arg); } - - /* Add a null at the end */ - *p = '\0'; return 0; } |