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
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.
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
29 #include "libuutil_common.h"
41 static const char PNAME_FMT[] = "%s: ";
42 static const char ERRNO_FMT[] = ": %s\n";
44 static const char *pname;
47 uu_die_internal(int status, const char *format, va_list alist) __NORETURN;
49 int uu_exit_ok_value = EXIT_SUCCESS;
50 int uu_exit_fatal_value = EXIT_FAILURE;
51 int uu_exit_usage_value = 2;
56 return (&uu_exit_ok_value);
62 return (&uu_exit_fatal_value);
68 return (&uu_exit_usage_value);
72 uu_alt_exit(int profile)
75 case UU_PROFILE_DEFAULT:
76 uu_exit_ok_value = EXIT_SUCCESS;
77 uu_exit_fatal_value = EXIT_FAILURE;
78 uu_exit_usage_value = 2;
80 case UU_PROFILE_LAUNCHER:
81 uu_exit_ok_value = EXIT_SUCCESS;
82 uu_exit_fatal_value = 124;
83 uu_exit_usage_value = 125;
89 uu_warn_internal(int err, const char *format, va_list alist)
92 (void) fprintf(stderr, PNAME_FMT, pname);
94 (void) vfprintf(stderr, format, alist);
96 if (strrchr(format, '\n') == NULL)
97 (void) fprintf(stderr, ERRNO_FMT, strerror(err));
101 uu_vwarn(const char *format, va_list alist)
103 uu_warn_internal(errno, format, alist);
108 uu_warn(const char *format, ...)
111 va_start(alist, format);
112 uu_warn_internal(errno, format, alist);
117 uu_die_internal(int status, const char *format, va_list alist)
119 uu_warn_internal(errno, format, alist);
125 cp = getenv("UU_DIE_ABORTS");
126 if (cp != NULL && *cp != '\0')
135 uu_vdie(const char *format, va_list alist)
137 uu_die_internal(UU_EXIT_FATAL, format, alist);
142 uu_die(const char *format, ...)
145 va_start(alist, format);
146 uu_die_internal(UU_EXIT_FATAL, format, alist);
151 uu_vxdie(int status, const char *format, va_list alist)
153 uu_die_internal(status, format, alist);
158 uu_xdie(int status, const char *format, ...)
161 va_start(alist, format);
162 uu_die_internal(status, format, alist);
167 uu_setpname(char *arg0)
170 * Having a NULL argv[0], while uncommon, is possible. It
171 * makes more sense to handle this event in uu_setpname rather
172 * than in each of its consumers.
175 pname = getexecname();
177 pname = "unknown_command";
182 * Guard against '/' at end of command invocation.
185 char *p = strrchr(arg0, '/');
190 if (*(p + 1) == '\0') {