16310ef27SDarren Tucker /*
26310ef27SDarren Tucker  * Copyright (c) 2015 Tim Rice <tim@multitalents.net>
36310ef27SDarren Tucker  *
46310ef27SDarren Tucker  * Redistribution and use in source and binary forms, with or without
56310ef27SDarren Tucker  * modification, are permitted provided that the following conditions
66310ef27SDarren Tucker  * are met:
76310ef27SDarren Tucker  *
86310ef27SDarren Tucker  * 1. Redistributions of source code must retain the above copyright
96310ef27SDarren Tucker  *   notice, this list of conditions and the following disclaimer.
106310ef27SDarren Tucker  * 2. Redistributions in binary form must reproduce the above copyright
116310ef27SDarren Tucker  *   notice, this list of conditions and the following disclaimer in the
126310ef27SDarren Tucker  *   documentation and/or other materials provided with the distribution.
136310ef27SDarren Tucker  * 3. The name of the author may not be used to endorse or promote products
146310ef27SDarren Tucker  *   derived from this software without specific prior written permission.
156310ef27SDarren Tucker  *
166310ef27SDarren Tucker  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
176310ef27SDarren Tucker  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
186310ef27SDarren Tucker  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
196310ef27SDarren Tucker  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
206310ef27SDarren Tucker  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
216310ef27SDarren Tucker  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
226310ef27SDarren Tucker  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236310ef27SDarren Tucker  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246310ef27SDarren Tucker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
256310ef27SDarren Tucker  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266310ef27SDarren Tucker  */
276310ef27SDarren Tucker 
286310ef27SDarren Tucker #include "includes.h"
296310ef27SDarren Tucker 
30*f5e917abSDarren Tucker #include <errno.h>
31*f5e917abSDarren Tucker #include <stdarg.h>
32*f5e917abSDarren Tucker #include <stdio.h>
33*f5e917abSDarren Tucker #include <stdlib.h>
34*f5e917abSDarren Tucker #include <string.h>
35*f5e917abSDarren Tucker 
366310ef27SDarren Tucker #ifndef HAVE_ERR
376310ef27SDarren Tucker void
err(int r,const char * fmt,...)386310ef27SDarren Tucker err(int r, const char *fmt, ...)
396310ef27SDarren Tucker {
406310ef27SDarren Tucker 	va_list args;
416310ef27SDarren Tucker 
426310ef27SDarren Tucker 	va_start(args, fmt);
436310ef27SDarren Tucker 	fprintf(stderr, "%s: ", strerror(errno));
446310ef27SDarren Tucker 	vfprintf(stderr, fmt, args);
456310ef27SDarren Tucker 	fputc('\n', stderr);
466310ef27SDarren Tucker 	va_end(args);
476310ef27SDarren Tucker 	exit(r);
486310ef27SDarren Tucker }
496310ef27SDarren Tucker #endif
506310ef27SDarren Tucker 
516310ef27SDarren Tucker #ifndef HAVE_ERRX
526310ef27SDarren Tucker void
errx(int r,const char * fmt,...)536310ef27SDarren Tucker errx(int r, const char *fmt, ...)
546310ef27SDarren Tucker {
556310ef27SDarren Tucker 	va_list args;
566310ef27SDarren Tucker 
576310ef27SDarren Tucker 	va_start(args, fmt);
586310ef27SDarren Tucker 	vfprintf(stderr, fmt, args);
596310ef27SDarren Tucker 	fputc('\n', stderr);
606310ef27SDarren Tucker 	va_end(args);
616310ef27SDarren Tucker 	exit(r);
626310ef27SDarren Tucker }
636310ef27SDarren Tucker #endif
646310ef27SDarren Tucker 
656310ef27SDarren Tucker #ifndef HAVE_WARN
666310ef27SDarren Tucker void
warn(const char * fmt,...)676310ef27SDarren Tucker warn(const char *fmt, ...)
686310ef27SDarren Tucker {
696310ef27SDarren Tucker 	va_list args;
706310ef27SDarren Tucker 
716310ef27SDarren Tucker 	va_start(args, fmt);
726310ef27SDarren Tucker 	fprintf(stderr, "%s: ", strerror(errno));
736310ef27SDarren Tucker 	vfprintf(stderr, fmt, args);
746310ef27SDarren Tucker 	fputc('\n', stderr);
756310ef27SDarren Tucker 	va_end(args);
766310ef27SDarren Tucker }
776310ef27SDarren Tucker #endif
78