File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -332,7 +332,12 @@ static FileContents readFile(std::string fileName,
332
332
int fd = open (fileName.c_str (), O_RDONLY);
333
333
if (fd == -1 ) throw SysError (fmt (" opening '" , fileName, " '" ));
334
334
335
- if ((size_t ) read (fd, contents->data (), size) != size)
335
+ size_t bytesRead = 0 ;
336
+ ssize_t portion;
337
+ while ((portion = read (fd, contents->data () + bytesRead, size - bytesRead)) > 0 )
338
+ bytesRead += portion;
339
+
340
+ if (bytesRead != size)
336
341
throw SysError (fmt (" reading '" , fileName, " '" ));
337
342
338
343
close (fd);
@@ -496,7 +501,12 @@ static void writeFile(std::string fileName, FileContents contents)
496
501
if (fd == -1 )
497
502
error (" open" );
498
503
499
- if (write (fd, contents->data (), contents->size ()) != (off_t ) contents->size ())
504
+ size_t bytesWritten = 0 ;
505
+ ssize_t portion;
506
+ while ((portion = write (fd, contents->data () + bytesWritten, contents->size () - bytesWritten)) > 0 )
507
+ bytesWritten += portion;
508
+
509
+ if (bytesWritten != contents->size ())
500
510
error (" write" );
501
511
502
512
if (close (fd) != 0 )
You can’t perform that action at this time.
0 commit comments