Write until all buffer was written or an error except EINTR. Returns: -1 error happened, errno is set count all written
| 119 | // -1 error happened, errno is set |
| 120 | // count all written |
| 121 | static ssize_t temp_file_write_all(int fd, const void *buf, size_t count) { |
| 122 | size_t off = 0; |
| 123 | for (;;) { |
| 124 | ssize_t nw = write(fd, (char*)buf + off, count - off); |
| 125 | if (nw == (ssize_t)(count - off)) { // including count==0 |
| 126 | return count; |
| 127 | } |
| 128 | if (nw >= 0) { |
| 129 | off += nw; |
| 130 | } else if (errno != EINTR) { |
| 131 | return -1; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | int TempFile::save_bin(const void *buf, size_t count) { |
| 137 | if (_reopen_if_necessary() < 0) { |