1178481Sjb/*
2178481Sjb * CDDL HEADER START
3178481Sjb *
4178481Sjb * The contents of this file are subject to the terms of the
5178481Sjb * Common Development and Distribution License, Version 1.0 only
6178481Sjb * (the "License").  You may not use this file except in compliance
7178481Sjb * with the License.
8178481Sjb *
9178481Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10178481Sjb * or http://www.opensolaris.org/os/licensing.
11178481Sjb * See the License for the specific language governing permissions
12178481Sjb * and limitations under the License.
13178481Sjb *
14178481Sjb * When distributing Covered Code, include this CDDL HEADER in each
15178481Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16178481Sjb * If applicable, add the following below this CDDL HEADER, with the
17178481Sjb * fields enclosed by brackets "[]" replaced with your own identifying
18178481Sjb * information: Portions Copyright [yyyy] [name of copyright owner]
19178481Sjb *
20178481Sjb * CDDL HEADER END
21178481Sjb */
22178481Sjb/*
23178481Sjb * Copyright (c) 1998-2001 by Sun Microsystems, Inc.
24178481Sjb * All rights reserved.
25178481Sjb */
26178481Sjb
27178481Sjb#pragma ident	"%Z%%M%	%I%	%E% SMI"
28178481Sjb
29178481Sjb#include <string.h>
30178481Sjb#include <stdlib.h>
31178481Sjb#include <stdarg.h>
32178481Sjb#include <stdio.h>
33178481Sjb#include <errno.h>
34178481Sjb
35178481Sjb#include "utils.h"
36178481Sjb
37178481Sjb/*LINTLIBRARY*/
38178481Sjb
39178481Sjbstatic const char *pname;
40178481Sjb
41178481Sjb#pragma init(getpname)
42178481Sjbconst char *
43178481Sjbgetpname(void)
44178481Sjb{
45178481Sjb	const char *p, *q;
46178481Sjb
47178481Sjb	if (pname != NULL)
48178481Sjb		return (pname);
49178481Sjb
50178481Sjb	if ((p = getexecname()) != NULL)
51178481Sjb		q = strrchr(p, '/');
52178481Sjb	else
53178481Sjb		q = NULL;
54178481Sjb
55178481Sjb	if (q == NULL)
56178481Sjb		pname = p;
57178481Sjb	else
58178481Sjb		pname = q + 1;
59178481Sjb
60178481Sjb	return (pname);
61178481Sjb}
62178481Sjb
63178481Sjbvoid
64178481Sjbvwarn(const char *format, va_list alist)
65178481Sjb{
66178481Sjb	int err = errno;
67178481Sjb
68178481Sjb	if (pname != NULL)
69178481Sjb		(void) fprintf(stderr, "%s: ", pname);
70178481Sjb
71178481Sjb	(void) vfprintf(stderr, format, alist);
72178481Sjb
73178481Sjb	if (strchr(format, '\n') == NULL)
74178481Sjb		(void) fprintf(stderr, ": %s\n", strerror(err));
75178481Sjb}
76178481Sjb
77178481Sjb/*PRINTFLIKE1*/
78178481Sjbvoid
79178481Sjbwarn(const char *format, ...)
80178481Sjb{
81178481Sjb	va_list alist;
82178481Sjb
83178481Sjb	va_start(alist, format);
84178481Sjb	vwarn(format, alist);
85178481Sjb	va_end(alist);
86178481Sjb}
87178481Sjb
88178481Sjbvoid
89178481Sjbvdie(const char *format, va_list alist)
90178481Sjb{
91178481Sjb	vwarn(format, alist);
92178481Sjb	exit(E_ERROR);
93178481Sjb}
94178481Sjb
95178481Sjb/*PRINTFLIKE1*/
96178481Sjbvoid
97178481Sjbdie(const char *format, ...)
98178481Sjb{
99178481Sjb	va_list alist;
100178481Sjb
101178481Sjb	va_start(alist, format);
102178481Sjb	vdie(format, alist);
103178481Sjb	va_end(alist);
104178481Sjb}
105