1 /*- 2 * Copyright (c) 1991, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Keith Muller of the University of California, San Diego and Lance 7 * Visser of Convex Computer Corporation. 8 * 9 * %sccs.include.redist.c% 10 */ 11 12 #ifndef lint 13 static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 04/02/94"; 14 #endif /* not lint */ 15 16 #include <sys/types.h> 17 18 #include <err.h> 19 #include <stdio.h> 20 #include <stdlib.h> 21 #include <string.h> 22 #include <time.h> 23 #include <unistd.h> 24 25 #include "dd.h" 26 #include "extern.h" 27 28 void 29 summary() 30 { 31 time_t secs; 32 char buf[100]; 33 34 (void)time(&secs); 35 if ((secs -= st.start) == 0) 36 secs = 1; 37 /* Use snprintf(3) so that we don't reenter stdio(3). */ 38 (void)snprintf(buf, sizeof(buf), 39 "%u+%u records in\n%u+%u records out\n", 40 st.in_full, st.in_part, st.out_full, st.out_part); 41 (void)write(STDERR_FILENO, buf, strlen(buf)); 42 if (st.swab) { 43 (void)snprintf(buf, sizeof(buf), "%u odd length swab %s\n", 44 st.swab, (st.swab == 1) ? "block" : "blocks"); 45 (void)write(STDERR_FILENO, buf, strlen(buf)); 46 } 47 if (st.trunc) { 48 (void)snprintf(buf, sizeof(buf), "%u truncated %s\n", 49 st.trunc, (st.trunc == 1) ? "block" : "blocks"); 50 (void)write(STDERR_FILENO, buf, strlen(buf)); 51 } 52 (void)snprintf(buf, sizeof(buf), 53 "%u bytes transferred in %u secs (%u bytes/sec)\n", 54 st.bytes, secs, st.bytes / secs); 55 (void)write(STDERR_FILENO, buf, strlen(buf)); 56 } 57 58 /* ARGSUSED */ 59 void 60 summaryx(notused) 61 int notused; 62 { 63 64 summary(); 65 } 66 67 /* ARGSUSED */ 68 void 69 terminate(notused) 70 int notused; 71 { 72 73 exit(0); 74 } 75