| 105 | } |
| 106 | |
| 107 | ssize_t KittyIOFile::pwrite(uintptr_t offset, const void *buffer, size_t len) |
| 108 | { |
| 109 | _error = 0; |
| 110 | |
| 111 | if (_fd < 0) |
| 112 | return -1; |
| 113 | |
| 114 | const char *ptr = static_cast<const char *>(buffer); |
| 115 | size_t total = 0; |
| 116 | while (total < len) |
| 117 | { |
| 118 | size_t toWrite = std::min(len - total, _bufferSize); |
| 119 | #ifdef __APPLE__ |
| 120 | ssize_t n = KT_EINTR_RETRY(::pwrite(_fd, ptr + total, toWrite, (off_t)(offset + total))); |
| 121 | #else |
| 122 | ssize_t n = KT_EINTR_RETRY(::pwrite64(_fd, ptr + total, toWrite, (off64_t)(offset + total))); |
| 123 | #endif |
| 124 | if (n <= 0) |
| 125 | { |
| 126 | _error = (n < 0) ? errno : 0; |
| 127 | return total > 0 ? total : -1; |
| 128 | } |
| 129 | total += n; |
| 130 | } |
| 131 | return total; |
| 132 | } |
| 133 | |
| 134 | bool KittyIOFile::readToString(std::string *str) |
| 135 | { |
no outgoing calls
no test coverage detected