warnerr.c revision 72445
160484Sobrien/* 260484Sobrien * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska H�gskolan 3218822Sdim * (Royal Institute of Technology, Stockholm, Sweden). 489857Sobrien * All rights reserved. 560484Sobrien * 6130561Sobrien * Redistribution and use in source and binary forms, with or without 760484Sobrien * modification, are permitted provided that the following conditions 8130561Sobrien * are met: 9130561Sobrien * 10130561Sobrien * 1. Redistributions of source code must retain the above copyright 11130561Sobrien * notice, this list of conditions and the following disclaimer. 1260484Sobrien * 13130561Sobrien * 2. Redistributions in binary form must reproduce the above copyright 14130561Sobrien * notice, this list of conditions and the following disclaimer in the 15130561Sobrien * documentation and/or other materials provided with the distribution. 16130561Sobrien * 1760484Sobrien * 3. Neither the name of the Institute nor the names of its contributors 18130561Sobrien * may be used to endorse or promote products derived from this software 19130561Sobrien * without specific prior written permission. 20218822Sdim * 2160484Sobrien * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22218822Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2360484Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2489857Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 2560484Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2660484Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2760484Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2860484Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2960484Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3060484Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3160484Sobrien * SUCH DAMAGE. 3260484Sobrien */ 3360484Sobrien 3460484Sobrien#ifdef HAVE_CONFIG_H 3560484Sobrien#include <config.h> 3660484SobrienRCSID("$Id: warnerr.c,v 1.9 2000/07/25 09:54:05 joda Exp $"); 3760484Sobrien#endif 3860484Sobrien 39130561Sobrien#include "roken.h" 4060484Sobrien#include "err.h" 4160484Sobrien 4260484Sobrien#ifndef HAVE___PROGNAME 4360484Sobrienconst char *__progname; 4460484Sobrien#endif 4560484Sobrien 4660484Sobrienconst char * 4760484Sobrienget_progname(void) 4860484Sobrien{ 4960484Sobrien return __progname; 5060484Sobrien} 5160484Sobrien 5260484Sobrienvoid 5360484Sobrienset_progname(char *argv0) 5460484Sobrien{ 5560484Sobrien#ifndef HAVE___PROGNAME 5660484Sobrien char *p; 5760484Sobrien if(argv0 == NULL) 5860484Sobrien return; 5960484Sobrien p = strrchr(argv0, '/'); 6060484Sobrien if(p == NULL) 6160484Sobrien p = argv0; 6260484Sobrien else 6360484Sobrien p++; 6460484Sobrien __progname = p; 6560484Sobrien#endif 6660484Sobrien} 6760484Sobrien 68130561Sobrienvoid 69130561Sobrienwarnerr(int doerrno, const char *fmt, va_list ap) 7060484Sobrien{ 7160484Sobrien int sverrno = errno; 7260484Sobrien if(__progname != NULL){ 7360484Sobrien fprintf(stderr, "%s", __progname); 7460484Sobrien if(fmt != NULL || doerrno) 7560484Sobrien fprintf(stderr, ": "); 7660484Sobrien } 7760484Sobrien if (fmt != NULL){ 7860484Sobrien vfprintf(stderr, fmt, ap); 7960484Sobrien if(doerrno) 80130561Sobrien fprintf(stderr, ": "); 81130561Sobrien } 82130561Sobrien if(doerrno) 83130561Sobrien fprintf(stderr, "%s", strerror(sverrno)); 84130561Sobrien fprintf(stderr, "\n"); 85218822Sdim} 86130561Sobrien