150567Sbostic /*- 250567Sbostic * Copyright (c) 1991 The Regents of the University of California. 350567Sbostic * 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*50644Sbostic static char sccsid[] = "@(#)misc.c 5.3 (Berkeley) 07/29/91"; 1450567Sbostic #endif /* not lint */ 1550567Sbostic 1650567Sbostic #include <sys/types.h> 1750567Sbostic #include <unistd.h> 1850567Sbostic #include <stdlib.h> 1950567Sbostic #include <stdio.h> 2050567Sbostic #include "dd.h" 2150567Sbostic #include "extern.h" 2250567Sbostic 2350567Sbostic /* ARGSUSED */ 2450567Sbostic void 2550567Sbostic summary(notused) 2650567Sbostic int notused; 2750567Sbostic { 2850567Sbostic int len; 2950567Sbostic char buf[100]; 3050567Sbostic 3150567Sbostic /* Use snprintf(3) so that we don't reenter stdio(3). */ 3250567Sbostic len = snprintf(buf, sizeof(buf), 3350567Sbostic "%u+%u records in\n%u+%u records out\n", 34*50644Sbostic st.in_full, st.in_part, st.out_full, st.out_part); 3550567Sbostic (void)write(STDERR_FILENO, buf, len); 36*50644Sbostic if (st.swab) { 37*50644Sbostic len = snprintf(buf, sizeof(buf), "%u odd length swab %s\n", 38*50644Sbostic st.swab, (st.swab == 1) ? "block" : "blocks"); 39*50644Sbostic (void)write(STDERR_FILENO, buf, len); 40*50644Sbostic } 41*50644Sbostic if (st.trunc) { 4250567Sbostic len = snprintf(buf, sizeof(buf), "%u truncated %s\n", 43*50644Sbostic st.trunc, (st.trunc == 1) ? "block" : "blocks"); 4450567Sbostic (void)write(STDERR_FILENO, buf, len); 4550567Sbostic } 4650567Sbostic } 4750567Sbostic 4850567Sbostic /* ARGSUSED */ 4950567Sbostic void 5050567Sbostic terminate(notused) 5150567Sbostic int notused; 5250567Sbostic { 5350567Sbostic summary(0); 5450567Sbostic exit(0); 5550567Sbostic } 5650567Sbostic 5750567Sbostic #if __STDC__ 5850567Sbostic #include <stdarg.h> 5950567Sbostic #else 6050567Sbostic #include <varargs.h> 6150567Sbostic #endif 6250567Sbostic 6350567Sbostic void 6450567Sbostic #if __STDC__ 6550567Sbostic err(const char *fmt, ...) 6650567Sbostic #else 6750567Sbostic err(fmt, va_alist) 6850567Sbostic char *fmt; 6950567Sbostic va_dcl 7050567Sbostic #endif 7150567Sbostic { 7250567Sbostic va_list ap; 7350567Sbostic #if __STDC__ 7450567Sbostic va_start(ap, fmt); 7550567Sbostic #else 7650567Sbostic va_start(ap); 7750567Sbostic #endif 7850567Sbostic (void)fprintf(stderr, "dd: "); 7950567Sbostic (void)vfprintf(stderr, fmt, ap); 8050567Sbostic va_end(ap); 8150567Sbostic (void)fprintf(stderr, "\n"); 8250567Sbostic exit(1); 8350567Sbostic /* NOTREACHED */ 8450567Sbostic } 8550567Sbostic 8650567Sbostic void 8750567Sbostic #if __STDC__ 8850567Sbostic warn(const char *fmt, ...) 8950567Sbostic #else 9050567Sbostic warn(fmt, va_alist) 9150567Sbostic char *fmt; 9250567Sbostic va_dcl 9350567Sbostic #endif 9450567Sbostic { 9550567Sbostic va_list ap; 9650567Sbostic #if __STDC__ 9750567Sbostic va_start(ap, fmt); 9850567Sbostic #else 9950567Sbostic va_start(ap); 10050567Sbostic #endif 10150567Sbostic (void)fprintf(stderr, "dd: "); 10250567Sbostic (void)vfprintf(stderr, fmt, ap); 10350567Sbostic va_end(ap); 10450567Sbostic (void)fprintf(stderr, "\n"); 10550567Sbostic } 106