Differences From Artifact [8cc38c1f3c]:
- File src/OFProcess.m — part of check-in [37d2a81754] at 2017-05-07 21:25:56 on branch trunk — Use char{16,32}_t instead of of_char{16,32}_t (user: js, size: 14339) [annotate] [blame] [check-ins using]
To Artifact [57b3b6c720]:
- File
src/OFProcess.m
— part of check-in
[6b77a5dd8b]
at
2017-05-21 21:28:57
on branch trunk
— Prefix private methods with of_ instead of OF_
This matches Apple's style. (user: js, size: 14339) [annotate] [blame] [check-ins using]
| ︙ | ︙ | |||
54 55 56 57 58 59 60 | #if !defined(OF_WINDOWS) && !defined(HAVE_POSIX_SPAWNP) extern char **environ; #endif @interface OFProcess () #ifndef OF_WINDOWS | | | | | 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
forProgramName: (OFString *)programName
andArguments: (OFArray *)arguments;
- (char **)of_environmentForDictionary: (OFDictionary *)dictionary;
#else
- (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 | char **argv; if (pipe(_readPipe) != 0 || pipe(_writePipe) != 0) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; path = [program cStringWithEncoding: [OFLocalization encoding]]; | | | | 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
forProgramName: programName
andArguments: arguments];
@try {
char **env = [self
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 |
count: length + 1];
memcpy(argumentsCopy, [argumentsString UTF16String],
([argumentsString UTF16StringLength] + 1) * 2);
@try {
if (!CreateProcessW([program UTF16String],
argumentsCopy, NULL, NULL, TRUE,
CREATE_UNICODE_ENVIRONMENT,
| | | 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],
NULL, &si, &pi))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
} @finally {
[self freeMemory: argumentsCopy];
}
|
| ︙ | ︙ | |||
334 335 336 337 338 339 340 |
{
[self close];
[super dealloc];
}
#ifndef OF_WINDOWS
| | | 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
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 | for (i = 0; i < count; i++) (*argv)[i + 1] = (char *)[objects[i] cStringWithEncoding: encoding]; (*argv)[i + 1] = NULL; } | | | 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
{
OFEnumerator *keyEnumerator, *objectEnumerator;
char **envp;
size_t i, count;
of_string_encoding_t encoding;
if (environment == nil)
|
| ︙ | ︙ | |||
400 401 402 403 404 405 406 | } envp[i] = NULL; return envp; } #else | | | 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
{
OFDataArray *env;
OFEnumerator *keyEnumerator, *objectEnumerator;
OFString *key, *object;
const char16_t equal = '=';
const char16_t zero[2] = { 0, 0 };
|
| ︙ | ︙ |