add Lance Visser to contrib list
[unix-history] / usr / src / bin / dd / misc.c
CommitLineData
c7961ddb
KB
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
a08a4cd0
KB
6 * Keith Muller of the University of California, San Diego and Lance
7 * Visser of Convex Computer Corporation.
c7961ddb
KB
8 *
9 * %sccs.include.redist.c%
10 */
11
12#ifndef lint
a08a4cd0 13static char sccsid[] = "@(#)misc.c 5.2 (Berkeley) %G%";
c7961ddb
KB
14#endif /* not lint */
15
16#include <sys/types.h>
17#include <unistd.h>
18#include <stdlib.h>
19#include <stdio.h>
20#include "dd.h"
21#include "extern.h"
22
23/* ARGSUSED */
24void
25summary(notused)
26 int notused;
27{
28 int len;
29 char buf[100];
30
31 /* Use snprintf(3) so that we don't reenter stdio(3). */
32 len = snprintf(buf, sizeof(buf),
33 "%u+%u records in\n%u+%u records out\n",
34 in.f_stats, in.p_stats, out.f_stats, out.p_stats);
35 (void)write(STDERR_FILENO, buf, len);
36 if (in.t_stats) {
37 len = snprintf(buf, sizeof(buf), "%u truncated %s\n",
38 in.t_stats, (in.t_stats == 1) ? "block" : "blocks");
39 (void)write(STDERR_FILENO, buf, len);
40 }
41}
42
43/* ARGSUSED */
44void
45terminate(notused)
46 int notused;
47{
48 summary(0);
49 exit(0);
50}
51
52#if __STDC__
53#include <stdarg.h>
54#else
55#include <varargs.h>
56#endif
57
58void
59#if __STDC__
60err(const char *fmt, ...)
61#else
62err(fmt, va_alist)
63 char *fmt;
64 va_dcl
65#endif
66{
67 va_list ap;
68#if __STDC__
69 va_start(ap, fmt);
70#else
71 va_start(ap);
72#endif
73 (void)fprintf(stderr, "dd: ");
74 (void)vfprintf(stderr, fmt, ap);
75 va_end(ap);
76 (void)fprintf(stderr, "\n");
77 exit(1);
78 /* NOTREACHED */
79}
80
81void
82#if __STDC__
83warn(const char *fmt, ...)
84#else
85warn(fmt, va_alist)
86 char *fmt;
87 va_dcl
88#endif
89{
90 va_list ap;
91#if __STDC__
92 va_start(ap, fmt);
93#else
94 va_start(ap);
95#endif
96 (void)fprintf(stderr, "dd: ");
97 (void)vfprintf(stderr, fmt, ap);
98 va_end(ap);
99 (void)fprintf(stderr, "\n");
100}