summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2018-05-09 09:48:29 (GMT)
committerGitHub <noreply@github.com>2018-05-09 09:48:29 (GMT)
commit27ffe8ae871e7a186018d66020ef3f6162c12c69 (patch)
tree32c37f396c6425b37cb1d2697699c9de50b12ebf
parent1fa4d36fead44333528cbee4b5c04c207ce77ca4 (diff)
parentba2695a8110abbc8cc6baf0eea819922ee5007fa (diff)
downloadpatchelf-27ffe8ae871e7a186018d66020ef3f6162c12c69.zip
patchelf-27ffe8ae871e7a186018d66020ef3f6162c12c69.tar.gz
patchelf-27ffe8ae871e7a186018d66020ef3f6162c12c69.tar.bz2
Merge pull request #148 from stmarkevich/bigfile
fix reading and writing big files (e.g. > 2Gb)
-rw-r--r--src/patchelf.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index 118dbb0..3ca38d9 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -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);
@@ -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)