From 2ccfafe67fa5c46611d0a505457a283c904fc169 Mon Sep 17 00:00:00 2001 From: "Sijmen J. Mulder" Date: Wed, 29 Sep 2021 01:06:10 +0200 Subject: [PATCH] dprintf() polyfill for Solaris --- src/nnn.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/nnn.c b/src/nnn.c index ccbebe742..68e011b5b 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -121,6 +121,10 @@ #define alloca(size) __builtin_alloca(size) #endif +#ifdef __sun +#define NEED_DPRINTF +#endif + #include "nnn.h" #include "dbg.h" @@ -856,6 +860,27 @@ static void notify_fifo(bool force); /* Functions */ +#ifdef NEED_DPRINTF +static int dprintf(int fd, const char *format, ...) +{ + va_list ap; + char *s; + int len, nwritten; + + va_start(ap, format); + len = vasprintf(&s, format, ap); + va_end(ap); + + if (len == -1) + return -1; + + nwritten = write(fd, s, len); + free(s); + + return nwritten; +} +#endif + static void sigint_handler(int sig) { (void) sig;