1aa97860fSglass /*-
2ae646d0eSjtc * Copyright (c) 1991, 1993
3ae646d0eSjtc * The Regents of the University of California. All rights reserved.
4aa97860fSglass *
5aa97860fSglass * This code is derived from software contributed to Berkeley by
6aa97860fSglass * Edward Sze-Tyan Wang.
7aa97860fSglass *
8aa97860fSglass * Redistribution and use in source and binary forms, with or without
9aa97860fSglass * modification, are permitted provided that the following conditions
10aa97860fSglass * are met:
11aa97860fSglass * 1. Redistributions of source code must retain the above copyright
12aa97860fSglass * notice, this list of conditions and the following disclaimer.
13aa97860fSglass * 2. Redistributions in binary form must reproduce the above copyright
14aa97860fSglass * notice, this list of conditions and the following disclaimer in the
15aa97860fSglass * documentation and/or other materials provided with the distribution.
1689aaa1bbSagc * 3. Neither the name of the University nor the names of its contributors
17aa97860fSglass * may be used to endorse or promote products derived from this software
18aa97860fSglass * without specific prior written permission.
19aa97860fSglass *
20aa97860fSglass * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21aa97860fSglass * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22aa97860fSglass * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23aa97860fSglass * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24aa97860fSglass * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25aa97860fSglass * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26aa97860fSglass * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27aa97860fSglass * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28aa97860fSglass * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29aa97860fSglass * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30aa97860fSglass * SUCH DAMAGE.
31aa97860fSglass */
32aa97860fSglass
33079884daSlukem #include <sys/cdefs.h>
34aa97860fSglass #ifndef lint
35ae646d0eSjtc #if 0
36ae646d0eSjtc static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93";
37ae646d0eSjtc #endif
38*56b933f4Schristos __RCSID("$NetBSD: misc.c,v 1.7 2011/09/03 09:02:20 christos Exp $");
39aa97860fSglass #endif /* not lint */
40aa97860fSglass
41aa97860fSglass #include <sys/types.h>
42aa97860fSglass #include <sys/stat.h>
43aa97860fSglass #include <errno.h>
443c4c9d2bSwiz #include <stdarg.h>
45aa97860fSglass #include <stdio.h>
46aa97860fSglass #include <stdlib.h>
47aa97860fSglass #include <string.h>
483c4c9d2bSwiz #include <unistd.h>
49*56b933f4Schristos #include <err.h>
503c4c9d2bSwiz
51aa97860fSglass #include "extern.h"
52aa97860fSglass
53aa97860fSglass void
ierr(void)543c4c9d2bSwiz ierr(void)
55aa97860fSglass {
56*56b933f4Schristos xerr(0, "%s", fname);
57aa97860fSglass }
58aa97860fSglass
59aa97860fSglass void
oerr(void)603c4c9d2bSwiz oerr(void)
61aa97860fSglass {
62*56b933f4Schristos xerr(1, "stdout");
63aa97860fSglass }
64aa97860fSglass
65aa97860fSglass void
xerr(int fatal,const char * fmt,...)66*56b933f4Schristos xerr(int fatal, const char *fmt, ...)
67aa97860fSglass {
68aa97860fSglass va_list ap;
693c4c9d2bSwiz
70aa97860fSglass va_start(ap, fmt);
71*56b933f4Schristos vwarn(fmt, ap);
72aa97860fSglass va_end(ap);
73*56b933f4Schristos if (fatal)
74*56b933f4Schristos exit(1);
75*56b933f4Schristos rval = 1;
76*56b933f4Schristos }
77*56b933f4Schristos
78*56b933f4Schristos void
xerrx(int fatal,const char * fmt,...)79*56b933f4Schristos xerrx(int fatal, const char *fmt, ...)
80*56b933f4Schristos {
81*56b933f4Schristos va_list ap;
82*56b933f4Schristos
83*56b933f4Schristos va_start(ap, fmt);
84*56b933f4Schristos vwarnx(fmt, ap);
85*56b933f4Schristos va_end(ap);
86ae646d0eSjtc if (fatal)
87aa97860fSglass exit(1);
88ae646d0eSjtc rval = 1;
89aa97860fSglass }
90