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
;
43 static __attribute__((noreturn
)) void
44 uu_die_internal(int status
, const char *format
, va_list alist
);
46 int uu_exit_ok_value
= EXIT_SUCCESS
;
47 int uu_exit_fatal_value
= EXIT_FAILURE
;
48 int uu_exit_usage_value
= 2;
53 return (&uu_exit_ok_value
);
59 return (&uu_exit_fatal_value
);
65 return (&uu_exit_usage_value
);
69 uu_alt_exit(int profile
)
72 case UU_PROFILE_DEFAULT
:
73 uu_exit_ok_value
= EXIT_SUCCESS
;
74 uu_exit_fatal_value
= EXIT_FAILURE
;
75 uu_exit_usage_value
= 2;
77 case UU_PROFILE_LAUNCHER
:
78 uu_exit_ok_value
= EXIT_SUCCESS
;
79 uu_exit_fatal_value
= 124;
80 uu_exit_usage_value
= 125;
85 static __attribute__((format(printf
, 2, 0))) void
86 uu_warn_internal(int err
, const char *format
, va_list alist
)
89 (void) fprintf(stderr
, "%s: ", pname
);
92 (void) vfprintf(stderr
, format
, alist
);
94 if (strrchr(format
, '\n') == NULL
)
95 (void) fprintf(stderr
, ": %s\n", strerror(err
));
99 uu_vwarn(const char *format
, va_list alist
)
101 uu_warn_internal(errno
, format
, alist
);
105 uu_warn(const char *format
, ...)
108 va_start(alist
, format
);
109 uu_warn_internal(errno
, format
, alist
);
113 static __attribute__((format(printf
, 2, 0))) __attribute__((noreturn
)) void
114 uu_die_internal(int status
, const char *format
, va_list alist
)
116 uu_warn_internal(errno
, format
, alist
);
122 cp
= getenv("UU_DIE_ABORTS");
123 if (cp
!= NULL
&& *cp
!= '\0')
132 uu_vdie(const char *format
, va_list alist
)
134 uu_die_internal(UU_EXIT_FATAL
, format
, alist
);
138 uu_die(const char *format
, ...)
141 va_start(alist
, format
);
142 uu_die_internal(UU_EXIT_FATAL
, format
, alist
);
147 uu_vxdie(int status
, const char *format
, va_list alist
)
149 uu_die_internal(status
, format
, alist
);
153 uu_xdie(int status
, const char *format
, ...)
156 va_start(alist
, format
);
157 uu_die_internal(status
, format
, alist
);
162 uu_setpname(char *arg0
)
165 * Having a NULL argv[0], while uncommon, is possible. It
166 * makes more sense to handle this event in uu_setpname rather
167 * than in each of its consumers.
170 pname
= getexecname();
172 pname
= "unknown_command";
177 * Guard against '/' at end of command invocation.
180 char *p
= strrchr(arg0
, '/');
185 if (*(p
+ 1) == '\0') {