1176434Skaiw/*-
2176434Skaiw * Copyright (c) 2003-2007 Tim Kientzle
3176434Skaiw * All rights reserved.
4176434Skaiw *
5176434Skaiw * Redistribution and use in source and binary forms, with or without
6176434Skaiw * modification, are permitted provided that the following conditions
7176434Skaiw * are met:
8176434Skaiw * 1. Redistributions of source code must retain the above copyright
9176434Skaiw *    notice, this list of conditions and the following disclaimer
10176434Skaiw *    in this position and unchanged.
11176434Skaiw * 2. Redistributions in binary form must reproduce the above copyright
12176434Skaiw *    notice, this list of conditions and the following disclaimer in the
13176434Skaiw *    documentation and/or other materials provided with the distribution.
14176434Skaiw *
15176434Skaiw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16176434Skaiw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17176434Skaiw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18176434Skaiw * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19176434Skaiw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20176434Skaiw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21176434Skaiw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22176434Skaiw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23176434Skaiw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24176434Skaiw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25176434Skaiw */
26176434Skaiw
27176434Skaiw#include <sys/cdefs.h>
28176434Skaiw__FBSDID("$FreeBSD$");
29176434Skaiw
30176434Skaiw#include <sys/queue.h>
31176434Skaiw#include <sys/types.h>
32200462Sdelphij#include <errno.h>
33176434Skaiw#include <stdarg.h>
34176434Skaiw#include <stdio.h>
35176434Skaiw#include <stdlib.h>
36176434Skaiw#include <string.h>
37176434Skaiw
38176434Skaiw#include "ar.h"
39176434Skaiw
40176434Skaiwstatic void	bsdar_vwarnc(struct bsdar *, int code,
41176434Skaiw		    const char *fmt, va_list ap);
42176434Skaiwstatic void	bsdar_verrc(struct bsdar *bsdar, int code,
43176434Skaiw		    const char *fmt, va_list ap);
44176434Skaiw
45176434Skaiwstatic void
46176434Skaiwbsdar_vwarnc(struct bsdar *bsdar, int code, const char *fmt, va_list ap)
47176434Skaiw{
48176434Skaiw
49176434Skaiw	fprintf(stderr, "%s: warning: ", bsdar->progname);
50176434Skaiw	vfprintf(stderr, fmt, ap);
51176434Skaiw	if (code != 0)
52176434Skaiw		fprintf(stderr, ": %s", strerror(code));
53176434Skaiw	fprintf(stderr, "\n");
54176434Skaiw}
55176434Skaiw
56176434Skaiwvoid
57176434Skaiwbsdar_warnc(struct bsdar *bsdar, int code, const char *fmt, ...)
58176434Skaiw{
59176434Skaiw	va_list ap;
60176434Skaiw
61176434Skaiw	va_start(ap, fmt);
62176434Skaiw	bsdar_vwarnc(bsdar, code, fmt, ap);
63176434Skaiw	va_end(ap);
64176434Skaiw}
65176434Skaiw
66176434Skaiwstatic void
67176434Skaiwbsdar_verrc(struct bsdar *bsdar, int code, const char *fmt, va_list ap)
68176434Skaiw{
69176434Skaiw
70176434Skaiw	fprintf(stderr, "%s: fatal: ", bsdar->progname);
71176434Skaiw	vfprintf(stderr, fmt, ap);
72176434Skaiw	if (code != 0)
73176434Skaiw		fprintf(stderr, ": %s", strerror(code));
74176434Skaiw	fprintf(stderr, "\n");
75176434Skaiw}
76176434Skaiw
77176434Skaiwvoid
78176434Skaiwbsdar_errc(struct bsdar *bsdar, int eval, int code, const char *fmt, ...)
79176434Skaiw{
80176434Skaiw	va_list ap;
81176434Skaiw
82176434Skaiw	va_start(ap, fmt);
83176434Skaiw	bsdar_verrc(bsdar, code, fmt, ap);
84176434Skaiw	va_end(ap);
85176434Skaiw	exit(eval);
86176434Skaiw}
87