ANSI C; sprintf now returns an int.
[unix-history] / usr / src / libexec / bugfiler / error.c
CommitLineData
ecee9486
KB
1/*
2 * Copyright (c) 1986 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
36e21f76 8static char sccsid[] = "@(#)error.c 5.4 (Berkeley) 87/07/21";
ecee9486
KB
9#endif not lint
10
d8336336 11#include <bug.h>
ecee9486
KB
12#include <syslog.h>
13#include <stdio.h>
ecee9486
KB
14
15static short err_redir; /* stderr redirected */
16
17/*
18 * seterr --
19 * redirect stderr for error processing
20 */
21seterr()
22{
d8336336 23 if (!freopen(ERROR_FILE, "a", stderr))
36e21f76 24 error("can't open error file %s.", ERROR_FILE);
ecee9486
KB
25 err_redir = YES;
26}
27
28/*
29 * error --
30 * write errors to log file and die
31 */
d8336336
KB
32error(fmt, arg)
33 register char *fmt,
34 *arg;
ecee9486
KB
35{
36 static char logmsg[MAXLINELEN]; /* syslog message */
37 char *strcpy(), *strcat();
38
39 if (err_redir) {
40 /* don't combine these, "fmt" may not require "arg" */
36e21f76 41 fprintf(stderr, "\t%s\n\t", tmpname);
d8336336 42 fprintf(stderr, fmt, arg);
36e21f76 43 fputc('\n', stderr);
ecee9486
KB
44 }
45 else {
d8336336
KB
46 sprintf(logmsg, "bugfiler: %s", fmt);
47 syslog(LOG_ERR, logmsg, arg);
ecee9486 48 }
ecee9486
KB
49#ifdef METOO
50 exit(ERR);
d8336336 51#else
ecee9486 52 exit(OK);
d8336336 53#endif
ecee9486 54}