* xwrite() is the same a write(), but it automatically restarts write() * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT * GUARANTEE that "len" bytes is written even if the operation is successful. */
| 248 | * GUARANTEE that "len" bytes is written even if the operation is successful. |
| 249 | */ |
| 250 | ssize_t xwrite(int fd, const void *buf, size_t len) |
| 251 | { |
| 252 | ssize_t nr; |
| 253 | if (len > MAX_IO_SIZE) |
| 254 | len = MAX_IO_SIZE; |
| 255 | while (1) { |
| 256 | nr = write(fd, buf, len); |
| 257 | if (nr < 0) { |
| 258 | if (errno == EINTR) |
| 259 | continue; |
| 260 | if (handle_nonblock(fd, POLLOUT, errno)) |
| 261 | continue; |
| 262 | } |
| 263 | |
| 264 | return nr; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * xpread() is the same as pread(), but it automatically restarts pread() |