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