| 296 | } |
| 297 | |
| 298 | int close_tempfile_gently(struct tempfile *tempfile) |
| 299 | { |
| 300 | int fd; |
| 301 | FILE *fp; |
| 302 | int err; |
| 303 | |
| 304 | if (!is_tempfile_active(tempfile) || tempfile->fd < 0) |
| 305 | return 0; |
| 306 | |
| 307 | fd = tempfile->fd; |
| 308 | fp = tempfile->fp; |
| 309 | tempfile->fd = -1; |
| 310 | if (fp) { |
| 311 | tempfile->fp = NULL; |
| 312 | if (ferror(fp)) { |
| 313 | err = -1; |
| 314 | if (!fclose(fp)) |
| 315 | errno = EIO; |
| 316 | } else { |
| 317 | err = fclose(fp); |
| 318 | } |
| 319 | } else { |
| 320 | err = close(fd); |
| 321 | } |
| 322 | |
| 323 | return err ? -1 : 0; |
| 324 | } |
| 325 | |
| 326 | int reopen_tempfile(struct tempfile *tempfile) |
| 327 | { |
no test coverage detected