Instead of formatting to a buffer and then writing the buffer to an fd, 
just use dprintf to write formatted output directly to the fd.

Note that our dprintf() has the same async-signal-safety as our snprintf()

ok?

Philip Guenther


Index: newfs/mkfs.c
===================================================================
RCS file: /cvs/src/sbin/newfs/mkfs.c,v
retrieving revision 1.92
diff -u -p -r1.92 mkfs.c
--- newfs/mkfs.c        20 Aug 2015 22:02:21 -0000      1.92
+++ newfs/mkfs.c        10 Oct 2015 23:26:36 -0000
@@ -154,11 +154,9 @@ void
 siginfo(int sig)
 {
        int save_errno = errno;
-       char buf[128];
 
-       snprintf(buf, sizeof(buf), "%s: initializing cg %ld/%d\n",
+       dprintf(STDERR_FILENO, "%s: initializing cg %ld/%d\n",
            cur_fsys, (long)cur_cylno, sblock.fs_ncg);
-       write(STDERR_FILENO, buf, strlen(buf));
        errno = save_errno;
 }
 #endif
Index: ping/ping.c
===================================================================
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.127
diff -u -p -r1.127 ping.c
--- ping/ping.c 9 Oct 2015 01:37:06 -0000       1.127
+++ ping/ping.c 10 Oct 2015 23:26:36 -0000
@@ -623,7 +623,6 @@ void
 pinger(void)
 {
        struct icmp *icp;
-       char buf[8192];
        int cc, i;
        u_char *packet = outpack;
 
@@ -688,9 +687,8 @@ pinger(void)
        if (i < 0 || i != cc)  {
                if (i < 0)
                        perror("ping: sendto");
-               snprintf(buf, sizeof buf, "ping: wrote %s %d chars, ret=%d\n",
+               dprintf(STDOUT_FILENO, "ping: wrote %s %d chars, ret=%d\n",
                    hostname, cc, i);
-               write(STDOUT_FILENO, buf, strlen(buf));
        }
        if (!(options & F_QUIET) && options & F_FLOOD)
                (void)write(STDOUT_FILENO, &DOT, 1);

Reply via email to