1d876124dSJohn Birrell /*
2d876124dSJohn Birrell * CDDL HEADER START
3d876124dSJohn Birrell *
4d876124dSJohn Birrell * The contents of this file are subject to the terms of the
5d876124dSJohn Birrell * Common Development and Distribution License, Version 1.0 only
6d876124dSJohn Birrell * (the "License"). You may not use this file except in compliance
7d876124dSJohn Birrell * with the License.
8d876124dSJohn Birrell *
9d876124dSJohn Birrell * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d876124dSJohn Birrell * or http://www.opensolaris.org/os/licensing.
11d876124dSJohn Birrell * See the License for the specific language governing permissions
12d876124dSJohn Birrell * and limitations under the License.
13d876124dSJohn Birrell *
14d876124dSJohn Birrell * When distributing Covered Code, include this CDDL HEADER in each
15d876124dSJohn Birrell * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16d876124dSJohn Birrell * If applicable, add the following below this CDDL HEADER, with the
17d876124dSJohn Birrell * fields enclosed by brackets "[]" replaced with your own identifying
18d876124dSJohn Birrell * information: Portions Copyright [yyyy] [name of copyright owner]
19d876124dSJohn Birrell *
20d876124dSJohn Birrell * CDDL HEADER END
21d876124dSJohn Birrell */
22d876124dSJohn Birrell /*
23d876124dSJohn Birrell * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24d876124dSJohn Birrell * Use is subject to license terms.
25d876124dSJohn Birrell */
26d876124dSJohn Birrell
27d876124dSJohn Birrell #pragma ident "%Z%%M% %I% %E% SMI"
28d876124dSJohn Birrell
29d876124dSJohn Birrell #include <stdio.h>
30d876124dSJohn Birrell #include <stdlib.h>
31d876124dSJohn Birrell #include <stdarg.h>
32d876124dSJohn Birrell #include <string.h>
33d876124dSJohn Birrell #include <errno.h>
34d876124dSJohn Birrell #include <elf.h>
35d876124dSJohn Birrell
36d876124dSJohn Birrell #include <util.h>
37d876124dSJohn Birrell
38d876124dSJohn Birrell void
die(char * format,...)39d876124dSJohn Birrell die(char *format, ...)
40d876124dSJohn Birrell {
41d876124dSJohn Birrell va_list ap;
42d876124dSJohn Birrell int err = errno;
43*bc96366cSSteven Hartland #ifndef illumos
449f1fe401SJohn Birrell const char *progname = getprogname();
459f1fe401SJohn Birrell #endif
46d876124dSJohn Birrell
47d876124dSJohn Birrell (void) fprintf(stderr, "%s: ", progname);
48d876124dSJohn Birrell
49d876124dSJohn Birrell va_start(ap, format);
50d876124dSJohn Birrell /* LINTED - variable format specifier */
51d876124dSJohn Birrell (void) vfprintf(stderr, format, ap);
52d876124dSJohn Birrell va_end(ap);
53d876124dSJohn Birrell
54d876124dSJohn Birrell if (format[strlen(format) - 1] != '\n')
55d876124dSJohn Birrell (void) fprintf(stderr, ": %s\n", strerror(err));
56d876124dSJohn Birrell
57*bc96366cSSteven Hartland #ifndef illumos
589f1fe401SJohn Birrell exit(0);
599f1fe401SJohn Birrell #else
60d876124dSJohn Birrell exit(1);
619f1fe401SJohn Birrell #endif
62d876124dSJohn Birrell }
63d876124dSJohn Birrell
64d876124dSJohn Birrell void
elfdie(char * format,...)65d876124dSJohn Birrell elfdie(char *format, ...)
66d876124dSJohn Birrell {
67d876124dSJohn Birrell va_list ap;
68*bc96366cSSteven Hartland #ifndef illumos
699f1fe401SJohn Birrell const char *progname = getprogname();
709f1fe401SJohn Birrell #endif
71d876124dSJohn Birrell
72d876124dSJohn Birrell (void) fprintf(stderr, "%s: ", progname);
73d876124dSJohn Birrell
74d876124dSJohn Birrell va_start(ap, format);
75d876124dSJohn Birrell /* LINTED - variable format specifier */
76d876124dSJohn Birrell (void) vfprintf(stderr, format, ap);
77d876124dSJohn Birrell va_end(ap);
78d876124dSJohn Birrell
79d876124dSJohn Birrell if (format[strlen(format) - 1] != '\n')
80d876124dSJohn Birrell (void) fprintf(stderr, ": %s\n", elf_errmsg(elf_errno()));
81d876124dSJohn Birrell
82*bc96366cSSteven Hartland #ifndef illumos
839f1fe401SJohn Birrell exit(0);
849f1fe401SJohn Birrell #else
85d876124dSJohn Birrell exit(1);
869f1fe401SJohn Birrell #endif
87d876124dSJohn Birrell }
88