From 857715e1465062bc5a5f0dcea5ef325ed8deb6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Sat, 9 Jan 2021 16:16:59 +0000 Subject: [PATCH] Cleanup and remove uio deps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- secret.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/secret.c b/secret.c index dd4164c..bf1dd6c 100644 --- a/secret.c +++ b/secret.c @@ -1,4 +1,5 @@ -#define _GNU_SOURCE +#include "argz/argz.c" +#include "libhydrogen/hydrogen.c" #include #include @@ -10,14 +11,10 @@ #include #include #include -#include #include #include #include -#include "argz/argz.c" -#include "libhydrogen/hydrogen.c" - #define S_COUNT(x) (sizeof(x) / sizeof((x)[0])) #define S_VER_MAJOR 0U #define S_VER_MINOR 11U @@ -68,8 +65,9 @@ _Noreturn static void s_fatal(const char *fmt, ...) { va_list ap; - char buf[256]; - size_t size = sizeof(buf); + char tmp[256] = "Fatal: "; + char *buf = &tmp[7]; + size_t size = sizeof(tmp) - 7; va_start(ap, fmt); int ret = vsnprintf(buf, size, fmt, ap); @@ -78,16 +76,11 @@ s_fatal(const char *fmt, ...) if (ret <= 0) { buf[0] = '?'; size = 1; + } else if (size > (size_t)ret) { + size = (size_t)ret + 1; } - if (size > (size_t)ret) - size = (size_t)ret; - - char hdr[] = "Fatal: "; - struct iovec iov[] = { - {hdr, sizeof(hdr) - 1}, - {buf, size}, {"\n", 1}, - }; - writev(2, iov, 3); + buf[size - 1] = '\n'; + write(2, tmp, size + 7); s_exit(1); }