| 132 | bool KittyIOFile::readToString(std::string *str) |
| 133 | { |
| 134 | _error = 0; |
| 135 | |
| 136 | if (!str) |
| 137 | return false; |
| 138 | |
| 139 | str->clear(); |
| 140 | |
| 141 | auto s = info(); |
| 142 | if (_error == 0 && s.st_size > 0) |
| 143 | { |
| 144 | str->resize(static_cast<size_t>(s.st_size)); |
| 145 | ssize_t n = pread(0, (void*)str->data(), static_cast<size_t>(s.st_size)); |
| 146 | if (n > 0) |
| 147 | { |
| 148 | if (n != static_cast<ssize_t>(s.st_size)) |
| 149 | { |
| 150 | str->resize(static_cast<size_t>(n)); |
| 151 | } |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | str->clear(); |
| 156 | } |
| 157 | |
| 158 | std::vector<char> buffer(KT_IO_CHUNK_SIZE, 0); |
| 159 | kt_off64_t offset = 0; |
| 160 | while (true) |
| 161 | { |
| 162 | ssize_t n = pread(offset, buffer.data(), buffer.size()); |
| 163 | if (n <= 0) |
| 164 | break; |
| 165 | |
| 166 | offset += n; |