summary refs log tree commit diff
path: root/nq.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-03-21 15:31:21 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2016-03-21 15:31:21 +0100
commit15d3b7ba7cf2db52aa1b33b517425dcae3ccadde (patch)
tree976f3e3333e017515d0854d5aeb2e7cda511d32d /nq.c
parentd6c8f4fee8392620dd7c33dc8e94ff1d84455633 (diff)
downloadnq-15d3b7ba7cf2db52aa1b33b517425dcae3ccadde.tar.gz
nq-15d3b7ba7cf2db52aa1b33b517425dcae3ccadde.tar.xz
nq-15d3b7ba7cf2db52aa1b33b517425dcae3ccadde.zip
nq: add dprintf stub for Solaris
Diffstat (limited to 'nq.c')
-rw-r--r--nq.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/nq.c b/nq.c
index 67e3485..9fda2b0 100644
--- a/nq.c
+++ b/nq.c
@@ -23,6 +23,10 @@
 /* for FreeBSD.  */
 #define _WITH_DPRINTF
 
+#if defined(__sun) && defined(__SVR4) && !defined(HAVE_DPRINTF)
+#define NEED_DPRINTF
+#endif
+
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -40,6 +44,24 @@
 #include <time.h>
 #include <unistd.h>
 
+#ifdef NEED_DPRINTF
+#include <stdarg.h>
+static int
+dprintf(int fd, const char *fmt, ...)
+{
+	char buf[128];  // good enough for usage in nq
+	va_list ap;
+	int r;
+
+	va_start(ap, fmt);
+	r = vsnprintf(buf, sizeof buf, fmt, ap);
+	va_end(ap);
+	if (r >= 0 && r < sizeof buf)
+		return write(fd, buf, r);
+	return -1;
+}
+#endif
+
 static void
 swrite(int fd, char *str)
 {