From d9492642c7d6f3f5191a313d179833318c7a7210 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 19 Mar 2022 18:29:07 -0700 Subject: [PATCH] gvpr: rewrite debug I/O output to use stdio instead of unistd There is no need to use the lower level `write` API for this I/O. By using `fprintf` instead, we avoid a dependency on non-portable unistd.h. Gitlab: #2204 --- cmd/gvpr/gvprmain.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/gvpr/gvprmain.c b/cmd/gvpr/gvprmain.c index 228e8365b..819b692a6 100644 --- a/cmd/gvpr/gvprmain.c +++ b/cmd/gvpr/gvprmain.c @@ -17,6 +17,9 @@ #include "config.h" +#include +#include +#include #ifdef HAVE_UNISTD_H #include @@ -34,14 +37,18 @@ #include static ssize_t outfn (void* sp, const char *buf, size_t nbyte, void* dp) { - write (1, " ", 8); - return write (1, buf, nbyte); + if (nbyte > (size_t)INT_MAX) { + return -1; + } + return printf("%.*s", (int)nbyte, buf); } static ssize_t errfn (void* sp, const char *buf, size_t nbyte, void* dp) { - write (2, " ", 8); - return write (2, buf, nbyte); + if (nbyte > (size_t)INT_MAX) { + return -1; + } + return fprintf(stderr, "%.*s", (int)nbyte, buf); } static int iofread(void *chan, char *buf, int bufsize) -- 2.40.0