* Read @p len bytes at @p ptr from descriptor @p desc, retrying if * interrupted. * * @retval >0 the actual number of bytes read * * @retval 0 for EOF * * @retval <0 for an error. * * Derived from GNU C's cccp.c. */
| 306 | * |
| 307 | * Derived from GNU C's cccp.c. */ |
| 308 | static int safe_read(int desc, char *ptr, size_t len) |
| 309 | { |
| 310 | int n_chars; |
| 311 | |
| 312 | if (len == 0) |
| 313 | return len; |
| 314 | |
| 315 | do { |
| 316 | n_chars = read(desc, ptr, len); |
| 317 | } while (n_chars < 0 && errno == EINTR); |
| 318 | |
| 319 | return n_chars; |
| 320 | } |
| 321 | |
| 322 | /* Remove existing file @dest and reopen, creating a new file with @mode */ |
| 323 | static int unlink_and_reopen(const char *dest, mode_t mode) |