'\" te .\" Copyright (c) 1996-2001 Wolfram Schneider. Berlin. .\" Copyright (c) 1993-1995 Berkeley Software Design, Inc. .\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .TH ERR 3C "Aug 20, 2007" .SH NAME err, verr, errx, verrx, warn, vwarn, warnx, vwarnx \- formatted error messages .SH SYNOPSIS .LP .nf #include \fBvoid\fR \fBerr\fR(\fBint\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, ...); .fi .LP .nf \fBvoid\fR \fBverr\fR(\fBint\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR); .fi .LP .nf \fBvoid\fR \fBerrx\fR(\fBint\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, ...); .fi .LP .nf \fBvoid\fR \fBverrx\fR\fB(int\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR); .fi .LP .nf \fBvoid\fR \fBwarn\fR(\fBconst char *\fR\fIfmt\fR, ...); .fi .LP .nf \fBvoid\fR \fBvwarn\fR(\fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR); .fi .LP .nf \fBvoid\fR \fBwarnx\fR(\fBconst char *\fR\fIfmt\fR, ...); .fi .LP .nf \fBvoid\fR \fBvwarnx\fR(\fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR); .fi .SH DESCRIPTION .sp .LP The \fBerr()\fR and \fBwarn()\fR family of functions display a formatted error message on the standard error output. In all cases, the last component of the program name, followed by a colon character and a space, are output. If the \fIfmt\fR argument is not \fINULL\fR, the formatted error message is output. In the case of the \fBerr()\fR, \fBverr()\fR, \fBwarn()\fR, and \fBvwarn()\fR functions, the error message string affiliated with the current value of the global variable \fBerrno\fR is output next, preceded by a colon character and a space if \fIfmt\fR is not \fINULL\fR. In all cases, the output is followed by a newline character. The \fBerrx()\fR, \fBverrx()\fR, \fBwarnx()\fR, and \fBvwarnx()\fR functions will not output this error message string. .sp .LP The \fBerr()\fR, \fBverr()\fR, \fBerrx()\fR, and \fBverrx()\fR functions do not return, but instead cause the program to terminate with the status value given by the argument status. .SH EXAMPLES .LP \fBExample 1 \fRDisplay the current \fBerrno\fR information string and terminate with status indicating failure. .sp .in +2 .nf if ((p = malloc(size)) == NULL) err(EXIT_FAILURE, NULL); if ((fd = open(file_name, O_RDONLY, 0)) == -1) err(EXIT_FAILURE, "%s", file_name); .fi .in -2 .LP \fBExample 2 \fRDisplay an error message and terminate with status indicating failure. .sp .in +2 .nf if (tm.tm_hour < START_TIME) errx(EXIT_FAILURE, "too early, wait until %s", start_time_string); .fi .in -2 .LP \fBExample 3 \fRWarn of an error. .sp .in +2 .nf if ((fd = open(raw_device, O_RDONLY, 0)) == -1) warnx("%s: %s: trying the block device", raw_device, strerror(errno)); if ((fd = open(block_device, O_RDONLY, 0)) == -1) warn("%s", block_device); .fi .in -2 .SH WARNINGS .sp .LP It is important never to pass a string with user-supplied data as a format without using `%s'. An attacker can put format specifiers in the string to mangle the stack, leading to a possible security hole. This holds true even if the string has been built ``by hand'' using a function like \fBsnprintf\fR(3C), as the resulting string can still contain user-supplied conversion specifiers for later interpolation by the \fBerr()\fR and \fBwarn()\fR functions. .sp .LP Always be sure to use the proper secure idiom: .sp .in +2 .nf err(1, "%s", string); .fi .in -2 .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS box; c | c l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed _ MT-Level Safe with Exceptions .TE .sp .LP These functions are safe to use in multithreaded applications as long as \fBsetlocale\fR(3C) is not being called to change the locale. .SH SEE ALSO .sp .LP \fBexit\fR(3C), \fBgetexecname\fR(3C), \fBsetlocale\fR(3C), \fBstrerror\fR(3C), \fBattributes\fR(5)