Simpler.

ok?

--
Scott Cheloha

Index: bin/dd/misc.c
===================================================================
RCS file: /cvs/src/bin/dd/misc.c,v
retrieving revision 1.22
diff -u -p -r1.22 misc.c
--- bin/dd/misc.c       24 Oct 2017 14:21:10 -0000      1.22
+++ bin/dd/misc.c       31 Mar 2018 17:49:42 -0000
@@ -36,13 +36,9 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
-#include <sys/uio.h>
 
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <errno.h>
+#include <stdio.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -53,10 +49,7 @@ void
 summary(void)
 {
        struct timespec elapsed, now;
-       char buf[4][100];
-       struct iovec iov[4];
        double nanosecs;
-       int i = 0;
 
        if (ddflags & C_NOINFO)
                return;
@@ -67,38 +60,25 @@ summary(void)
        if (nanosecs == 0)
                nanosecs = 1;
 
-       /* Use snprintf(3) so that we don't reenter stdio(3). */
-       (void)snprintf(buf[0], sizeof(buf[0]),
-           "%zu+%zu records in\n%zu+%zu records out\n",
+       /* Be async safe: use dprintf(3). */
+       dprintf(STDERR_FILENO, "%zu+%zu records in\n%zu+%zu records out\n",
            st.in_full, st.in_part, st.out_full, st.out_part);
-       iov[i].iov_base = buf[0];
-       iov[i++].iov_len = strlen(buf[0]);
 
        if (st.swab) {
-               (void)snprintf(buf[1], sizeof(buf[1]),
-                   "%zu odd length swab %s\n",
-                    st.swab, (st.swab == 1) ? "block" : "blocks");
-               iov[i].iov_base = buf[1];
-               iov[i++].iov_len = strlen(buf[1]);
+               dprintf(STDERR_FILENO, "%zu odd length swab %s\n",
+                   st.swab, (st.swab == 1) ? "block" : "blocks");
        }
        if (st.trunc) {
-               (void)snprintf(buf[2], sizeof(buf[2]),
-                   "%zu truncated %s\n",
-                    st.trunc, (st.trunc == 1) ? "block" : "blocks");
-               iov[i].iov_base = buf[2];
-               iov[i++].iov_len = strlen(buf[2]);
+               dprintf(STDERR_FILENO, "%zu truncated %s\n",
+                   st.trunc, (st.trunc == 1) ? "block" : "blocks");
        }
        if (!(ddflags & C_NOXFER)) {
-               (void)snprintf(buf[3], sizeof(buf[3]),
+               dprintf(STDERR_FILENO,
                    "%lld bytes transferred in %lld.%03ld secs "
                    "(%0.0f bytes/sec)\n", (long long)st.bytes,
                    (long long)elapsed.tv_sec, elapsed.tv_nsec / 1000000,
                    ((double)st.bytes * 1000000000) / nanosecs);
-               iov[i].iov_base = buf[3];
-               iov[i++].iov_len = strlen(buf[3]);
        }
-
-       (void)writev(STDERR_FILENO, iov, i);
 }
 
 void

Reply via email to