diff options
author | Ian Lance Taylor <iant@google.com> | 2007-09-25 06:43:17 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2007-09-25 06:43:17 +0000 |
commit | 82dcae9de0f7ca290bba97b6dfb8449e1a2e27fb (patch) | |
tree | 0c47d6a96f9fedfe8ed7862d913ff5e5cf9b9537 /gold/script.cc | |
parent | bae3688d8f8566ea43c712982cea95897ed359da (diff) | |
download | gdb-82dcae9de0f7ca290bba97b6dfb8449e1a2e27fb.zip gdb-82dcae9de0f7ca290bba97b6dfb8449e1a2e27fb.tar.gz gdb-82dcae9de0f7ca290bba97b6dfb8449e1a2e27fb.tar.bz2 |
Rework File_read interface. Get file size. Use pread when
available.
Diffstat (limited to 'gold/script.cc')
-rw-r--r-- | gold/script.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/gold/script.cc b/gold/script.cc index 53cd493..950fa15 100644 --- a/gold/script.cc +++ b/gold/script.cc @@ -299,17 +299,21 @@ class Lex void Lex::read_file(std::string* contents) { + off_t filesize = this->input_file_->file().filesize(); contents->clear(); + contents->reserve(filesize); + off_t off = 0; - off_t got; unsigned char buf[BUFSIZ]; - do + while (off < filesize) { - this->input_file_->file().read_up_to(off, sizeof buf, buf, &got); - contents->append(reinterpret_cast<char*>(&buf[0]), got); - off += got; + off_t get = BUFSIZ; + if (get > filesize - off) + get = filesize - off; + this->input_file_->file().read(off, get, buf); + contents->append(reinterpret_cast<char*>(&buf[0]), get); + off += get; } - while (got == sizeof buf); } // Return whether C can be the start of a name, if the next character |