| 564 | } |
| 565 | |
| 566 | static int write_message(const void *buf, size_t len, const char *filename, |
| 567 | int append_eol) |
| 568 | { |
| 569 | struct lock_file msg_file = LOCK_INIT; |
| 570 | |
| 571 | int msg_fd = hold_lock_file_for_update(&msg_file, filename, 0); |
| 572 | if (msg_fd < 0) |
| 573 | return error_errno(_("could not lock '%s'"), filename); |
| 574 | if (write_in_full(msg_fd, buf, len) < 0) { |
| 575 | error_errno(_("could not write to '%s'"), filename); |
| 576 | rollback_lock_file(&msg_file); |
| 577 | return -1; |
| 578 | } |
| 579 | if (append_eol && write(msg_fd, "\n", 1) < 0) { |
| 580 | error_errno(_("could not write eol to '%s'"), filename); |
| 581 | rollback_lock_file(&msg_file); |
| 582 | return -1; |
| 583 | } |
| 584 | if (commit_lock_file(&msg_file) < 0) |
| 585 | return error(_("failed to finalize '%s'"), filename); |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | int read_oneliner(struct strbuf *buf, |
| 591 | const char *path, unsigned flags) |
no test coverage detected