1294109Sbapt#include "config.h"
2294109Sbapt
3294109Sbapt#if HAVE_ERR
4294109Sbapt
5294109Sbaptint dummy;
6294109Sbapt
7294109Sbapt#else
8294109Sbapt
9294109Sbapt/* $Id: compat_err.c,v 1.4 2015/11/26 07:42:11 schwarze Exp $ */
10294109Sbapt/*
11294109Sbapt * Copyright (c) 1993
12294109Sbapt *      The Regents of the University of California.  All rights reserved.
13294109Sbapt *
14294109Sbapt * Redistribution and use in source and binary forms, with or without
15294109Sbapt * modification, are permitted provided that the following conditions
16294109Sbapt * are met:
17294109Sbapt * 1. Redistributions of source code must retain the above copyright
18294109Sbapt *    notice, this list of conditions and the following disclaimer.
19294109Sbapt * 2. Redistributions in binary form must reproduce the above copyright
20294109Sbapt *    notice, this list of conditions and the following disclaimer in the
21294109Sbapt *    documentation and/or other materials provided with the distribution.
22294109Sbapt * 3. Neither the name of the University nor the names of its contributors
23294109Sbapt *    may be used to endorse or promote products derived from this software
24294109Sbapt *    without specific prior written permission.
25294109Sbapt *
26294109Sbapt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27294109Sbapt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28294109Sbapt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29294109Sbapt * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30294109Sbapt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31294109Sbapt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32294109Sbapt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33294109Sbapt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34294109Sbapt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35294109Sbapt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36294109Sbapt * SUCH DAMAGE.
37294109Sbapt */
38294109Sbapt
39294109Sbapt#include <errno.h>
40294109Sbapt#include <stdarg.h>
41294109Sbapt#include <stdio.h>
42294109Sbapt#include <stdlib.h>
43294109Sbapt#include <string.h>
44294109Sbapt
45294109Sbaptstatic void vwarni(const char *, va_list);
46294109Sbaptstatic void vwarnxi(const char *, va_list);
47294109Sbapt
48294109Sbaptstatic void
49294109Sbaptvwarnxi(const char *fmt, va_list ap)
50294109Sbapt{
51294109Sbapt	fprintf(stderr, "%s: ", getprogname());
52294109Sbapt	if (fmt != NULL)
53294109Sbapt		vfprintf(stderr, fmt, ap);
54294109Sbapt}
55294109Sbapt
56294109Sbaptstatic void
57294109Sbaptvwarni(const char *fmt, va_list ap)
58294109Sbapt{
59294109Sbapt	int sverrno;
60294109Sbapt
61294109Sbapt	sverrno = errno;
62294109Sbapt	vwarnxi(fmt, ap);
63294109Sbapt	if (fmt != NULL)
64294109Sbapt		fputs(": ", stderr);
65294109Sbapt	fprintf(stderr, "%s\n", strerror(sverrno));
66294109Sbapt}
67294109Sbapt
68294109Sbaptvoid
69294109Sbapterr(int eval, const char *fmt, ...)
70294109Sbapt{
71294109Sbapt	va_list ap;
72294109Sbapt
73294109Sbapt	va_start(ap, fmt);
74294109Sbapt	vwarni(fmt, ap);
75294109Sbapt	va_end(ap);
76294109Sbapt	exit(eval);
77294109Sbapt}
78294109Sbapt
79294109Sbaptvoid
80294109Sbapterrx(int eval, const char *fmt, ...)
81294109Sbapt{
82294109Sbapt	va_list ap;
83294109Sbapt
84294109Sbapt	va_start(ap, fmt);
85294109Sbapt	vwarnxi(fmt, ap);
86294109Sbapt	va_end(ap);
87294109Sbapt	fputc('\n', stderr);
88294109Sbapt	exit(eval);
89294109Sbapt}
90294109Sbapt
91294109Sbaptvoid
92294109Sbaptwarn(const char *fmt, ...)
93294109Sbapt{
94294109Sbapt	va_list ap;
95294109Sbapt
96294109Sbapt	va_start(ap, fmt);
97294109Sbapt	vwarni(fmt, ap);
98294109Sbapt	va_end(ap);
99294109Sbapt}
100294109Sbapt
101294109Sbaptvoid
102294109Sbaptwarnx(const char *fmt, ...)
103294109Sbapt{
104294109Sbapt	va_list ap;
105294109Sbapt
106294109Sbapt	va_start(ap, fmt);
107294109Sbapt	vwarnxi(fmt, ap);
108294109Sbapt	va_end(ap);
109294109Sbapt	fputc('\n', stderr);
110294109Sbapt}
111294109Sbapt
112294109Sbapt#endif
113