︙ | | | ︙ | |
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# include <crt_externs.h>
#endif
#import "OFProcess.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"
#ifdef _WIN32
# include <windows.h>
|
>
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# include <crt_externs.h>
#endif
#import "OFProcess.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"
#ifdef _WIN32
# include <windows.h>
|
︙ | | | ︙ | |
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
for (i = 0; i < count; i++)
argv[i + 1] = (char*)[objects[i]
cStringUsingEncoding:
OF_STRING_ENCODING_NATIVE];
argv[i + 1] = NULL;
if (environment != nil)
[self OF_setEnvironment: environment];
close(readPipe[0]);
close(writePipe[1]);
dup2(writePipe[0], 0);
dup2(readPipe[1], 1);
execvp([program cStringUsingEncoding:
OF_STRING_ENCODING_NATIVE], argv);
|
|
>
>
|
>
>
>
>
>
|
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
for (i = 0; i < count; i++)
argv[i + 1] = (char*)[objects[i]
cStringUsingEncoding:
OF_STRING_ENCODING_NATIVE];
argv[i + 1] = NULL;
if (environment != nil) {
#ifdef __MACH__
*_NSGetEnviron() = [self
OF_environmentForDictionary: environment];
#else
environ = [self
OF_environmentForDictionary: environment];
#endif
}
close(readPipe[0]);
close(writePipe[1]);
dup2(writePipe[0], 0);
dup2(readPipe[1], 1);
execvp([program cStringUsingEncoding:
OF_STRING_ENCODING_NATIVE], argv);
|
︙ | | | ︙ | |
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
}
argumentsCString = strdup([argumentsString
cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]);
@try {
if (!CreateProcess([program cStringUsingEncoding:
OF_STRING_ENCODING_NATIVE], argumentsCString, NULL,
NULL, TRUE, 0, NULL, NULL, &si, &pi))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
} @finally {
free(argumentsString);
}
objc_autoreleasePoolPop(pool);
|
>
|
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
}
argumentsCString = strdup([argumentsString
cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]);
@try {
if (!CreateProcess([program cStringUsingEncoding:
OF_STRING_ENCODING_NATIVE], argumentsCString, NULL,
NULL, TRUE, 0, [self OF_environmentForDictionary:
environment], NULL, &si, &pi))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
} @finally {
free(argumentsString);
}
objc_autoreleasePoolPop(pool);
|
︙ | | | ︙ | |
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
[self release];
@throw e;
}
return self;
}
- (void)OF_setEnvironment: (OFDictionary*)environment
{
OFEnumerator *keyEnumerator, *objectEnumerator;
char **envp;
size_t i, count;
count = [environment count];
envp = [self allocMemoryWithSize: sizeof(char*)
count: count + 1];
keyEnumerator = [environment keyEnumerator];
objectEnumerator = [environment objectEnumerator];
|
|
>
>
>
>
|
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
[self release];
@throw e;
}
return self;
}
- (char**)OF_environmentForDictionary: (OFDictionary*)environment
{
OFEnumerator *keyEnumerator, *objectEnumerator;
#ifndef _WIN32
char **envp;
size_t i, count;
if (environment == nil)
return NULL;
count = [environment count];
envp = [self allocMemoryWithSize: sizeof(char*)
count: count + 1];
keyEnumerator = [environment keyEnumerator];
objectEnumerator = [environment objectEnumerator];
|
︙ | | | ︙ | |
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
memcpy(envp[i] + keyLen + 1, [object cStringUsingEncoding:
OF_STRING_ENCODING_NATIVE], objectLen);
envp[i][keyLen + objectLen + 1] = '\0';
}
envp[i] = NULL;
#ifdef __MACH__
*_NSGetEnviron() = envp;
#else
environ = envp;
#endif
}
- (BOOL)lowlevelIsAtEndOfStream
{
#ifndef _WIN32
if (readPipe[0] == -1)
|
<
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
memcpy(envp[i] + keyLen + 1, [object cStringUsingEncoding:
OF_STRING_ENCODING_NATIVE], objectLen);
envp[i][keyLen + objectLen + 1] = '\0';
}
envp[i] = NULL;
return envp;
#else
OFDataArray *env = [OFDataArray dataArray];
OFString *key, *object;
keyEnumerator = [environment keyEnumerator];
objectEnumerator = [environment objectEnumerator];
while ((key = [keyEnumerator nextObject]) != nil &&
(object = [objectEnumerator nextObject]) != nil) {
[env addItems: [key UTF8String]
count: [key UTF8StringLength]];
[env addItems: "="
count: 1];
[env addItems: [object UTF8String]
count: [object UTF8StringLength]];
[env addItems: ""
count: 1];
}
[env addItems: ""
count: 1];
return [env items];
#endif
}
- (BOOL)lowlevelIsAtEndOfStream
{
#ifndef _WIN32
if (readPipe[0] == -1)
|
︙ | | | ︙ | |