xref: /titanic_44/usr/src/cmd/ramdiskadm/utils.c (revision 5c51f1241dbbdf2656d0e10011981411ed0c9673)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/stat.h>
32 #include <sys/statvfs.h>
33 #include <sys/sysmacros.h>
34 #include <libintl.h>
35 #include <libgen.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include <stdarg.h>
39 #include <stdio.h>
40 #include <errno.h>
41 
42 #include "utils.h"
43 
44 static char *pname = NULL;
45 
46 /*PRINTFLIKE1*/
47 void
48 warn(const char *format, ...)
49 {
50 	int err = errno;
51 	va_list alist;
52 
53 	if (pname != NULL)
54 		(void) fprintf(stderr, gettext("%s: "), pname);
55 
56 	va_start(alist, format);
57 	(void) vfprintf(stderr, format, alist);
58 	va_end(alist);
59 
60 	if (strchr(format, '\n') == NULL)
61 		(void) fprintf(stderr, gettext(": %s\n"), strerror(err));
62 }
63 
64 /*PRINTFLIKE1*/
65 void
66 die(const char *format, ...)
67 {
68 	int err = errno;
69 	va_list alist;
70 
71 	if (pname != NULL)
72 		(void) fprintf(stderr, gettext("%s: "), pname);
73 
74 	va_start(alist, format);
75 	(void) vfprintf(stderr, format, alist);
76 	va_end(alist);
77 
78 	if (strchr(format, '\n') == NULL)
79 		(void) fprintf(stderr, gettext(": %s\n"), strerror(err));
80 
81 	exit(E_ERROR);
82 }
83 
84 char *
85 getpname(char *arg0)
86 {
87 	if (pname == NULL)
88 		pname = basename(arg0);
89 	return (pname);
90 }
91