From ae850b1ac755f471beac4dbfef4654fe3fbaaae9 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 9 Jan 2024 22:04:24 +0100 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libpatch_fd_diff2_printer__.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 libpatch_fd_diff2_printer__.c (limited to 'libpatch_fd_diff2_printer__.c') diff --git a/libpatch_fd_diff2_printer__.c b/libpatch_fd_diff2_printer__.c new file mode 100644 index 0000000..3267b69 --- /dev/null +++ b/libpatch_fd_diff2_printer__.c @@ -0,0 +1,38 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +static void +put(struct libpatch_diff2_printer *this, const char *text, size_t len) +{ + size_t off; + ssize_t r; + int fd = ((struct printer_internals *)this->user_data)->f.fd; + for (off = 0; off < len; off += (size_t)r) { + r = write(fd, &text[off], len - off); + if (r < 0) { + if (errno != EINTR) { + this->error = errno; + break; + } + r = 0; + } + } +} + + +struct libpatch_diff2_printer * +libpatch_fd_diff2_printer__(int output) +{ + struct libpatch_diff2_printer *printer; + struct printer_internals *internals; + printer = calloc(1, sizeof(*printer) + sizeof(struct printer_internals)); + if (!printer) + return NULL; + internals = (void *)&((char *)printer)[sizeof(*printer)]; + printer->user_data = internals; + internals->put = put; + internals->f.fd = output; + return printer; + +} -- cgit v1.2.3-70-g09d2