4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
29 #include "thr_uberdata.h"
30 #include <sys/types.h>
40 /* Function exit/warning functions and global variables. */
42 const char *__progname
; /* GNU/Linux/BSD compatibility */
44 #define PROGNAMESIZE 128 /* buffer size for __progname */
53 setprogname(const char *argv0
)
55 uberdata_t
*udp
= curthread
->ul_uberdata
;
58 if ((progname
= strrchr(argv0
, '/')) == NULL
)
63 if (udp
->progname
== NULL
)
64 udp
->progname
= lmalloc(PROGNAMESIZE
);
65 (void) strlcpy(udp
->progname
, progname
, PROGNAMESIZE
);
66 __progname
= udp
->progname
;
69 /* called only from libc_init() */
76 if (dlinfo(RTLD_SELF
, RTLD_DI_ARGSINFO
, &args
) < 0 ||
78 (argv0
= args
.dla_argv
[0]) == NULL
)
85 * warncore() is the workhorse of these functions. Everything else has
86 * a warncore() component in it.
89 warncore(FILE *fp
, const char *fmt
, va_list args
)
95 if (__progname
!= NULL
)
96 (void) fprintf(fp
, "%s: ", __progname
);
99 (void) vfprintf(fp
, fmt
, args
);
105 /* Finish a warning with a newline and a flush of stderr. */
107 warnfinish(FILE *fp
, rmutex_t
*lk
)
109 (void) fputc('\n', fp
);
115 _vwarnxfp(FILE *fp
, const char *fmt
, va_list args
)
119 lk
= warncore(fp
, fmt
, args
);
124 vwarnx(const char *fmt
, va_list args
)
126 _vwarnxfp(stderr
, fmt
, args
);
130 _vwarnfp(FILE *fp
, const char *fmt
, va_list args
)
132 int tmperr
= errno
; /* Capture errno now. */
135 lk
= warncore(fp
, fmt
, args
);
137 (void) fputc(':', fp
);
138 (void) fputc(' ', fp
);
140 (void) fputs(strerror(tmperr
), fp
);
145 vwarn(const char *fmt
, va_list args
)
147 _vwarnfp(stderr
, fmt
, args
);
152 warnx(const char *fmt
, ...)
162 _warnfp(FILE *fp
, const char *fmt
, ...)
167 _vwarnfp(fp
, fmt
, args
);
172 _warnxfp(FILE *fp
, const char *fmt
, ...)
177 _vwarnxfp(fp
, fmt
, args
);
183 warn(const char *fmt
, ...)
194 err(int status
, const char *fmt
, ...)
205 _errfp(FILE *fp
, int status
, const char *fmt
, ...)
210 _vwarnfp(fp
, fmt
, args
);
216 verr(int status
, const char *fmt
, va_list args
)
223 _verrfp(FILE *fp
, int status
, const char *fmt
, va_list args
)
225 _vwarnfp(fp
, fmt
, args
);
231 errx(int status
, const char *fmt
, ...)
242 _errxfp(FILE *fp
, int status
, const char *fmt
, ...)
247 _vwarnxfp(fp
, fmt
, args
);
253 verrx(int status
, const char *fmt
, va_list args
)
260 _verrxfp(FILE *fp
, int status
, const char *fmt
, va_list args
)
262 _vwarnxfp(fp
, fmt
, args
);