From 71b43c2803ffed08ec727c29d70a0d2de3ffb3f1 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Tue, 1 Nov 2011 09:29:08 +0100 Subject: [PATCH] Don't call writev() anymore. It might be a sexy syscall, but it's not portable and more complex than the mainstream solution. For sexy source program, go elsewhere! --- configure.ac | 2 +- sbr/error.c | 69 ++++++++++------------------------------------------------ 2 files changed, 12 insertions(+), 59 deletions(-) diff --git a/configure.ac b/configure.ac index 6a37f2f..2fba897 100644 --- a/configure.ac +++ b/configure.ac @@ -385,7 +385,7 @@ dnl --------------- AC_FUNC_VFORK AC_CHECK_LIB(mkstemp,mkstemp) AC_CHECK_FUNCS(waitpid wait3 sigaction sigprocmask sigblock sigsetmask \ - sighold sigrelse writev lstat uname tzset killpg mkstemp \ + sighold sigrelse lstat uname tzset killpg mkstemp \ getutent nl_langinfo mbtowc wcwidth) dnl sigsetjmp may be a macro diff --git a/sbr/error.c b/sbr/error.c index 7db8d18..d8313ce 100644 --- a/sbr/error.c +++ b/sbr/error.c @@ -7,12 +7,6 @@ */ #include - -#ifdef HAVE_WRITEV -# include -# include -#endif - #include @@ -62,64 +56,24 @@ admonish(char *what, char *fmt, ...) /* ** main routine for printing error messages. ** -** Use writev() if available, for slightly better performance. -** Why? Well, there are a couple of reasons. Primarily, it -** gives a smoother output... More importantly though, it's a -** sexy syscall()... +** Until 2011-11-01, this routine used writev(). In order to remove +** ``sexy'' syscalls, in favor for mainstream programming, I removed +** it. But I want to preserve the following comment: +** +** Use writev() if available, for slightly better performance. +** Why? Well, there are a couple of reasons. Primarily, it +** gives a smoother output... More importantly though, it's a +** sexy syscall()... +** +** advertise() does *not* use writev() anymore, and that's good so. +** -- meillo@marmaro.de */ void advertise(char *what, char *tail, char *fmt, va_list ap) { int eindex = errno; -#ifdef HAVE_WRITEV - char buffer[BUFSIZ], err[BUFSIZ]; - struct iovec iob[20], *iov; -#endif - fflush(stdout); - -#ifdef HAVE_WRITEV - fflush(stderr); - iov = iob; - - if (invo_name && *invo_name) { - iov->iov_len = strlen(iov->iov_base = invo_name); - iov++; - iov->iov_len = strlen(iov->iov_base = ": "); - iov++; - } - - vsnprintf(buffer, sizeof(buffer), fmt, ap); - iov->iov_len = strlen(iov->iov_base = buffer); - iov++; - if (what) { - if (*what) { - iov->iov_len = strlen(iov->iov_base = " "); - iov++; - iov->iov_len = strlen(iov->iov_base = what); - iov++; - iov->iov_len = strlen(iov->iov_base = ": "); - iov++; - } - if (!(iov->iov_base = strerror(eindex))) { - /* this shouldn't happen, but we'll test for it just in case */ - snprintf(err, sizeof(err), "Error %d", eindex); - iov->iov_base = err; - } - iov->iov_len = strlen(iov->iov_base); - iov++; - } - if (tail && *tail) { - iov->iov_len = strlen(iov->iov_base = ", "); - iov++; - iov->iov_len = strlen(iov->iov_base = tail); - iov++; - } - iov->iov_len = strlen(iov->iov_base = "\n"); - iov++; - writev(fileno(stderr), iob, iov - iob); -#else if (invo_name && *invo_name) fprintf(stderr, "%s: ", invo_name); vfprintf(stderr, fmt, ap); @@ -137,5 +91,4 @@ advertise(char *what, char *tail, char *fmt, va_list ap) if (tail) fprintf(stderr, ", %s", tail); fputc('\n', stderr); -#endif } -- 1.7.10.4