| 334 | } |
| 335 | |
| 336 | int rename_tempfile(struct tempfile **tempfile_p, const char *path) |
| 337 | { |
| 338 | struct tempfile *tempfile = *tempfile_p; |
| 339 | |
| 340 | if (!is_tempfile_active(tempfile)) |
| 341 | BUG("rename_tempfile called for inactive object"); |
| 342 | |
| 343 | if (close_tempfile_gently(tempfile)) { |
| 344 | delete_tempfile(tempfile_p); |
| 345 | return -1; |
| 346 | } |
| 347 | |
| 348 | if (rename(tempfile->filename.buf, path)) { |
| 349 | int save_errno = errno; |
| 350 | delete_tempfile(tempfile_p); |
| 351 | errno = save_errno; |
| 352 | return -1; |
| 353 | } |
| 354 | |
| 355 | deactivate_tempfile(tempfile); |
| 356 | *tempfile_p = NULL; |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | int delete_tempfile(struct tempfile **tempfile_p) |
| 361 | { |
no test coverage detected