annotate lib/w32spawn.h @ 30235:d2d89737e596

Enable use of shell scripts as executables in mingw.
author Bruno Haible <bruno@clisp.org>
date Mon, 29 Sep 2008 15:13:25 +0200
parents 49d1cc4454bf
children e70e12db795d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24627
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Auxiliary functions for the creation of subprocesses. Native Woe32 API.
30235
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
2 Copyright (C) 2003, 2006-2008 Free Software Foundation, Inc.
24627
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2003.
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
29000
49d1cc4454bf Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 27635
diff changeset
5 This program is free software: you can redistribute it and/or modify
24627
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
29000
49d1cc4454bf Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 27635
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
49d1cc4454bf Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 27635
diff changeset
8 (at your option) any later version.
24627
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
29000
49d1cc4454bf Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 27635
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24627
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 /* Get declarations of the Win32 API functions. */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #define WIN32_LEAN_AND_MEAN
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <windows.h>
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 /* Get _get_osfhandle() and _open_osfhandle(). */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <io.h>
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdbool.h>
27635
0bd3697b93f0 * doc/gnulib-tool.texi (Initial import): Update to match current
Paul Eggert <eggert@cs.ucla.edu>
parents: 27306
diff changeset
26 #include <string.h>
24627
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <errno.h>
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include "xalloc.h"
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 /* Duplicates a file handle, making the copy uninheritable. */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 static int
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 dup_noinherit (int fd)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 {
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 HANDLE curr_process = GetCurrentProcess ();
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 HANDLE old_handle = (HANDLE) _get_osfhandle (fd);
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 HANDLE new_handle;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 int nfd;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 if (!DuplicateHandle (curr_process, /* SourceProcessHandle */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 old_handle, /* SourceHandle */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 curr_process, /* TargetProcessHandle */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 (PHANDLE) &new_handle, /* TargetHandle */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 (DWORD) 0, /* DesiredAccess */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 FALSE, /* InheritHandle */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 DUPLICATE_SAME_ACCESS)) /* Options */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 error (EXIT_FAILURE, 0, _("DuplicateHandle failed with error code 0x%08x"),
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 GetLastError ());
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 nfd = _open_osfhandle ((long) new_handle, O_BINARY);
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 if (nfd < 0)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 error (EXIT_FAILURE, errno, _("_open_osfhandle failed"));
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 return nfd;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 }
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 /* Prepares an argument vector before calling spawn().
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 Note that spawn() does not by itself call the command interpreter
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 GetVersionEx(&v);
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 v.dwPlatformId == VER_PLATFORM_WIN32_NT;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 }) ? "cmd.exe" : "command.com").
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 Instead it simply concatenates the arguments, separated by ' ', and calls
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 CreateProcess(). We must quote the arguments since Win32 CreateProcess()
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 special way:
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 - Space and tab are interpreted as delimiters. They are not treated as
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 delimiters if they are surrounded by double quotes: "...".
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 - Unescaped double quotes are removed from the input. Their only effect is
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 that within double quotes, space and tab are treated like normal
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 characters.
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 - Backslashes not followed by double quotes are not special.
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 - But 2*n+1 backslashes followed by a double quote become
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 n backslashes followed by a double quote (n >= 0):
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 \" -> "
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 \\\" -> \"
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 \\\\\" -> \\"
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 #define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 #define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 static char **
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 prepare_spawn (char **argv)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 {
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 size_t argc;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 char **new_argv;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 size_t i;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 /* Count number of arguments. */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 for (argc = 0; argv[argc] != NULL; argc++)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 ;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 /* Allocate new argument vector. */
30235
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
94 new_argv = XNMALLOC (1 + argc + 1, char *);
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
95
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
96 /* Add an element upfront that can be used when argv[0] turns out to be a
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
97 script, not a program.
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
98 On Unix, this would be "/bin/sh". On native Windows, "sh" is actually
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
99 "sh.exe". We have to omit the directory part and rely on the search in
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
100 PATH, because the mingw "mount points" are not visible inside Win32
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
101 CreateProcess(). */
d2d89737e596 Enable use of shell scripts as executables in mingw.
Bruno Haible <bruno@clisp.org>
parents: 29000
diff changeset
102 *new_argv++ = "sh.exe";
24627
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 /* Put quoted arguments into the new argument vector. */
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 for (i = 0; i < argc; i++)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 {
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 const char *string = argv[i];
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 if (string[0] == '\0')
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 new_argv[i] = xstrdup ("\"\"");
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 {
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 bool quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 size_t length;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 unsigned int backslashes;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 const char *s;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 char *quoted_string;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 char *p;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 length = 0;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 backslashes = 0;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 if (quote_around)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 length++;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 for (s = string; *s != '\0'; s++)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 {
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 char c = *s;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 if (c == '"')
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 length += backslashes + 1;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 length++;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 if (c == '\\')
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 backslashes++;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 else
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 backslashes = 0;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 }
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 if (quote_around)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 length += backslashes + 1;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 quoted_string = (char *) xmalloc (length + 1);
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 p = quoted_string;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 backslashes = 0;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 if (quote_around)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 *p++ = '"';
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 for (s = string; *s != '\0'; s++)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 {
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 char c = *s;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 if (c == '"')
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 {
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 unsigned int j;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 for (j = backslashes + 1; j > 0; j--)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 *p++ = '\\';
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 }
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 *p++ = c;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 if (c == '\\')
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 backslashes++;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 else
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 backslashes = 0;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 }
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 if (quote_around)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 {
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 unsigned int j;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 for (j = backslashes; j > 0; j--)
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 *p++ = '\\';
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 *p++ = '"';
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 }
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 *p = '\0';
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 new_argv[i] = quoted_string;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 }
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 else
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 new_argv[i] = (char *) string;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 }
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 new_argv[argc] = NULL;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 return new_argv;
b09322ccb0cb New module 'execute'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 }