From 82dcae9de0f7ca290bba97b6dfb8449e1a2e27fb Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 25 Sep 2007 06:43:17 +0000 Subject: Rework File_read interface. Get file size. Use pread when available. --- gold/script.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'gold/script.cc') 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(&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(&buf[0]), get); + off += get; } - while (got == sizeof buf); } // Return whether C can be the start of a name, if the next character -- cgit v1.1