aboutsummaryrefslogtreecommitdiffstats
path: root/libpatch_stream_diff2_printer__.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-01-09 22:04:24 +0100
committerMattias Andrée <maandree@kth.se>2024-01-09 22:04:24 +0100
commitae850b1ac755f471beac4dbfef4654fe3fbaaae9 (patch)
tree319e7f7f1b99cd1ee75e100f0a29b0f7c827ccea /libpatch_stream_diff2_printer__.c
downloadlibpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.gz
libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.bz2
libpatch-ae850b1ac755f471beac4dbfef4654fe3fbaaae9.tar.xz
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libpatch_stream_diff2_printer__.c')
-rw-r--r--libpatch_stream_diff2_printer__.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libpatch_stream_diff2_printer__.c b/libpatch_stream_diff2_printer__.c
new file mode 100644
index 0000000..6c6bc14
--- /dev/null
+++ b/libpatch_stream_diff2_printer__.c
@@ -0,0 +1,39 @@
+/* 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, r;
+ FILE *f = ((struct printer_internals *)this->user_data)->f.stream;
+ if (ferror(f))
+ return;
+ for (off = 0; off < len; off += r) {
+ r = fwrite(&text[off], 1, len - off, f);
+ if (!r) {
+ if (errno != EINTR) {
+ this->error = errno;
+ break;
+ }
+ clearerr(f);
+ }
+ }
+}
+
+
+struct libpatch_diff2_printer *
+libpatch_stream_diff2_printer__(FILE *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.stream = output;
+ return printer;
+
+}