Signed-off-by: Paul Tan <pyokagan@xxxxxxxxx> --- cache.h | 1 + wrapper.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/cache.h b/cache.h index 55d443e..aa5e97c 100644 --- a/cache.h +++ b/cache.h @@ -1700,6 +1700,7 @@ static inline ssize_t write_str_in_full(int fd, const char *str) extern int write_file(const char *path, const char *fmt, ...); extern int write_file_gently(const char *path, const char *fmt, ...); +extern void append_file(const char *path, const char *fmt, ...); /* pager.c */ extern void setup_pager(void); diff --git a/wrapper.c b/wrapper.c index 9afc1a0..cd77e94 100644 --- a/wrapper.c +++ b/wrapper.c @@ -709,6 +709,29 @@ int write_file_gently(const char *path, const char *fmt, ...) return status; } +void append_file(const char *path, const char *fmt, ...) +{ + struct strbuf sb = STRBUF_INIT; + int fd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0666); + va_list params; + if (fd < 0) + die_errno(_("could not open %s for appending"), path); + va_start(params, fmt); + strbuf_vaddf(&sb, fmt, params); + va_end(params); + strbuf_complete_line(&sb); + if (write_in_full(fd, sb.buf, sb.len) != sb.len) { + int err = errno; + close(fd); + strbuf_release(&sb); + errno = err; + die_errno(_("could not write to %s"), path); + } + strbuf_release(&sb); + if (close(fd)) + die_errno(_("could not close %s"), path); +} + void sleep_millisec(int millisec) { poll(NULL, 0, millisec); -- 2.7.0 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html