10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
54891Svk199839 * Common Development and Distribution License (the "License").
64891Svk199839 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*13093SRoger.Faulkner@Oracle.COM
220Sstevel@tonic-gate /*
23*13093SRoger.Faulkner@Oracle.COM * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/param.h>
270Sstevel@tonic-gate #include <libintl.h>
280Sstevel@tonic-gate #include <string.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <stdarg.h>
310Sstevel@tonic-gate #include <stdio.h>
320Sstevel@tonic-gate #include <errno.h>
330Sstevel@tonic-gate
340Sstevel@tonic-gate #include "utils.h"
350Sstevel@tonic-gate
360Sstevel@tonic-gate static char PNAME_FMT[] = "%s: ";
370Sstevel@tonic-gate static char ERRNO_FMT[] = ": %s\n";
380Sstevel@tonic-gate
390Sstevel@tonic-gate static char *pname;
400Sstevel@tonic-gate
410Sstevel@tonic-gate /*PRINTFLIKE1*/
420Sstevel@tonic-gate void
warn(const char * format,...)434891Svk199839 warn(const char *format, ...)
440Sstevel@tonic-gate {
450Sstevel@tonic-gate int err = errno;
460Sstevel@tonic-gate va_list alist;
470Sstevel@tonic-gate if (pname != NULL)
480Sstevel@tonic-gate (void) fprintf(stderr, gettext(PNAME_FMT), pname);
490Sstevel@tonic-gate va_start(alist, format);
500Sstevel@tonic-gate (void) vfprintf(stderr, format, alist);
510Sstevel@tonic-gate va_end(alist);
520Sstevel@tonic-gate if (strchr(format, '\n') == NULL)
530Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERRNO_FMT), strerror(err));
540Sstevel@tonic-gate }
550Sstevel@tonic-gate
560Sstevel@tonic-gate /*PRINTFLIKE1*/
570Sstevel@tonic-gate void
die(char * format,...)580Sstevel@tonic-gate die(char *format, ...)
590Sstevel@tonic-gate {
600Sstevel@tonic-gate int err = errno;
610Sstevel@tonic-gate va_list alist;
620Sstevel@tonic-gate
630Sstevel@tonic-gate if (pname != NULL)
640Sstevel@tonic-gate (void) fprintf(stderr, gettext(PNAME_FMT), pname);
650Sstevel@tonic-gate va_start(alist, format);
660Sstevel@tonic-gate (void) vfprintf(stderr, format, alist);
670Sstevel@tonic-gate va_end(alist);
680Sstevel@tonic-gate if (strchr(format, '\n') == NULL)
690Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERRNO_FMT), strerror(err));
700Sstevel@tonic-gate exit(E_ERROR);
710Sstevel@tonic-gate }
720Sstevel@tonic-gate
730Sstevel@tonic-gate char *
setpname(char * arg0)74*13093SRoger.Faulkner@Oracle.COM setpname(char *arg0)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate char *p = strrchr(arg0, '/');
770Sstevel@tonic-gate
780Sstevel@tonic-gate if (p == NULL)
790Sstevel@tonic-gate p = arg0;
800Sstevel@tonic-gate else
810Sstevel@tonic-gate p++;
820Sstevel@tonic-gate pname = p;
830Sstevel@tonic-gate return (pname);
840Sstevel@tonic-gate }
85