xref: /openbsd-src/usr.bin/dig/lib/isc/error.c (revision 9c5836fb5c83a5dcf5650ccdebf7279d15c834ed)
15185a700Sflorian /*
25185a700Sflorian  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
35185a700Sflorian  *
45185a700Sflorian  * Permission to use, copy, modify, and/or distribute this software for any
55185a700Sflorian  * purpose with or without fee is hereby granted, provided that the above
65185a700Sflorian  * copyright notice and this permission notice appear in all copies.
75185a700Sflorian  *
85185a700Sflorian  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
95185a700Sflorian  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
105185a700Sflorian  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
115185a700Sflorian  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
125185a700Sflorian  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
135185a700Sflorian  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
145185a700Sflorian  * PERFORMANCE OF THIS SOFTWARE.
155185a700Sflorian  */
165185a700Sflorian 
17*9c5836fbSflorian /* $Id: error.c,v 1.6 2020/09/12 07:19:59 florian Exp $ */
185185a700Sflorian 
195185a700Sflorian /*! \file */
205185a700Sflorian 
215185a700Sflorian #include <stdio.h>
225185a700Sflorian #include <stdlib.h>
235185a700Sflorian 
245185a700Sflorian #include <isc/error.h>
255185a700Sflorian 
265185a700Sflorian void
isc_error_unexpected(const char * file,int line,const char * format,...)275185a700Sflorian isc_error_unexpected(const char *file, int line, const char *format, ...) {
285185a700Sflorian 	va_list args;
295185a700Sflorian 
305185a700Sflorian 	va_start(args, format);
31*9c5836fbSflorian 	fprintf(stderr, "%s:%d: ", file, line);
32*9c5836fbSflorian 	vfprintf(stderr, format, args);
33*9c5836fbSflorian 	fprintf(stderr, "\n");
34*9c5836fbSflorian 	fflush(stderr);
355185a700Sflorian 	va_end(args);
365185a700Sflorian }
375185a700Sflorian 
385185a700Sflorian void
isc_error_fatal(const char * file,int line,const char * format,...)395185a700Sflorian isc_error_fatal(const char *file, int line, const char *format, ...) {
405185a700Sflorian 	va_list args;
415185a700Sflorian 
425185a700Sflorian 	va_start(args, format);
43*9c5836fbSflorian 	fprintf(stderr, "%s:%d: %s: ", file, line, "fatal error");
44*9c5836fbSflorian 	vfprintf(stderr, format, args);
45*9c5836fbSflorian 	fprintf(stderr, "\n");
46*9c5836fbSflorian 	fflush(stderr);
475185a700Sflorian 	va_end(args);
485185a700Sflorian 	abort();
495185a700Sflorian }
505185a700Sflorian 
515185a700Sflorian void
isc_error_runtimecheck(const char * file,int line,const char * expression)525185a700Sflorian isc_error_runtimecheck(const char *file, int line, const char *expression) {
535185a700Sflorian 	isc_error_fatal(file, line, "RUNTIME_CHECK(%s) %s", expression,
545185a700Sflorian 				       "failed");
555185a700Sflorian }
56