* xread() is the same a read(), but it automatically restarts read() * operations with a recoverable error (EAGAIN and EINTR). xread() * DOES NOT GUARANTEE that "len" bytes is read even if the data is available. */
| 226 | * DOES NOT GUARANTEE that "len" bytes is read even if the data is available. |
| 227 | */ |
| 228 | ssize_t xread(int fd, void *buf, size_t len) |
| 229 | { |
| 230 | ssize_t nr; |
| 231 | if (len > MAX_IO_SIZE) |
| 232 | len = MAX_IO_SIZE; |
| 233 | while (1) { |
| 234 | nr = read(fd, buf, len); |
| 235 | if (nr < 0) { |
| 236 | if (errno == EINTR) |
| 237 | continue; |
| 238 | if (handle_nonblock(fd, POLLIN, errno)) |
| 239 | continue; |
| 240 | } |
| 241 | return nr; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * xwrite() is the same a write(), but it automatically restarts write() |