@@ -51,6 +51,11 @@ typedef struct RemoteReflectionInfo {
51
51
} RemoteReflectionInfo ;
52
52
53
53
static void errorAndExit (const char * message ) {
54
+ fprintf (stderr , "%s\n" , message );
55
+ abort ();
56
+ }
57
+
58
+ static void errnoAndExit (const char * message ) {
54
59
fprintf (stderr , "%s: %s\n" , message , strerror (errno ));
55
60
abort ();
56
61
}
@@ -165,10 +170,13 @@ void PipeMemoryReader_collectBytesFromPipe(const PipeMemoryReader *Reader,
165
170
int ReadFD = PipeMemoryReader_getParentReadFD (Reader );
166
171
while (Size ) {
167
172
int bytesRead = read (ReadFD , Dest , Size );
168
- if (bytesRead == - EINTR )
169
- continue ;
170
- if (bytesRead <= 0 )
171
- errorAndExit ("collectBytesFromPipe" );
173
+ if (bytesRead < 0 )
174
+ if (errno == EINTR )
175
+ continue ;
176
+ else
177
+ errnoAndExit ("collectBytesFromPipe" );
178
+ else if (bytesRead == 0 )
179
+ errorAndExit ("collectBytesFromPipe: Unexpected end of file" );
172
180
Size -= bytesRead ;
173
181
Dest += bytesRead ;
174
182
}
@@ -232,9 +240,9 @@ static
232
240
PipeMemoryReader createPipeMemoryReader () {
233
241
PipeMemoryReader Reader ;
234
242
if (pipe (Reader .to_child ))
235
- errorAndExit ("Couldn't create pipes to child process" );
243
+ errnoAndExit ("Couldn't create pipes to child process" );
236
244
if (pipe (Reader .from_child ))
237
- errorAndExit ("Couldn't create pipes from child process" );
245
+ errnoAndExit ("Couldn't create pipes from child process" );
238
246
return Reader ;
239
247
}
240
248
@@ -265,7 +273,7 @@ PipeMemoryReader_receiveReflectionInfo(SwiftReflectionContextRef RC,
265
273
RemoteReflectionInfo * RemoteInfos = calloc (NumReflectionInfos ,
266
274
sizeof (RemoteReflectionInfo ));
267
275
if (RemoteInfos == NULL )
268
- errorAndExit ("malloc failed" );
276
+ errnoAndExit ("malloc failed" );
269
277
270
278
for (size_t i = 0 ; i < NumReflectionInfos ; ++ i ) {
271
279
RemoteInfos [i ] = makeRemoteReflectionInfo (
@@ -385,8 +393,7 @@ int doDumpHeapInstance(const char *BinaryFilename) {
385
393
pid_t pid = _fork ();
386
394
switch (pid ) {
387
395
case -1 :
388
- errorAndExit ("Couldn't fork child process" );
389
- exit (EXIT_FAILURE );
396
+ errnoAndExit ("Couldn't fork child process" );
390
397
case 0 : { // Child:
391
398
close (PipeMemoryReader_getParentWriteFD (& Pipe ));
392
399
close (PipeMemoryReader_getParentReadFD (& Pipe ));
0 commit comments