1d192f3d3SKai Wang /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3be72428eSEd Maste *
4d192f3d3SKai Wang * Copyright (c) 2003-2007 Tim Kientzle
5d192f3d3SKai Wang * All rights reserved.
6d192f3d3SKai Wang *
7d192f3d3SKai Wang * Redistribution and use in source and binary forms, with or without
8d192f3d3SKai Wang * modification, are permitted provided that the following conditions
9d192f3d3SKai Wang * are met:
10d192f3d3SKai Wang * 1. Redistributions of source code must retain the above copyright
11be72428eSEd Maste * notice, this list of conditions and the following disclaimer.
12d192f3d3SKai Wang * 2. Redistributions in binary form must reproduce the above copyright
13d192f3d3SKai Wang * notice, this list of conditions and the following disclaimer in the
14d192f3d3SKai Wang * documentation and/or other materials provided with the distribution.
15d192f3d3SKai Wang *
16be72428eSEd Maste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17be72428eSEd Maste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18be72428eSEd Maste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19be72428eSEd Maste * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20be72428eSEd Maste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21be72428eSEd Maste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22be72428eSEd Maste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23be72428eSEd Maste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24be72428eSEd Maste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25be72428eSEd Maste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26be72428eSEd Maste * SUCH DAMAGE.
27d192f3d3SKai Wang */
28d192f3d3SKai Wang
29d192f3d3SKai Wang #include <sys/cdefs.h>
30d192f3d3SKai Wang #include <sys/queue.h>
31d192f3d3SKai Wang #include <sys/types.h>
32821df508SXin LI #include <errno.h>
33d192f3d3SKai Wang #include <stdarg.h>
34d192f3d3SKai Wang #include <stdio.h>
35d192f3d3SKai Wang #include <stdlib.h>
36d192f3d3SKai Wang #include <string.h>
37d192f3d3SKai Wang
38d192f3d3SKai Wang #include "ar.h"
39d192f3d3SKai Wang
40d192f3d3SKai Wang static void bsdar_vwarnc(struct bsdar *, int code,
41d192f3d3SKai Wang const char *fmt, va_list ap);
42d192f3d3SKai Wang static void bsdar_verrc(struct bsdar *bsdar, int code,
43d192f3d3SKai Wang const char *fmt, va_list ap);
44d192f3d3SKai Wang
45d192f3d3SKai Wang static void
bsdar_vwarnc(struct bsdar * bsdar,int code,const char * fmt,va_list ap)46d192f3d3SKai Wang bsdar_vwarnc(struct bsdar *bsdar, int code, const char *fmt, va_list ap)
47d192f3d3SKai Wang {
48d192f3d3SKai Wang
49d192f3d3SKai Wang fprintf(stderr, "%s: warning: ", bsdar->progname);
50d192f3d3SKai Wang vfprintf(stderr, fmt, ap);
51d192f3d3SKai Wang if (code != 0)
52d192f3d3SKai Wang fprintf(stderr, ": %s", strerror(code));
53d192f3d3SKai Wang fprintf(stderr, "\n");
54d192f3d3SKai Wang }
55d192f3d3SKai Wang
56d192f3d3SKai Wang void
bsdar_warnc(struct bsdar * bsdar,int code,const char * fmt,...)57d192f3d3SKai Wang bsdar_warnc(struct bsdar *bsdar, int code, const char *fmt, ...)
58d192f3d3SKai Wang {
59d192f3d3SKai Wang va_list ap;
60d192f3d3SKai Wang
61d192f3d3SKai Wang va_start(ap, fmt);
62d192f3d3SKai Wang bsdar_vwarnc(bsdar, code, fmt, ap);
63d192f3d3SKai Wang va_end(ap);
64d192f3d3SKai Wang }
65d192f3d3SKai Wang
66d192f3d3SKai Wang static void
bsdar_verrc(struct bsdar * bsdar,int code,const char * fmt,va_list ap)67d192f3d3SKai Wang bsdar_verrc(struct bsdar *bsdar, int code, const char *fmt, va_list ap)
68d192f3d3SKai Wang {
69d192f3d3SKai Wang
70d192f3d3SKai Wang fprintf(stderr, "%s: fatal: ", bsdar->progname);
71d192f3d3SKai Wang vfprintf(stderr, fmt, ap);
72d192f3d3SKai Wang if (code != 0)
73d192f3d3SKai Wang fprintf(stderr, ": %s", strerror(code));
74d192f3d3SKai Wang fprintf(stderr, "\n");
75d192f3d3SKai Wang }
76d192f3d3SKai Wang
77d192f3d3SKai Wang void
bsdar_errc(struct bsdar * bsdar,int code,const char * fmt,...)78086f0908SEd Maste bsdar_errc(struct bsdar *bsdar, int code, const char *fmt, ...)
79d192f3d3SKai Wang {
80d192f3d3SKai Wang va_list ap;
81d192f3d3SKai Wang
82d192f3d3SKai Wang va_start(ap, fmt);
83d192f3d3SKai Wang bsdar_verrc(bsdar, code, fmt, ap);
84d192f3d3SKai Wang va_end(ap);
85086f0908SEd Maste exit(EXIT_FAILURE);
86d192f3d3SKai Wang }
87