summaryrefslogtreecommitdiffstats
path: root/bin/dd/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/dd/misc.c')
-rw-r--r--bin/dd/misc.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/bin/dd/misc.c b/bin/dd/misc.c
index 8edc5a5..84cc5ee 100644
--- a/bin/dd/misc.c
+++ b/bin/dd/misc.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <inttypes.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -57,41 +58,32 @@ summary(void)
{
struct timeval tv;
double secs;
- char buf[100];
(void)gettimeofday(&tv, NULL);
secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
if (secs < 1e-6)
secs = 1e-6;
- /* Use snprintf(3) so that we don't reenter stdio(3). */
- (void)snprintf(buf, sizeof(buf),
+ (void)fprintf(stderr,
"%ju+%ju records in\n%ju+%ju records out\n",
st.in_full, st.in_part, st.out_full, st.out_part);
- (void)write(STDERR_FILENO, buf, strlen(buf));
- if (st.swab) {
- (void)snprintf(buf, sizeof(buf), "%ju odd length swab %s\n",
+ if (st.swab)
+ (void)fprintf(stderr, "%ju odd length swab %s\n",
st.swab, (st.swab == 1) ? "block" : "blocks");
- (void)write(STDERR_FILENO, buf, strlen(buf));
- }
- if (st.trunc) {
- (void)snprintf(buf, sizeof(buf), "%ju truncated %s\n",
+ if (st.trunc)
+ (void)fprintf(stderr, "%ju truncated %s\n",
st.trunc, (st.trunc == 1) ? "block" : "blocks");
- (void)write(STDERR_FILENO, buf, strlen(buf));
- }
- (void)snprintf(buf, sizeof(buf),
+ (void)fprintf(stderr,
"%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
st.bytes, secs, st.bytes / secs);
- (void)write(STDERR_FILENO, buf, strlen(buf));
+ need_summary = 0;
}
/* ARGSUSED */
void
-summaryx(int notused __unused)
+siginfo_handler(int signo __unused)
{
- int save_errno = errno;
- summary();
- errno = save_errno;
+ need_summary = 1;
}
/* ARGSUSED */
OpenPOWER on IntegriCloud