︙ | | | ︙ | |
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
{
self = [super init];
@try {
#ifndef _WIN32
if (pipe(readPipe) != 0 || pipe(writePipe) != 0)
@throw [OFInitializationFailedException
exceptionWithClass: isa];
switch ((pid = fork())) {
case 0:;
OFString **objects = [arguments objects];
size_t i, count = [arguments count];
char **argv;
|
|
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
{
self = [super init];
@try {
#ifndef _WIN32
if (pipe(readPipe) != 0 || pipe(writePipe) != 0)
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
switch ((pid = fork())) {
case 0:;
OFString **objects = [arguments objects];
size_t i, count = [arguments count];
char **argv;
|
︙ | | | ︙ | |
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
close(writePipe[1]);
dup2(writePipe[0], 0);
dup2(readPipe[1], 1);
execvp([program cStringWithEncoding:
OF_STRING_ENCODING_NATIVE], argv);
@throw [OFInitializationFailedException
exceptionWithClass: isa];
case -1:
@throw [OFInitializationFailedException
exceptionWithClass: isa];
default:
close(readPipe[1]);
close(writePipe[0]);
break;
}
#else
SECURITY_ATTRIBUTES sa;
|
|
|
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
close(writePipe[1]);
dup2(writePipe[0], 0);
dup2(readPipe[1], 1);
execvp([program cStringWithEncoding:
OF_STRING_ENCODING_NATIVE], argv);
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
case -1:
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
default:
close(readPipe[1]);
close(writePipe[0]);
break;
}
#else
SECURITY_ATTRIBUTES sa;
|
︙ | | | ︙ | |
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
if (!CreatePipe(&readPipe[0], &readPipe[1], &sa, 0))
@throw [OFInitializationFailedException
exceptionWithClass: isa];
if (!SetHandleInformation(readPipe[0], HANDLE_FLAG_INHERIT, 0))
@throw [OFInitializationFailedException
exceptionWithClass: isa];
if (!CreatePipe(&writePipe[0], &writePipe[1], &sa, 0))
@throw [OFInitializationFailedException
exceptionWithClass: isa];
if (!SetHandleInformation(writePipe[1], HANDLE_FLAG_INHERIT, 0))
@throw [OFInitializationFailedException
exceptionWithClass: isa];
memset(&pi, 0, sizeof(pi));
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.hStdInput = writePipe[0];
si.hStdOutput = readPipe[1];
|
|
|
|
|
|
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
if (!CreatePipe(&readPipe[0], &readPipe[1], &sa, 0))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
if (!SetHandleInformation(readPipe[0], HANDLE_FLAG_INHERIT, 0))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
if (!CreatePipe(&writePipe[0], &writePipe[1], &sa, 0))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
if (!SetHandleInformation(writePipe[1], HANDLE_FLAG_INHERIT, 0))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
memset(&pi, 0, sizeof(pi));
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.hStdInput = writePipe[0];
si.hStdOutput = readPipe[1];
|
︙ | | | ︙ | |
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
argumentsCString = strdup([argumentsString
cStringWithEncoding: OF_STRING_ENCODING_NATIVE]);
@try {
if (!CreateProcess([program cStringWithEncoding:
OF_STRING_ENCODING_NATIVE], argumentsCString, NULL,
NULL, TRUE, 0, NULL, NULL, &si, &pi))
@throw [OFInitializationFailedException
exceptionWithClass: isa];
} @finally {
free(argumentsString);
}
[pool release];
CloseHandle(pi.hProcess);
|
|
|
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
argumentsCString = strdup([argumentsString
cStringWithEncoding: OF_STRING_ENCODING_NATIVE]);
@try {
if (!CreateProcess([program cStringWithEncoding:
OF_STRING_ENCODING_NATIVE], argumentsCString, NULL,
NULL, TRUE, 0, NULL, NULL, &si, &pi))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
} @finally {
free(argumentsString);
}
[pool release];
CloseHandle(pi.hProcess);
|
︙ | | | ︙ | |
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
!ReadFile(readPipe[0], buffer, length, &ret, NULL)) {
if (GetLastError() == ERROR_BROKEN_PIPE) {
atEndOfStream = YES;
return 0;
}
#endif
@throw [OFReadFailedException exceptionWithClass: isa
stream: self
requestedLength: length];
}
if (ret == 0)
atEndOfStream = YES;
|
|
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
!ReadFile(readPipe[0], buffer, length, &ret, NULL)) {
if (GetLastError() == ERROR_BROKEN_PIPE) {
atEndOfStream = YES;
return 0;
}
#endif
@throw [OFReadFailedException exceptionWithClass: [self class]
stream: self
requestedLength: length];
}
if (ret == 0)
atEndOfStream = YES;
|
︙ | | | ︙ | |
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
#else
DWORD ret;
if (writePipe[1] == NULL || atEndOfStream ||
!WriteFile(writePipe[1], buffer, length, &ret, NULL) ||
ret < length)
#endif
@throw [OFWriteFailedException exceptionWithClass: isa
stream: self
requestedLength: length];
}
- (void)dealloc
{
[self close];
|
|
|
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
#else
DWORD ret;
if (writePipe[1] == NULL || atEndOfStream ||
!WriteFile(writePipe[1], buffer, length, &ret, NULL) ||
ret < length)
#endif
@throw [OFWriteFailedException exceptionWithClass: [self class]
stream: self
requestedLength: length];
}
- (void)dealloc
{
[self close];
|
︙ | | | ︙ | |