150567Sbostic /*-
2*66634Spendry * Copyright (c) 1991, 1993, 1994
360660Sbostic * The Regents of the University of California. All rights reserved.
450567Sbostic *
550567Sbostic * This code is derived from software contributed to Berkeley by
650588Sbostic * Keith Muller of the University of California, San Diego and Lance
750588Sbostic * Visser of Convex Computer Corporation.
850567Sbostic *
950567Sbostic * %sccs.include.redist.c%
1050567Sbostic */
1150567Sbostic
1250567Sbostic #ifndef lint
13*66634Spendry static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 04/02/94";
1450567Sbostic #endif /* not lint */
1550567Sbostic
1650567Sbostic #include <sys/types.h>
1759462Sbostic
1866617Spendry #include <err.h>
1959462Sbostic #include <stdio.h>
2059462Sbostic #include <stdlib.h>
2159462Sbostic #include <string.h>
2266617Spendry #include <time.h>
2350567Sbostic #include <unistd.h>
2459462Sbostic
2550567Sbostic #include "dd.h"
2650567Sbostic #include "extern.h"
2750567Sbostic
2850567Sbostic void
summary()2966617Spendry summary()
3050567Sbostic {
3153813Smarc time_t secs;
3250567Sbostic char buf[100];
3350567Sbostic
3453813Smarc (void)time(&secs);
3553813Smarc if ((secs -= st.start) == 0)
3653813Smarc secs = 1;
3750567Sbostic /* Use snprintf(3) so that we don't reenter stdio(3). */
3856590Sbostic (void)snprintf(buf, sizeof(buf),
3959464Sbostic "%u+%u records in\n%u+%u records out\n",
4059464Sbostic st.in_full, st.in_part, st.out_full, st.out_part);
4156590Sbostic (void)write(STDERR_FILENO, buf, strlen(buf));
4250644Sbostic if (st.swab) {
4356590Sbostic (void)snprintf(buf, sizeof(buf), "%u odd length swab %s\n",
4450644Sbostic st.swab, (st.swab == 1) ? "block" : "blocks");
4556590Sbostic (void)write(STDERR_FILENO, buf, strlen(buf));
4650644Sbostic }
4750644Sbostic if (st.trunc) {
4856590Sbostic (void)snprintf(buf, sizeof(buf), "%u truncated %s\n",
4950644Sbostic st.trunc, (st.trunc == 1) ? "block" : "blocks");
5056590Sbostic (void)write(STDERR_FILENO, buf, strlen(buf));
5150567Sbostic }
5259464Sbostic (void)snprintf(buf, sizeof(buf),
5359464Sbostic "%u bytes transferred in %u secs (%u bytes/sec)\n",
5459464Sbostic st.bytes, secs, st.bytes / secs);
5559464Sbostic (void)write(STDERR_FILENO, buf, strlen(buf));
5650567Sbostic }
5750567Sbostic
5850567Sbostic /* ARGSUSED */
5950567Sbostic void
summaryx(notused)6066617Spendry summaryx(notused)
6150567Sbostic int notused;
6250567Sbostic {
6366617Spendry
6466617Spendry summary();
6550567Sbostic }
6650567Sbostic
6766617Spendry /* ARGSUSED */
6850567Sbostic void
terminate(notused)6966617Spendry terminate(notused)
7066617Spendry int notused;
7150567Sbostic {
7250567Sbostic
7366617Spendry exit(0);
7450567Sbostic }
75