ObjFW  Diff

Differences From Artifact [8cc38c1f3c]:

To Artifact [57b3b6c720]:


54
55
56
57
58
59
60
61

62
63
64

65
66

67
68
69
70
71
72
73
54
55
56
57
58
59
60

61
62
63

64
65

66
67
68
69
70
71
72
73







-
+


-
+

-
+








#if !defined(OF_WINDOWS) && !defined(HAVE_POSIX_SPAWNP)
extern char **environ;
#endif

@interface OFProcess ()
#ifndef OF_WINDOWS
- (void)OF_getArgV: (char ***)argv
- (void)of_getArgv: (char ***)argv
    forProgramName: (OFString *)programName
      andArguments: (OFArray *)arguments;
- (char **)OF_environmentForDictionary: (OFDictionary *)dictionary;
- (char **)of_environmentForDictionary: (OFDictionary *)dictionary;
#else
- (char16_t *)OF_environmentForDictionary: (OFDictionary *)dictionary;
- (char16_t *)of_environmentForDictionary: (OFDictionary *)dictionary;
#endif
@end

@implementation OFProcess
+ (instancetype)processWithProgram: (OFString *)program
{
	return [[[self alloc] initWithProgram: program] autorelease];
146
147
148
149
150
151
152
153

154
155
156
157
158
159

160
161
162
163
164
165
166
146
147
148
149
150
151
152

153
154
155
156
157
158

159
160
161
162
163
164
165
166







-
+





-
+







		char **argv;

		if (pipe(_readPipe) != 0 || pipe(_writePipe) != 0)
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];

		path = [program cStringWithEncoding: [OFLocalization encoding]];
		[self OF_getArgV: &argv
		[self of_getArgv: &argv
		  forProgramName: programName
		    andArguments: arguments];

		@try {
			char **env = [self
			    OF_environmentForDictionary: environment];
			    of_environmentForDictionary: environment];
# ifdef HAVE_POSIX_SPAWNP
			posix_spawn_file_actions_t actions;
			posix_spawnattr_t attr;

			if (posix_spawn_file_actions_init(&actions) != 0)
				@throw [OFInitializationFailedException
				    exceptionWithClass: [self class]];
302
303
304
305
306
307
308
309

310
311
312
313
314
315
316
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316







-
+







						    count: length + 1];
		memcpy(argumentsCopy, [argumentsString UTF16String],
		    ([argumentsString UTF16StringLength] + 1) * 2);
		@try {
			if (!CreateProcessW([program UTF16String],
			    argumentsCopy, NULL, NULL, TRUE,
			    CREATE_UNICODE_ENVIRONMENT,
			    [self OF_environmentForDictionary: environment],
			    [self of_environmentForDictionary: environment],
			    NULL, &si, &pi))
				@throw [OFInitializationFailedException
				    exceptionWithClass: [self class]];
		} @finally {
			[self freeMemory: argumentsCopy];
		}

334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348







-
+







{
	[self close];

	[super dealloc];
}

#ifndef OF_WINDOWS
- (void)OF_getArgV: (char ***)argv
- (void)of_getArgv: (char ***)argv
    forProgramName: (OFString *)programName
      andArguments: (OFArray *)arguments
{
	OFString *const *objects = [arguments objects];
	size_t i, count = [arguments count];
	of_string_encoding_t encoding;

356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370







-
+







	for (i = 0; i < count; i++)
		(*argv)[i + 1] =
		    (char *)[objects[i] cStringWithEncoding: encoding];

	(*argv)[i + 1] = NULL;
}

- (char **)OF_environmentForDictionary: (OFDictionary *)environment
- (char **)of_environmentForDictionary: (OFDictionary *)environment
{
	OFEnumerator *keyEnumerator, *objectEnumerator;
	char **envp;
	size_t i, count;
	of_string_encoding_t encoding;

	if (environment == nil)
400
401
402
403
404
405
406
407

408
409
410
411
412
413
414
400
401
402
403
404
405
406

407
408
409
410
411
412
413
414







-
+







	}

	envp[i] = NULL;

	return envp;
}
#else
- (char16_t *)OF_environmentForDictionary: (OFDictionary *)environment
- (char16_t *)of_environmentForDictionary: (OFDictionary *)environment
{
	OFDataArray *env;
	OFEnumerator *keyEnumerator, *objectEnumerator;
	OFString *key, *object;
	const char16_t equal = '=';
	const char16_t zero[2] = { 0, 0 };