1295367Sdes/*- 257429Smarkm * Copyright (c) 2003-2007 Tim Kientzle 357429Smarkm * All rights reserved. 457429Smarkm * 557429Smarkm * Redistribution and use in source and binary forms, with or without 657429Smarkm * modification, are permitted provided that the following conditions 757429Smarkm * are met: 857429Smarkm * 1. Redistributions of source code must retain the above copyright 960576Skris * notice, this list of conditions and the following disclaimer 1065674Skris * in this position and unchanged. 1165674Skris * 2. Redistributions in binary form must reproduce the above copyright 1265674Skris * notice, this list of conditions and the following disclaimer in the 1365674Skris * documentation and/or other materials provided with the distribution. 1465674Skris * 1557429Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 1657429Smarkm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1757429Smarkm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1857429Smarkm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19295367Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20295367Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21162856Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22162856Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23162856Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2476262Sgreen * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2576262Sgreen */ 26162856Sdes 27162856Sdes#include <sys/cdefs.h> 28162856Sdes__FBSDID("$FreeBSD$"); 29162856Sdes 30162856Sdes#include <sys/queue.h> 31162856Sdes#include <sys/types.h> 3257429Smarkm#include <errno.h> 3357429Smarkm#include <stdarg.h> 3476262Sgreen#include <stdio.h> 3557429Smarkm#include <stdlib.h> 3658585Skris#include <string.h> 37162856Sdes 3876262Sgreen#include "ar.h" 3976262Sgreen 40295367Sdesstatic void bsdar_vwarnc(struct bsdar *, int code, 4157429Smarkm const char *fmt, va_list ap); 42162856Sdesstatic void bsdar_verrc(struct bsdar *bsdar, int code, 43215116Sdes const char *fmt, va_list ap); 44162856Sdes 4576262Sgreenstatic void 46162856Sdesbsdar_vwarnc(struct bsdar *bsdar, int code, const char *fmt, va_list ap) 47162856Sdes{ 48162856Sdes 4998684Sdes fprintf(stderr, "%s: warning: ", bsdar->progname); 5098684Sdes vfprintf(stderr, fmt, ap); 5157429Smarkm if (code != 0) 52264377Sdes fprintf(stderr, ": %s", strerror(code)); 53264377Sdes fprintf(stderr, "\n"); 5469591Sgreen} 5569591Sgreen 5669591Sgreenvoid 5757429Smarkmbsdar_warnc(struct bsdar *bsdar, int code, const char *fmt, ...) 5857429Smarkm{ 5957429Smarkm va_list ap; 6057429Smarkm 6176262Sgreen va_start(ap, fmt); 6257429Smarkm bsdar_vwarnc(bsdar, code, fmt, ap); 6357429Smarkm va_end(ap); 6457429Smarkm} 6557429Smarkm 6657429Smarkmstatic void 6757429Smarkmbsdar_verrc(struct bsdar *bsdar, int code, const char *fmt, va_list ap) 6857429Smarkm{ 69147005Sdes 7057429Smarkm fprintf(stderr, "%s: fatal: ", bsdar->progname); 7157429Smarkm vfprintf(stderr, fmt, ap); 7257429Smarkm if (code != 0) 7398684Sdes fprintf(stderr, ": %s", strerror(code)); 7498684Sdes fprintf(stderr, "\n"); 7598684Sdes} 7698684Sdes 7798684Sdesvoid 7898684Sdesbsdar_errc(struct bsdar *bsdar, int eval, int code, const char *fmt, ...) 7998684Sdes{ 8098684Sdes va_list ap; 8198684Sdes 82164149Sdes va_start(ap, fmt); 83164149Sdes bsdar_verrc(bsdar, code, fmt, ap); 8498684Sdes va_end(ap); 85164149Sdes exit(eval); 86164149Sdes} 87164149Sdes