xref: /minix3/external/bsd/libarchive/dist/libarchive_fe/err.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1543adbedSBen Gras /*-
2543adbedSBen Gras  * Copyright (c) 2003-2007 Tim Kientzle
3543adbedSBen Gras  * All rights reserved.
4543adbedSBen Gras  *
5543adbedSBen Gras  * Redistribution and use in source and binary forms, with or without
6543adbedSBen Gras  * modification, are permitted provided that the following conditions
7543adbedSBen Gras  * are met:
8543adbedSBen Gras  * 1. Redistributions of source code must retain the above copyright
9543adbedSBen Gras  *    notice, this list of conditions and the following disclaimer
10543adbedSBen Gras  *    in this position and unchanged.
11543adbedSBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
12543adbedSBen Gras  *    notice, this list of conditions and the following disclaimer in the
13543adbedSBen Gras  *    documentation and/or other materials provided with the distribution.
14543adbedSBen Gras  *
15543adbedSBen Gras  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16543adbedSBen Gras  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17543adbedSBen Gras  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18543adbedSBen Gras  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19543adbedSBen Gras  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20543adbedSBen Gras  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21543adbedSBen Gras  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22543adbedSBen Gras  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23543adbedSBen Gras  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24543adbedSBen Gras  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25543adbedSBen Gras  */
26543adbedSBen Gras 
27543adbedSBen Gras #include "lafe_platform.h"
28543adbedSBen Gras __FBSDID("$FreeBSD$");
29543adbedSBen Gras 
30543adbedSBen Gras #ifdef HAVE_STDARG_H
31543adbedSBen Gras #include <stdarg.h>
32543adbedSBen Gras #endif
33543adbedSBen Gras #include <stdio.h>
34543adbedSBen Gras #ifdef HAVE_STDLIB_H
35543adbedSBen Gras #include <stdlib.h>
36543adbedSBen Gras #endif
37543adbedSBen Gras #ifdef HAVE_STRING_H
38543adbedSBen Gras #include <string.h>
39543adbedSBen Gras #endif
40543adbedSBen Gras 
41543adbedSBen Gras #include "err.h"
42543adbedSBen Gras 
43543adbedSBen Gras const char *lafe_progname;
44543adbedSBen Gras 
45*0a6a1f1dSLionel Sambuc static __printflike(2, 0) void
lafe_vwarnc(int code,const char * fmt,va_list ap)46543adbedSBen Gras lafe_vwarnc(int code, const char *fmt, va_list ap)
47543adbedSBen Gras {
48543adbedSBen Gras 	fprintf(stderr, "%s: ", lafe_progname);
49543adbedSBen Gras 	vfprintf(stderr, fmt, ap);
50543adbedSBen Gras 	if (code != 0)
51543adbedSBen Gras 		fprintf(stderr, ": %s", strerror(code));
52543adbedSBen Gras 	fprintf(stderr, "\n");
53543adbedSBen Gras }
54543adbedSBen Gras 
55543adbedSBen Gras void
lafe_warnc(int code,const char * fmt,...)56543adbedSBen Gras lafe_warnc(int code, const char *fmt, ...)
57543adbedSBen Gras {
58543adbedSBen Gras 	va_list ap;
59543adbedSBen Gras 
60543adbedSBen Gras 	va_start(ap, fmt);
61543adbedSBen Gras 	lafe_vwarnc(code, fmt, ap);
62543adbedSBen Gras 	va_end(ap);
63543adbedSBen Gras }
64543adbedSBen Gras 
65543adbedSBen Gras void
lafe_errc(int eval,int code,const char * fmt,...)66543adbedSBen Gras lafe_errc(int eval, int code, const char *fmt, ...)
67543adbedSBen Gras {
68543adbedSBen Gras 	va_list ap;
69543adbedSBen Gras 
70543adbedSBen Gras 	va_start(ap, fmt);
71543adbedSBen Gras 	lafe_vwarnc(code, fmt, ap);
72543adbedSBen Gras 	va_end(ap);
73543adbedSBen Gras 	exit(eval);
74543adbedSBen Gras }
75