* Wrapper on top of write(2) function. It handles EAGAIN and EINTR states and sends whole buffer if possible. */
| 350 | * Wrapper on top of write(2) function. It handles EAGAIN and EINTR states and sends whole buffer if possible. |
| 351 | */ |
| 352 | static size_t sam_safe_write ( |
| 353 | int d, |
| 354 | const void *buf, |
| 355 | size_t nbyte) |
| 356 | { |
| 357 | ssize_t bytes_write; |
| 358 | ssize_t tmp_bytes_write; |
| 359 | |
| 360 | bytes_write = 0; |
| 361 | |
| 362 | do { |
| 363 | tmp_bytes_write = write (d, (const char *)buf + bytes_write, |
| 364 | (nbyte - bytes_write > SSIZE_MAX) ? SSIZE_MAX : nbyte - bytes_write); |
| 365 | |
| 366 | if (tmp_bytes_write == -1) { |
| 367 | if (!(errno == EAGAIN || errno == EINTR)) |
| 368 | return -1; |
| 369 | } else { |
| 370 | bytes_write += tmp_bytes_write; |
| 371 | } |
| 372 | } while (bytes_write != nbyte); |
| 373 | |
| 374 | return (bytes_write); |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | * Wrapper on top of read(2) function. It handles EAGAIN and EINTR states and reads whole buffer if possible. |
no outgoing calls
no test coverage detected