gno/usr.man/man3/err.3

149 lines
4.3 KiB
Groff

.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93
.\" $Id: err.3,v 1.1 1997/02/27 07:32:21 gdr Exp $
.\"
.TH ERR 3 "April 13, 1995" GNO "Library Routines"
.SH NAME
.BR err ,
.BR verr ,
.BR errx ,
.BR verrx ,
.BR warn ,
.BR vwarn ,
.BR warnx ,
.BR vwarnx ,
.BR err_set_file ,
.BR err_set_exit
\- formatted error messages
.SH SYNOPSIS
.nf
#include <err.h>
void err (int \fIeval\fR, const char *\fIfmt\fR, ...);
void verr (int \fIeval\fR, const char *\fIfmt\fR, va_list \fIargs\fR);
void errx (int \fIeval\fR, const char *\fIfmt\fR, ...);
void verrx (int \fIeval\fR, const char *\fIfmt\fR, va_list \fIargs\fR);
void warn (const char *\fIfmt\fR, ...);
void vwarn (const char *\fIfmt\fR, va_list \fIargs\fR);
void warnx (const char *\fIfmt\fR, ...);
void vwarnx (const char *\fIfmt\fR, va_list \fIargs\fR);
void err_set_file (void *\fIfp\fR);
void err_set_exit (void (*\fIexitf\fR)(int));
.fi
.SH DESCRIPTION
The
.BR err
and
.BR warn
family of functions display a formatted error message on the standard
error output, or on another file specified using the
.BR err_set_file
function.
In all cases, the last component of the program name, a colon character,
and a space are output.
If the
.IR fmt
argument is not NULL, the formatted error message, a colon character,
and a space are output.
In the case of the
.BR err ,
.BR verr ,
.BR warn ,
and
.BR vwarn
functions, the error message string affiliated with the current value of
the global variable
.IR errno
is output.
In all cases, the output is followed by a newline character.
.LP
The
.BR err ,
.BR verr ,
.BR errx ,
and
.BR verrx
functions do not return, but exit with the value of the argument
.RI ( eval )
The
.BR err_set_exit
function can be used to specify a function which is called before
.BR exit (3)
to perform any necessary cleanup; passing a null function pointer for
.IR exitf
resets the hook to do nothing.
.SH EXAMPLES
Display the current errno information string and exit:
.RS
.nf
if ((p = malloc(size)) == NULL)
err(1, NULL);
if ((fd = open(file_name, O_RDONLY, 0)) == -1)
err(1, "%s", file_name);
.fi
.RE
.LP
Display an error message and exit:
.RS
.nf
if (tm.tm_hour < START_TIME)
errx(1, "too early, wait until %s", start_time_string);
.fi
.RE
.LP
Warn of an error:
.RS
.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)
err(1, "%s", block_device);
.fi
.RE
.SH "SEE ALSO"
.BR exit (3),
.BR strerror (3)
.SH HISTORY
The
.BR err
and
.BR warn
functions first appeared in 4.4BSD.