err.c revision 228753
1258231Sgjb/*-
219304Speter * Copyright (c) 2003-2007 Tim Kientzle
3258231Sgjb * All rights reserved.
4254225Speter *
5254225Speter * Redistribution and use in source and binary forms, with or without
619304Speter * modification, are permitted provided that the following conditions
7254225Speter * are met:
819304Speter * 1. Redistributions of source code must retain the above copyright
9254225Speter *    notice, this list of conditions and the following disclaimer
10254225Speter *    in this position and unchanged.
11254225Speter * 2. Redistributions in binary form must reproduce the above copyright
12254225Speter *    notice, this list of conditions and the following disclaimer in the
13254225Speter *    documentation and/or other materials provided with the distribution.
14254225Speter *
15254225Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16254225Speter * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17254225Speter * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18254225Speter * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
1919304Speter * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20254225Speter * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2119304Speter * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22254225Speter * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2319304Speter * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24254225Speter * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2519304Speter */
26254225Speter
27254225Speter#include "lafe_platform.h"
28254225Speter__FBSDID("$FreeBSD$");
29254225Speter
30254225Speter#ifdef HAVE_STDARG_H
3119304Speter#include <stdarg.h>
3219304Speter#endif
3319304Speter#include <stdio.h>
3419304Speter#ifdef HAVE_STDLIB_H
3519304Speter#include <stdlib.h>
3619304Speter#endif
3719304Speter#ifdef HAVE_STRING_H
3819304Speter#include <string.h>
3919304Speter#endif
4019304Speter
4119304Speter#include "err.h"
4219304Speter
4319304Speterconst char *lafe_progname;
4419304Speter
4519304Speterstatic void
4619304Speterlafe_vwarnc(int code, const char *fmt, va_list ap)
4719304Speter{
4819304Speter	fprintf(stderr, "%s: ", lafe_progname);
4919304Speter	vfprintf(stderr, fmt, ap);
5019304Speter	if (code != 0)
5119304Speter		fprintf(stderr, ": %s", strerror(code));
5219304Speter	fprintf(stderr, "\n");
5319304Speter}
5419304Speter
5519304Spetervoid
5619304Speterlafe_warnc(int code, const char *fmt, ...)
5719304Speter{
5819304Speter	va_list ap;
5919304Speter
6019304Speter	va_start(ap, fmt);
6119304Speter	lafe_vwarnc(code, fmt, ap);
6219304Speter	va_end(ap);
6319304Speter}
6419304Speter
6519304Spetervoid
6619304Speterlafe_errc(int eval, int code, const char *fmt, ...)
67{
68	va_list ap;
69
70	va_start(ap, fmt);
71	lafe_vwarnc(code, fmt, ap);
72	va_end(ap);
73	exit(eval);
74}
75