Path: blob/main/contrib/libarchive/libarchive_fe/err.c
39536 views
/*-1* Copyright (c) 2003-2007 Tim Kientzle2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer9* in this position and unchanged.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include "lafe_platform.h"27#ifdef HAVE_STDARG_H28#include <stdarg.h>29#endif30#include <stdio.h>31#ifdef HAVE_STDLIB_H32#include <stdlib.h>33#endif34#ifdef HAVE_STRING_H35#include <string.h>36#endif3738#include "err.h"3940static void lafe_vwarnc(int, const char *, va_list) __LA_PRINTFLIKE(2, 0);4142static const char *lafe_progname;4344const char *45lafe_getprogname(void)46{4748return lafe_progname;49}5051void52lafe_setprogname(const char *name, const char *defaultname)53{5455if (name == NULL)56name = defaultname;57#if defined(_WIN32) && !defined(__CYGWIN__)58lafe_progname = strrchr(name, '\\');59if (strrchr(name, '/') > lafe_progname)60#endif61lafe_progname = strrchr(name, '/');62if (lafe_progname != NULL)63lafe_progname++;64else65lafe_progname = name;66}6768static void69lafe_vwarnc(int code, const char *fmt, va_list ap)70{71fprintf(stderr, "%s: ", lafe_progname);72vfprintf(stderr, fmt, ap);73if (code != 0)74fprintf(stderr, ": %s", strerror(code));75fprintf(stderr, "\n");76}7778void79lafe_warnc(int code, const char *fmt, ...)80{81va_list ap;8283va_start(ap, fmt);84lafe_vwarnc(code, fmt, ap);85va_end(ap);86}8788void89lafe_errc(int eval, int code, const char *fmt, ...)90{91va_list ap;9293va_start(ap, fmt);94lafe_vwarnc(code, fmt, ap);95va_end(ap);96exit(eval);97}9899100