9103 opengroup acknowledgement should be properly formatted in man pages
[unleashed.git] / usr / src / man / man3c / err.3c
bloba82cca4a1bae789733c3c0883f2544a0658f2da2
1 '\" te
2 .\" Copyright 2014 Nexenta Systems, Inc.  All Rights Reserved.
3 .\" Copyright (c) 1996-2001 Wolfram Schneider. Berlin.
4 .\" Copyright (c) 1993-1995 Berkeley Software Design, Inc.
5 .\" Portions Copyright (c) 2007, Sun Microsystems, Inc.  All Rights Reserved.
6 .\" 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.
7 .\" 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.
8 .\" 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]
9 .TH ERR 3C "Nov 24, 2014"
10 .SH NAME
11 err, verr, errx, verrx, warn, vwarn, warnx, vwarnx \- formatted error messages
12 .SH SYNOPSIS
13 .LP
14 .nf
15 #include <err.h>
17 \fBvoid\fR \fBerr\fR(\fBint\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, ...);
18 .fi
20 .LP
21 .nf
22 \fBvoid\fR \fBverr\fR(\fBint\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR);
23 .fi
25 .LP
26 .nf
27 \fBvoid\fR \fBerrx\fR(\fBint\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, ...);
28 .fi
30 .LP
31 .nf
32 \fBvoid\fR \fBverrx\fR\fB(int\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR);
33 .fi
35 .LP
36 .nf
37 \fBvoid\fR \fBwarn\fR(\fBconst char *\fR\fIfmt\fR, ...);
38 .fi
40 .LP
41 .nf
42 \fBvoid\fR \fBvwarn\fR(\fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR);
43 .fi
45 .LP
46 .nf
47 \fBvoid\fR \fBwarnx\fR(\fBconst char *\fR\fIfmt\fR, ...);
48 .fi
50 .LP
51 .nf
52 \fBvoid\fR \fBvwarnx\fR(\fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR);
53 .fi
55 .SH DESCRIPTION
56 .LP
57 The \fBerr()\fR and \fBwarn()\fR family of functions display a formatted error
58 message on the standard error output. In all cases, the last component of the
59 program name, followed by a colon character and a space, are output. If the
60 \fIfmt\fR argument is not \fINULL\fR, the formatted error message is output. In
61 the case of the \fBerr()\fR, \fBverr()\fR, \fBwarn()\fR, and \fBvwarn()\fR
62 functions, the error message string affiliated with the current value of the
63 global variable \fBerrno\fR is output next, preceded by a colon character and a
64 space if \fIfmt\fR is not \fINULL\fR. In all cases, the output is followed by a
65 newline character.  The \fBerrx()\fR, \fBverrx()\fR, \fBwarnx()\fR, and
66 \fBvwarnx()\fR functions will not output this error message string.
67 .sp
68 .LP
69 The \fBerr()\fR, \fBverr()\fR, \fBerrx()\fR, and \fBverrx()\fR functions do not
70 return, but instead cause the program to terminate with the status value given
71 by the argument \fIeval\fR.
72 .SH EXAMPLES
73 .LP
74 \fBExample 1 \fRDisplay the current \fBerrno\fR information string and
75 terminate with status indicating failure.
76 .sp
77 .in +2
78 .nf
79 if ((p = malloc(size)) == NULL)
80     err(EXIT_FAILURE, NULL);
81 if ((fd = open(file_name, O_RDONLY, 0)) == -1)
82     err(EXIT_FAILURE, "%s", file_name);
83 .fi
84 .in -2
86 .LP
87 \fBExample 2 \fRDisplay an error message and terminate with status indicating
88 failure.
89 .sp
90 .in +2
91 .nf
92 if (tm.tm_hour < START_TIME)
93     errx(EXIT_FAILURE, "too early, wait until %s", start_time_string);
94 .fi
95 .in -2
97 .LP
98 \fBExample 3 \fRWarn of an error.
99 .sp
100 .in +2
102 if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
103     warnx("%s: %s: trying the block device",
104         raw_device, strerror(errno));
105 if ((fd = open(block_device, O_RDONLY, 0)) == -1)
106     warn("%s", block_device);
108 .in -2
110 .SH WARNINGS
112 It is important never to pass a string with user-supplied data as a format
113 without using `%s'. An attacker can put format specifiers in the string to
114 mangle the stack, leading to a possible security hole. This holds true even if
115 the string has been built ``by hand'' using a function like \fBsnprintf\fR(3C),
116 as the resulting string can still contain user-supplied conversion specifiers
117 for later interpolation by the \fBerr()\fR and \fBwarn()\fR functions.
120 Always be sure to use the proper secure idiom:
122 .in +2
124 err(1, "%s", string);
126 .in -2
128 .SH ATTRIBUTES
130 See \fBattributes\fR(5) for descriptions of the following attributes:
135 box;
136 c | c
137 l | l .
138 ATTRIBUTE TYPE  ATTRIBUTE VALUE
140 Interface Stability     Committed
142 MT-Level        Safe with Exceptions
147 These functions are safe to use in multithreaded applications as long as
148 \fBsetlocale\fR(3C) is not being called to change the locale.
149 .SH SEE ALSO
151 \fBexit\fR(3C), \fBgetexecname\fR(3C), \fBsetlocale\fR(3C), \fBstrerror\fR(3C),
152 \fBattributes\fR(5)