Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ static FileContents readFile(std::string fileName,
int fd = open(fileName.c_str(), O_RDONLY);
if (fd == -1) throw SysError(fmt("opening '", fileName, "'"));

if ((size_t) read(fd, contents->data(), size) != size)
size_t bytesRead = 0;
ssize_t portion;
while ((portion = read(fd, contents->data() + bytesRead, size - bytesRead)) > 0)
bytesRead += portion;

if (bytesRead != size)
throw SysError(fmt("reading '", fileName, "'"));

close(fd);
Expand Down Expand Up @@ -496,7 +501,12 @@ static void writeFile(std::string fileName, FileContents contents)
if (fd == -1)
error("open");

if (write(fd, contents->data(), contents->size()) != (off_t) contents->size())
size_t bytesWritten = 0;
ssize_t portion;
while ((portion = write(fd, contents->data() + bytesWritten, contents->size() - bytesWritten)) > 0)
bytesWritten += portion;

if (bytesWritten != contents->size())
error("write");

if (close(fd) != 0)
Expand Down