Commit | Line | Data |
---|---|---|
bdd2e02f KB |
1 | /*- |
2 | * Copyright (c) 1991 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
6 | */ | |
7 | ||
8 | #ifndef lint | |
9 | static char sccsid[] = "@(#)misc.c 5.1 (Berkeley) %G%"; | |
10 | #endif /* not lint */ | |
11 | ||
12 | #include <fcntl.h> | |
13 | #include <errno.h> | |
14 | #include <unistd.h> | |
15 | #include <stdio.h> | |
16 | #include <stdlib.h> | |
17 | #include <string.h> | |
18 | #include "extern.h" | |
19 | ||
20 | void | |
21 | cat(file) | |
22 | char *file; | |
23 | { | |
24 | register int fd, nr, nw; | |
25 | char buf[1024]; | |
26 | ||
27 | if ((fd = open(file, O_RDONLY, 0)) < 0) | |
28 | err("%s: %s", file, strerror(errno)); | |
29 | ||
30 | while ((nr = read(fd, buf, sizeof(buf))) > 0) | |
31 | if ((nw = write(STDERR_FILENO, buf, nr)) == -1) | |
32 | err("write to stderr: %s", strerror(errno)); | |
33 | if (nr != 0) | |
34 | err("%s: %s", file, strerror(errno)); | |
35 | (void)close(fd); | |
36 | } | |
37 | ||
38 | void | |
39 | outc(c) | |
40 | int c; | |
41 | { | |
42 | (void)putc(c, stderr); | |
43 | } | |
44 | ||
45 | #if __STDC__ | |
46 | #include <stdarg.h> | |
47 | #else | |
48 | #include <varargs.h> | |
49 | #endif | |
50 | ||
51 | void | |
52 | #if __STDC__ | |
53 | err(const char *fmt, ...) | |
54 | #else | |
55 | err(fmt, va_alist) | |
56 | char *fmt; | |
57 | va_dcl | |
58 | #endif | |
59 | { | |
60 | va_list ap; | |
61 | #if __STDC__ | |
62 | va_start(ap, fmt); | |
63 | #else | |
64 | va_start(ap); | |
65 | #endif | |
66 | (void)fprintf(stderr, "tset: "); | |
67 | (void)vfprintf(stderr, fmt, ap); | |
68 | va_end(ap); | |
69 | (void)fprintf(stderr, "\n"); | |
70 | exit(1); | |
71 | /* NOTREACHED */ | |
72 | } |