From 4f0b2c82e963eb17b2b33323de4c3a189221ccf5 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sat, 27 Feb 2016 21:56:37 -0800 Subject: [PATCH] Write header to stdout target. --- adsbus/opts.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/adsbus/opts.c b/adsbus/opts.c index 06f9df3..3a833e9 100644 --- a/adsbus/opts.c +++ b/adsbus/opts.c @@ -2,6 +2,7 @@ #include #include +#include "buf.h" #include "incoming.h" #include "outgoing.h" #include "peer.h" @@ -97,6 +98,17 @@ bool opts_add_stdout(char *arg) { if (!serializer) { return false; } - send_new(dup(1), serializer, NULL); + int fd = dup(1); + { + // TODO: move into standard location for non-socket fd handling + struct buf buf = BUF_INIT, *buf_ptr = &buf; + send_hello(&buf_ptr, serializer); + if (buf_ptr->length) { + if (write(fd, buf_at(buf_ptr, 0), buf_ptr->length) != (ssize_t) buf_ptr->length) { + return false; + } + } + } + send_new(fd, serializer, NULL); return true; }