author | coleenp |
Thu, 18 Jun 2015 00:40:51 +0000 | |
changeset 31364 | 782625e8fb3c |
parent 23837 | 6f3e6fee7b44 |
child 34101 | a1db3b482137 |
permissions | -rw-r--r-- |
14111 | 1 |
/* |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
2 |
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
14111 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#include <Windows.h> |
|
27 |
#include <io.h> |
|
28 |
#include <stdio.h> |
|
29 |
#include <string.h> |
|
30 |
#include <malloc.h> |
|
31 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
32 |
void report_error(char const * msg) |
15058
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
33 |
{ |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
34 |
LPVOID lpMsgBuf; |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
35 |
DWORD dw = GetLastError(); |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
36 |
|
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
37 |
FormatMessage( |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
38 |
FORMAT_MESSAGE_ALLOCATE_BUFFER | |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
39 |
FORMAT_MESSAGE_FROM_SYSTEM | |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
40 |
FORMAT_MESSAGE_IGNORE_INSERTS, |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
41 |
NULL, |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
42 |
dw, |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
43 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
44 |
(LPTSTR) &lpMsgBuf, |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
45 |
0, |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
46 |
NULL); |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
47 |
|
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
48 |
fprintf(stderr, |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
49 |
"%s Failed with error %d: %s\n", |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
50 |
msg, dw, lpMsgBuf); |
15058
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
51 |
|
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
52 |
LocalFree(lpMsgBuf); |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
53 |
} |
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
54 |
|
14111 | 55 |
/* |
56 |
* Test if pos points to /cygdrive/_/ where _ can |
|
57 |
* be any character. |
|
58 |
*/ |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
59 |
int is_cygdrive_here(int pos, char const *in, int len) |
14111 | 60 |
{ |
61 |
// Length of /cygdrive/c/ is 12 |
|
62 |
if (pos+12 > len) return 0; |
|
63 |
if (in[pos+11]=='/' && |
|
64 |
in[pos+9]=='/' && |
|
65 |
in[pos+8]=='e' && |
|
66 |
in[pos+7]=='v' && |
|
67 |
in[pos+6]=='i' && |
|
68 |
in[pos+5]=='r' && |
|
69 |
in[pos+4]=='d' && |
|
70 |
in[pos+3]=='g' && |
|
71 |
in[pos+2]=='y' && |
|
72 |
in[pos+1]=='c' && |
|
73 |
in[pos+0]=='/') { |
|
74 |
return 1; |
|
75 |
} |
|
76 |
return 0; |
|
77 |
} |
|
78 |
||
79 |
/* |
|
80 |
* Replace /cygdrive/_/ with _:/ |
|
81 |
* Works in place since drive letter is always |
|
82 |
* shorter than /cygdrive/ |
|
83 |
*/ |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
84 |
char *replace_cygdrive_cygwin(char const *in) |
14111 | 85 |
{ |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
86 |
size_t len = strlen(in); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
87 |
char *out = (char*) malloc(len+1); |
14111 | 88 |
int i,j; |
89 |
||
90 |
if (len < 12) { |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
91 |
memmove(out, in, len + 1); |
14111 | 92 |
return out; |
93 |
} |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
94 |
|
14111 | 95 |
for (i = 0, j = 0; i<len;) { |
96 |
if (is_cygdrive_here(i, in, len)) { |
|
97 |
out[j++] = in[i+10]; |
|
98 |
out[j++] = ':'; |
|
99 |
i+=11; |
|
100 |
} else { |
|
101 |
out[j] = in[i]; |
|
102 |
i++; |
|
103 |
j++; |
|
104 |
} |
|
105 |
} |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
106 |
out[j] = '\0'; |
14111 | 107 |
return out; |
108 |
} |
|
109 |
||
110 |
void append(char **b, size_t *bl, size_t *u, char *add, size_t addlen) |
|
111 |
{ |
|
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
112 |
while ((addlen+*u+1) > *bl) { |
14111 | 113 |
*bl *= 2; |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
114 |
*b = (char*) realloc(*b, *bl); |
14111 | 115 |
} |
116 |
memcpy(*b+*u, add, addlen); |
|
117 |
*u += addlen; |
|
118 |
} |
|
119 |
||
120 |
/* |
|
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
121 |
* Creates a new string from in where the first occurrence of sub is |
14111 | 122 |
* replaced by rep. |
123 |
*/ |
|
124 |
char *replace_substring(char *in, char *sub, char *rep) |
|
125 |
{ |
|
126 |
int in_len = strlen(in); |
|
127 |
int sub_len = strlen(sub); |
|
128 |
int rep_len = strlen(rep); |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
129 |
char *out = (char *) malloc(in_len - sub_len + rep_len + 1); |
14111 | 130 |
char *p; |
131 |
||
132 |
if (!(p = strstr(in, sub))) { |
|
133 |
// If sub isn't a substring of in, just return in. |
|
134 |
return in; |
|
135 |
} |
|
136 |
||
137 |
// Copy characters from beginning of in to start of sub. |
|
138 |
strncpy(out, in, p - in); |
|
139 |
out[p - in] = '\0'; |
|
140 |
||
141 |
sprintf(out + (p - in), "%s%s", rep, p + sub_len); |
|
142 |
||
143 |
return out; |
|
144 |
} |
|
145 |
||
146 |
char* msys_path_list; // @-separated list of paths prefix to look for |
|
147 |
char* msys_path_list_end; // Points to last \0 in msys_path_list. |
|
148 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
149 |
void setup_msys_path_list(char const * argument) |
14111 | 150 |
{ |
151 |
char* p; |
|
152 |
char* drive_letter_pos; |
|
153 |
||
154 |
msys_path_list = strdup(&argument[2]); |
|
155 |
msys_path_list_end = &msys_path_list[strlen(msys_path_list)]; |
|
156 |
||
157 |
// Convert all at-sign (@) in path list to \0. |
|
158 |
// @ was chosen as separator to minimize risk of other tools messing around with it |
|
159 |
p = msys_path_list; |
|
160 |
do { |
|
161 |
if (p[1] == ':') { |
|
162 |
// msys has mangled our path list, restore it from c:/... to /c/... |
|
163 |
drive_letter_pos = p+1; |
|
164 |
*drive_letter_pos = *p; |
|
165 |
*p = '/'; |
|
166 |
} |
|
167 |
||
168 |
// Look for an @ in the list |
|
169 |
p = strchr(p, '@'); |
|
170 |
if (p != NULL) { |
|
171 |
*p = '\0'; |
|
172 |
p++; |
|
173 |
} |
|
174 |
} while (p != NULL); |
|
175 |
} |
|
176 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
177 |
char *replace_cygdrive_msys(char const *in) |
14111 | 178 |
{ |
179 |
char* str; |
|
180 |
char* prefix; |
|
181 |
char* p; |
|
182 |
||
183 |
str = strdup(in); |
|
184 |
||
185 |
// For each prefix in the path list, search for it and replace /c/... with c:/... |
|
186 |
for (prefix = msys_path_list; prefix < msys_path_list_end && prefix != NULL; prefix += strlen(prefix)+1) { |
|
187 |
p=str; |
|
188 |
while ((p = strstr(p, prefix))) { |
|
189 |
char* drive_letter = p+1; |
|
190 |
*p = *drive_letter; |
|
191 |
*drive_letter = ':'; |
|
192 |
p++; |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
return str; |
|
197 |
} |
|
198 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
199 |
char*(*replace_cygdrive)(char const *in) = NULL; |
14111 | 200 |
|
201 |
char *files_to_delete[1024]; |
|
202 |
int num_files_to_delete = 0; |
|
203 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
204 |
char *fix_at_file(char const *in) |
14111 | 205 |
{ |
206 |
char *tmpdir; |
|
207 |
char name[2048]; |
|
208 |
char *atname; |
|
209 |
char *buffer; |
|
210 |
size_t buflen=65536; |
|
211 |
size_t used=0; |
|
212 |
size_t len; |
|
213 |
int rc; |
|
214 |
FILE *atout; |
|
215 |
FILE *atin; |
|
216 |
char block[2048]; |
|
217 |
size_t blocklen; |
|
218 |
char *fixed; |
|
219 |
||
220 |
atin = fopen(in+1, "r"); |
|
221 |
if (atin == NULL) { |
|
222 |
fprintf(stderr, "Could not read at file %s\n", in+1); |
|
223 |
exit(-1); |
|
224 |
} |
|
225 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
226 |
tmpdir = getenv("TEMP"); |
14111 | 227 |
if (tmpdir == NULL) { |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
228 |
#if _WIN64 |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
229 |
tmpdir = "c:/cygwin64/tmp"; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
230 |
#else |
14111 | 231 |
tmpdir = "c:/cygwin/tmp"; |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
232 |
#endif |
14111 | 233 |
} |
234 |
_snprintf(name, sizeof(name), "%s\\atfile_XXXXXX", tmpdir); |
|
235 |
||
236 |
rc = _mktemp_s(name, strlen(name)+1); |
|
237 |
if (rc) { |
|
238 |
fprintf(stderr, "Could not create temporary file name for at file!\n"); |
|
239 |
exit(-1); |
|
240 |
} |
|
241 |
||
242 |
atout = fopen(name, "w"); |
|
243 |
if (atout == NULL) { |
|
244 |
fprintf(stderr, "Could not open temporary file for writing! %s\n", name); |
|
245 |
exit(-1); |
|
246 |
} |
|
247 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
248 |
buffer = (char*) malloc(buflen); |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
249 |
while ((blocklen = fread(block, 1, sizeof(block), atin)) > 0) { |
14111 | 250 |
append(&buffer, &buflen, &used, block, blocklen); |
251 |
} |
|
252 |
buffer[used] = 0; |
|
253 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
|
254 |
fprintf(stderr, "fixpath input from @-file %s: %s\n", &in[1], buffer); |
|
255 |
} |
|
256 |
fixed = replace_cygdrive(buffer); |
|
257 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
|
258 |
fprintf(stderr, "fixpath converted to @-file %s is: %s\n", name, fixed); |
|
259 |
} |
|
260 |
fwrite(fixed, strlen(fixed), 1, atout); |
|
261 |
fclose(atin); |
|
262 |
fclose(atout); |
|
263 |
free(fixed); |
|
264 |
free(buffer); |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
265 |
files_to_delete[num_files_to_delete] = (char*) malloc(strlen(name)+1); |
14111 | 266 |
strcpy(files_to_delete[num_files_to_delete], name); |
267 |
num_files_to_delete++; |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
268 |
atname = (char*) malloc(strlen(name)+2); |
14111 | 269 |
atname[0] = '@'; |
270 |
strcpy(atname+1, name); |
|
271 |
return atname; |
|
272 |
} |
|
273 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
274 |
// given an argument, convert it to the windows command line safe quoted version |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
275 |
// using rules from: |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
276 |
// http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
277 |
// caller is responsible for freeing both input and output. |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
278 |
char * quote_arg(char const * in_arg) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
279 |
char *quoted = NULL; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
280 |
char *current = quoted; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
281 |
int pass; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
282 |
|
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
283 |
if (strlen(in_arg) == 0) { |
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
284 |
// empty string? explicitly quote it. |
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
285 |
return _strdup("\"\""); |
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
286 |
} |
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
287 |
|
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
288 |
if (strpbrk(in_arg, " \t\n\v\r\\\"") == NULL) { |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
289 |
return _strdup(in_arg); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
290 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
291 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
292 |
// process the arg twice. Once to calculate the size and then to copy it. |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
293 |
for (pass=1; pass<=2; pass++) { |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
294 |
char const *arg = in_arg; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
295 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
296 |
// initial " |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
297 |
if (pass == 2) { |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
298 |
*current = '\"'; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
299 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
300 |
current++; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
301 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
302 |
// process string to be quoted until NUL |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
303 |
do { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
304 |
int escapes = 0; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
305 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
306 |
while (*arg == '\\') { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
307 |
// count escapes. |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
308 |
escapes++; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
309 |
arg++; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
310 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
311 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
312 |
if (*arg == '\0') { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
313 |
// escape the escapes before final " |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
314 |
escapes *= 2; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
315 |
} else if (*arg == '"') { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
316 |
// escape the escapes and the " |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
317 |
escapes = escapes * 2 + 1; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
318 |
} else { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
319 |
// escapes aren't special, just echo them. |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
320 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
321 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
322 |
// emit some escapes |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
323 |
while (escapes > 0) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
324 |
if (pass == 2) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
325 |
*current = '\\'; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
326 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
327 |
current++; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
328 |
escapes--; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
329 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
330 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
331 |
// and the current char |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
332 |
if (pass == 2) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
333 |
*current = *arg; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
334 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
335 |
current++; |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
336 |
} while (*arg++ != '\0'); |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
337 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
338 |
// allocate the buffer |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
339 |
if (pass == 1) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
340 |
size_t alloc = (size_t) (current - quoted + (ptrdiff_t) 2); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
341 |
current = quoted = (char*) calloc(alloc, sizeof(char)); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
342 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
343 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
344 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
345 |
// final " and \0 |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
346 |
*(current - 1) = '"'; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
347 |
*current = '\0'; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
348 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
349 |
return quoted; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
350 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
351 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
352 |
int main(int argc, char const ** argv) |
14111 | 353 |
{ |
354 |
STARTUPINFO si; |
|
355 |
PROCESS_INFORMATION pi; |
|
356 |
unsigned short rc; |
|
357 |
||
358 |
char *line; |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
359 |
char *current; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
360 |
int i, cmd; |
14111 | 361 |
DWORD exitCode; |
362 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
363 |
if (argc<2 || argv[1][0] != '-' || (argv[1][1] != 'c' && argv[1][1] != 'm')) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
364 |
fprintf(stderr, "Usage: fixpath -c|m<path@path@...> /cygdrive/c/WINDOWS/notepad.exe [/cygdrive/c/x/test.txt|@/cygdrive/c/x/atfile]\n"); |
14111 | 365 |
exit(0); |
366 |
} |
|
367 |
||
368 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
369 |
char const * cmdline = GetCommandLine(); |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
370 |
fprintf(stderr, "fixpath input line >%s<\n", strstr(cmdline, argv[1])); |
14111 | 371 |
} |
372 |
||
373 |
if (argv[1][1] == 'c' && argv[1][2] == '\0') { |
|
374 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
375 |
fprintf(stderr, "fixpath using cygwin mode\n"); |
14111 | 376 |
} |
377 |
replace_cygdrive = replace_cygdrive_cygwin; |
|
378 |
} else if (argv[1][1] == 'm') { |
|
379 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
380 |
fprintf(stderr, "fixpath using msys mode, with path list: %s\n", &argv[1][2]); |
14111 | 381 |
} |
382 |
setup_msys_path_list(argv[1]); |
|
383 |
replace_cygdrive = replace_cygdrive_msys; |
|
384 |
} else { |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
385 |
fprintf(stderr, "fixpath Unknown mode: %s\n", argv[1]); |
14111 | 386 |
exit(-1); |
387 |
} |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
388 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
389 |
i = 2; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
390 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
391 |
// handle assignments |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
392 |
while (i < argc) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
393 |
char const * assignment = strchr(argv[i], '='); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
394 |
if (assignment != NULL && assignment != argv[i]) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
395 |
size_t var_len = (size_t) (assignment - argv[i] + (ptrdiff_t) 1); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
396 |
char *var = (char *) calloc(var_len, sizeof(char)); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
397 |
char *val = replace_cygdrive(assignment + 1); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
398 |
memmove(var, argv[i], var_len); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
399 |
var[var_len - 1] = '\0'; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
400 |
strupr(var); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
401 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
402 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
403 |
fprintf(stderr, "fixpath setting var >%s< to >%s<\n", var, val); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
404 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
405 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
406 |
rc = SetEnvironmentVariable(var, val); |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
407 |
if (!rc) { |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
408 |
// Could not set var for some reason. Try to report why. |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
409 |
const int msg_len = 80 + var_len + strlen(val); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
410 |
char * msg = (char *) alloca(msg_len); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
411 |
_snprintf_s(msg, msg_len, _TRUNCATE, "Could not set environment variable [%s=%s]", var, val); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
412 |
report_error(msg); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
413 |
exit(1); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
414 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
415 |
free(var); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
416 |
free(val); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
417 |
} else { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
418 |
// no more assignments; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
419 |
break; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
420 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
421 |
i++; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
422 |
} |
14111 | 423 |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
424 |
// remember index of the command |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
425 |
cmd = i; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
426 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
427 |
// handle command and it's args. |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
428 |
while (i < argc) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
429 |
char const *replaced = replace_cygdrive(argv[i]); |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
430 |
if (replaced[0] == '@') { |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
431 |
// Found at-file! Fix it! |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
432 |
replaced = fix_at_file(replaced); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
433 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
434 |
argv[i] = quote_arg(replaced); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
435 |
i++; |
14111 | 436 |
} |
437 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
438 |
// determine the length of the line |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
439 |
line = NULL; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
440 |
// args |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
441 |
for (i = cmd; i < argc; i++) { |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
442 |
line += (ptrdiff_t) strlen(argv[i]); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
443 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
444 |
// spaces and null |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
445 |
line += (ptrdiff_t) (argc - cmd + 1); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
446 |
// allocate |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
447 |
line = (char*) calloc(line - (char*) NULL, sizeof(char)); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
448 |
|
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
449 |
// copy in args. |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
450 |
current = line; |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
451 |
for (i = cmd; i < argc; i++) { |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
452 |
ptrdiff_t len = strlen(argv[i]); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
453 |
if (i != cmd) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
454 |
*current++ = ' '; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
455 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
456 |
memmove(current, argv[i], len); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
457 |
current += len; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
458 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
459 |
*current = '\0'; |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
460 |
|
14111 | 461 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
462 |
fprintf(stderr, "fixpath converted line >%s<\n", line); |
|
463 |
} |
|
464 |
||
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
465 |
if (cmd == argc) { |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
466 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
467 |
fprintf(stderr, "fixpath no command provided!\n"); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
468 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
469 |
exit(0); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
470 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
471 |
|
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
472 |
ZeroMemory(&si, sizeof(si)); |
14111 | 473 |
si.cb=sizeof(si); |
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
474 |
ZeroMemory(&pi, sizeof(pi)); |
14111 | 475 |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
476 |
fflush(stderr); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
477 |
fflush(stdout); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
478 |
|
14111 | 479 |
rc = CreateProcess(NULL, |
480 |
line, |
|
481 |
0, |
|
482 |
0, |
|
483 |
TRUE, |
|
484 |
0, |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
485 |
NULL, |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
486 |
NULL, |
14111 | 487 |
&si, |
488 |
&pi); |
|
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
489 |
if (!rc) { |
15058
61c4ac49cbda
8005635: build-infra: Support building install in jprt
erikj
parents:
14111
diff
changeset
|
490 |
// Could not start process for some reason. Try to report why: |
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
491 |
report_error("Could not start process!"); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
492 |
exit(126); |
14111 | 493 |
} |
494 |
||
23837
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
495 |
WaitForSingleObject(pi.hProcess, INFINITE); |
6f3e6fee7b44
8040332: fixpath must explicitly quote empty string parameters.
mduigou
parents:
23435
diff
changeset
|
496 |
GetExitCodeProcess(pi.hProcess, &exitCode); |
14111 | 497 |
|
498 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
|
499 |
for (i=0; i<num_files_to_delete; ++i) { |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
500 |
fprintf(stderr, "fixpath Not deleting temporary file %s\n", |
14111 | 501 |
files_to_delete[i]); |
502 |
} |
|
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
503 |
} else { |
14111 | 504 |
for (i=0; i<num_files_to_delete; ++i) { |
505 |
remove(files_to_delete[i]); |
|
506 |
} |
|
507 |
} |
|
508 |
||
23435
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
509 |
if (exitCode != 0) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
510 |
if (getenv("DEBUG_FIXPATH") != NULL) { |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
511 |
fprintf(stderr, "fixpath exit code %d\n", |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
512 |
exitCode); |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
513 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
514 |
} |
098340eccdcb
8039411: Enhance fixpath to allow environment variable assignments.
mduigou
parents:
15058
diff
changeset
|
515 |
|
14111 | 516 |
exit(exitCode); |
517 |
} |