die.c revision 302408
138451Smsmith/*
238451Smsmith * CDDL HEADER START
338451Smsmith *
438451Smsmith * The contents of this file are subject to the terms of the
538451Smsmith * Common Development and Distribution License, Version 1.0 only
638451Smsmith * (the "License").  You may not use this file except in compliance
738451Smsmith * with the License.
838451Smsmith *
938451Smsmith * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1038451Smsmith * or http://www.opensolaris.org/os/licensing.
1138451Smsmith * See the License for the specific language governing permissions
1238451Smsmith * and limitations under the License.
1338451Smsmith *
1438451Smsmith * When distributing Covered Code, include this CDDL HEADER in each
1538451Smsmith * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1638451Smsmith * If applicable, add the following below this CDDL HEADER, with the
1738451Smsmith * fields enclosed by brackets "[]" replaced with your own identifying
1838451Smsmith * information: Portions Copyright [yyyy] [name of copyright owner]
1938451Smsmith *
2038451Smsmith * CDDL HEADER END
2138451Smsmith */
2238451Smsmith/*
2338451Smsmith * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
2438451Smsmith * Use is subject to license terms.
2538451Smsmith */
2638451Smsmith
2738451Smsmith#pragma ident	"%Z%%M%	%I%	%E% SMI"
2838451Smsmith
2938451Smsmith#include <stdio.h>
3038451Smsmith#include <stdlib.h>
3138451Smsmith#include <stdarg.h>
3238451Smsmith#include <string.h>
3338451Smsmith#include <errno.h>
3484221Sdillon#include <elf.h>
3584221Sdillon
3684221Sdillon#include <util.h>
3738451Smsmith
3838451Smsmithvoid
3938451Smsmithdie(char *format, ...)
4038451Smsmith{
4138451Smsmith	va_list ap;
4238451Smsmith	int err = errno;
4338451Smsmith#ifndef illumos
4438451Smsmith	const char *progname = getprogname();
4538451Smsmith#endif
4638451Smsmith
4738451Smsmith	(void) fprintf(stderr, "%s: ", progname);
4838451Smsmith
4938451Smsmith	va_start(ap, format);
5038451Smsmith	/* LINTED - variable format specifier */
5138451Smsmith	(void) vfprintf(stderr, format, ap);
5238451Smsmith	va_end(ap);
5338451Smsmith
5438451Smsmith	if (format[strlen(format) - 1] != '\n')
5538451Smsmith		(void) fprintf(stderr, ": %s\n", strerror(err));
5638451Smsmith
5738451Smsmith#ifndef illumos
5838451Smsmith	exit(0);
5938451Smsmith#else
6038451Smsmith	exit(1);
6138451Smsmith#endif
6238451Smsmith}
63223124Srodrigc
64223124Srodrigcvoid
6539468Smsmithelfdie(char *format, ...)
6638451Smsmith{
67223488Srodrigc	va_list ap;
6838451Smsmith#ifndef illumos
6938451Smsmith	const char *progname = getprogname();
7038451Smsmith#endif
71223124Srodrigc
7238451Smsmith	(void) fprintf(stderr, "%s: ", progname);
73223488Srodrigc
74223124Srodrigc	va_start(ap, format);
75223124Srodrigc	/* LINTED - variable format specifier */
76223124Srodrigc	(void) vfprintf(stderr, format, ap);
77223124Srodrigc	va_end(ap);
7838451Smsmith
7938451Smsmith	if (format[strlen(format) - 1] != '\n')
8059766Sjlemon		(void) fprintf(stderr, ": %s\n", elf_errmsg(elf_errno()));
8159766Sjlemon
8259766Sjlemon#ifndef illumos
8359766Sjlemon	exit(0);
8459766Sjlemon#else
8559766Sjlemon	exit(1);
8659766Sjlemon#endif
8759766Sjlemon}
8838451Smsmith