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,
332332 int fd = open (fileName.c_str (), O_RDONLY);
333333 if (fd == -1 ) throw SysError (fmt (" opening '" , fileName, " '" ));
334334
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)
336341 throw SysError (fmt (" reading '" , fileName, " '" ));
337342
338343 close (fd);
@@ -496,7 +501,12 @@ static void writeFile(std::string fileName, FileContents contents)
496501 if (fd == -1 )
497502 error (" open" );
498503
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 ())
500510 error (" write" );
501511
502512 if (close (fd) != 0 )
You can’t perform that action at this time.
0 commit comments