Path: blob/main/cddl/contrib/opensolaris/cmd/mdb/tools/common/die.c
39537 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License, Version 1.0 only5* (the "License"). You may not use this file except in compliance6* with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or http://www.opensolaris.org/os/licensing.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/21/*22* Copyright 2004 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/2526#pragma ident "%Z%%M% %I% %E% SMI"2728#include <stdio.h>29#include <stdlib.h>30#include <stdarg.h>31#include <string.h>32#include <errno.h>33#include <elf.h>3435#include <util.h>3637void38die(char *format, ...)39{40va_list ap;41int err = errno;42#ifndef illumos43const char *progname = getprogname();44#endif4546(void) fprintf(stderr, "%s: ", progname);4748va_start(ap, format);49/* LINTED - variable format specifier */50(void) vfprintf(stderr, format, ap);51va_end(ap);5253if (format[strlen(format) - 1] != '\n')54(void) fprintf(stderr, ": %s\n", strerror(err));5556#ifndef illumos57exit(0);58#else59exit(1);60#endif61}6263void64elfdie(char *format, ...)65{66va_list ap;67#ifndef illumos68const char *progname = getprogname();69#endif7071(void) fprintf(stderr, "%s: ", progname);7273va_start(ap, format);74/* LINTED - variable format specifier */75(void) vfprintf(stderr, format, ap);76va_end(ap);7778if (format[strlen(format) - 1] != '\n')79(void) fprintf(stderr, ": %s\n", elf_errmsg(elf_errno()));8081#ifndef illumos82exit(0);83#else84exit(1);85#endif86}878889