broken up into multiple modules -- rewrite lots of it, reorganize the
[unix-history] / usr / src / usr.bin / tset / misc.c
CommitLineData
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
9static 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
20void
21cat(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
38void
39outc(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
51void
52#if __STDC__
53err(const char *fmt, ...)
54#else
55err(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}