misc.c (239991) | misc.c (250469) |
---|---|
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 * --- 23 unchanged lines hidden (view full) --- 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; 37#endif 38#endif /* not lint */ 39#include <sys/cdefs.h> | 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 * --- 23 unchanged lines hidden (view full) --- 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; 37#endif 38#endif /* not lint */ 39#include <sys/cdefs.h> |
40__FBSDID("$FreeBSD: head/bin/dd/misc.c 239991 2012-09-01 14:45:15Z ed $"); | 40__FBSDID("$FreeBSD: head/bin/dd/misc.c 250469 2013-05-10 18:43:36Z eadler $"); |
41 42#include <sys/types.h> 43#include <sys/time.h> 44 45#include <errno.h> 46#include <inttypes.h> | 41 42#include <sys/types.h> 43#include <sys/time.h> 44 45#include <errno.h> 46#include <inttypes.h> |
47#include <signal.h> |
|
47#include <stdio.h> 48#include <stdlib.h> 49#include <string.h> 50#include <unistd.h> 51 52#include "dd.h" 53#include "extern.h" 54 55void 56summary(void) 57{ 58 struct timeval tv; 59 double secs; | 48#include <stdio.h> 49#include <stdlib.h> 50#include <string.h> 51#include <unistd.h> 52 53#include "dd.h" 54#include "extern.h" 55 56void 57summary(void) 58{ 59 struct timeval tv; 60 double secs; |
60 char buf[100]; | |
61 62 (void)gettimeofday(&tv, NULL); 63 secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start; 64 if (secs < 1e-6) 65 secs = 1e-6; | 61 62 (void)gettimeofday(&tv, NULL); 63 secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start; 64 if (secs < 1e-6) 65 secs = 1e-6; |
66 /* Use snprintf(3) so that we don't reenter stdio(3). */ 67 (void)snprintf(buf, sizeof(buf), | 66 (void)fprintf(stderr, |
68 "%ju+%ju records in\n%ju+%ju records out\n", 69 st.in_full, st.in_part, st.out_full, st.out_part); | 67 "%ju+%ju records in\n%ju+%ju records out\n", 68 st.in_full, st.in_part, st.out_full, st.out_part); |
70 (void)write(STDERR_FILENO, buf, strlen(buf)); 71 if (st.swab) { 72 (void)snprintf(buf, sizeof(buf), "%ju odd length swab %s\n", | 69 if (st.swab) 70 (void)fprintf(stderr, "%ju odd length swab %s\n", |
73 st.swab, (st.swab == 1) ? "block" : "blocks"); | 71 st.swab, (st.swab == 1) ? "block" : "blocks"); |
74 (void)write(STDERR_FILENO, buf, strlen(buf)); 75 } 76 if (st.trunc) { 77 (void)snprintf(buf, sizeof(buf), "%ju truncated %s\n", | 72 if (st.trunc) 73 (void)fprintf(stderr, "%ju truncated %s\n", |
78 st.trunc, (st.trunc == 1) ? "block" : "blocks"); | 74 st.trunc, (st.trunc == 1) ? "block" : "blocks"); |
79 (void)write(STDERR_FILENO, buf, strlen(buf)); 80 } 81 (void)snprintf(buf, sizeof(buf), | 75 (void)fprintf(stderr, |
82 "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n", 83 st.bytes, secs, st.bytes / secs); | 76 "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n", 77 st.bytes, secs, st.bytes / secs); |
84 (void)write(STDERR_FILENO, buf, strlen(buf)); | 78 need_summary = 0; |
85} 86 87/* ARGSUSED */ 88void | 79} 80 81/* ARGSUSED */ 82void |
89summaryx(int notused __unused) | 83siginfo_handler(int signo __unused) |
90{ | 84{ |
91 int save_errno = errno; | |
92 | 85 |
93 summary(); 94 errno = save_errno; | 86 need_summary = 1; |
95} 96 97/* ARGSUSED */ 98void 99terminate(int sig) 100{ 101 102 summary(); 103 _exit(sig == 0 ? 0 : 1); 104} | 87} 88 89/* ARGSUSED */ 90void 91terminate(int sig) 92{ 93 94 summary(); 95 _exit(sig == 0 ? 0 : 1); 96} |