| 155 | |
| 156 | |
| 157 | ssize_t writeall(int fd, const void *buf, size_t nbytes) |
| 158 | // Write all the bytes to the given fd. Return the number of bytes written, |
| 159 | // or -1 if we hit an error or 0 if we can't write (in which case it is |
| 160 | // possible that some bytes were written successfully; we just don't say how |
| 161 | // many to the caller). Returns nbytes on success. |
| 162 | { |
| 163 | const char *cbuf = static_cast<const char *>(buf); |
| 164 | size_t total = 0; |
| 165 | |
| 166 | while(nbytes > 0) { |
| 167 | ssize_t byteswritten = write(fd, cbuf, nbytes); |
| 168 | if(byteswritten <= 0) { |
| 169 | return byteswritten; |
| 170 | } |
| 171 | |
| 172 | cbuf += byteswritten; |
| 173 | nbytes -= byteswritten; |
| 174 | total += byteswritten; |
| 175 | } |
| 176 | |
| 177 | return total; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | ssize_t readall(int fd, void *buf, size_t nbytes) |
no outgoing calls
no test coverage detected