xref: /freebsd/lib/libc/gen/err.3 (revision 3688be0eeb59367d9dd33e4b0963813b72ce0ef3)
158f0484fSRodney W. Grimes.\" Copyright (c) 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
658f0484fSRodney W. Grimes.\" are met:
758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
858f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1058f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1158f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
1258f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
1358f0484fSRodney W. Grimes.\"    must display the following acknowledgement:
1458f0484fSRodney W. Grimes.\"	This product includes software developed by the University of
1558f0484fSRodney W. Grimes.\"	California, Berkeley and its contributors.
1658f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
1758f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1858f0484fSRodney W. Grimes.\"    without specific prior written permission.
1958f0484fSRodney W. Grimes.\"
2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3058f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3158f0484fSRodney W. Grimes.\"
323688be0eSGarrett Wollman.\"	From: @(#)err.3	8.1 (Berkeley) 6/9/93
333688be0eSGarrett Wollman.\"	$Id$
3458f0484fSRodney W. Grimes.\"
353688be0eSGarrett Wollman.Dd April 13, 1995
3658f0484fSRodney W. Grimes.Dt ERR 3
3758f0484fSRodney W. Grimes.Os BSD 4
3858f0484fSRodney W. Grimes.Sh NAME
3958f0484fSRodney W. Grimes.Nm err ,
4058f0484fSRodney W. Grimes.Nm verr ,
4158f0484fSRodney W. Grimes.Nm errx ,
4258f0484fSRodney W. Grimes.Nm verrx ,
4358f0484fSRodney W. Grimes.Nm warn ,
4458f0484fSRodney W. Grimes.Nm vwarn ,
4558f0484fSRodney W. Grimes.Nm warnx ,
463688be0eSGarrett Wollman.Nm vwarnx ,
473688be0eSGarrett Wollman.Nm err_set_file ,
483688be0eSGarrett Wollman.Nm err_set_exit
4958f0484fSRodney W. Grimes.Nd formatted error messages
5058f0484fSRodney W. Grimes.Sh SYNOPSIS
5158f0484fSRodney W. Grimes.Fd #include <err.h>
5258f0484fSRodney W. Grimes.Ft void
5358f0484fSRodney W. Grimes.Fn err "int eval" "const char *fmt" "..."
5458f0484fSRodney W. Grimes.Ft void
5558f0484fSRodney W. Grimes.Fn verr "int eval" "const char *fmt" "va_list args"
5658f0484fSRodney W. Grimes.Ft void
5758f0484fSRodney W. Grimes.Fn errx "int eval" "const char *fmt" "..."
5858f0484fSRodney W. Grimes.Ft void
5958f0484fSRodney W. Grimes.Fn verrx "int eval" "const char *fmt" "va_list args"
6058f0484fSRodney W. Grimes.Ft void
6158f0484fSRodney W. Grimes.Fn warn "const char *fmt" "..."
6258f0484fSRodney W. Grimes.Ft void
6358f0484fSRodney W. Grimes.Fn vwarn "const char *fmt" "va_list args"
6458f0484fSRodney W. Grimes.Ft void
6558f0484fSRodney W. Grimes.Fn warnx "const char *fmt" "..."
6658f0484fSRodney W. Grimes.Ft void
6758f0484fSRodney W. Grimes.Fn vwarnx "const char *fmt" "va_list args"
683688be0eSGarrett Wollman.Ft void
693688be0eSGarrett Wollman.Fn err_set_file "void *fp"
703688be0eSGarrett Wollman.Ft void
713688be0eSGarrett Wollman.Fn err_set_exit "void (*exitf)(int)"
7258f0484fSRodney W. Grimes.Sh DESCRIPTION
7358f0484fSRodney W. GrimesThe
7458f0484fSRodney W. Grimes.Fn err
7558f0484fSRodney W. Grimesand
7658f0484fSRodney W. Grimes.Fn warn
7758f0484fSRodney W. Grimesfamily of functions display a formatted error message on the standard
783688be0eSGarrett Wollmanerror output, or on another file specified using the
793688be0eSGarrett Wollman.Fn err_set_file
803688be0eSGarrett Wollmanfunction.
8158f0484fSRodney W. GrimesIn all cases, the last component of the program name, a colon character,
8258f0484fSRodney W. Grimesand a space are output.
8358f0484fSRodney W. GrimesIf the
8458f0484fSRodney W. Grimes.Va fmt
8558f0484fSRodney W. Grimesargument is not NULL, the formatted error message, a colon character,
8658f0484fSRodney W. Grimesand a space are output.
8758f0484fSRodney W. GrimesIn the case of the
8858f0484fSRodney W. Grimes.Fn err ,
8958f0484fSRodney W. Grimes.Fn verr ,
9058f0484fSRodney W. Grimes.Fn warn ,
9158f0484fSRodney W. Grimesand
9258f0484fSRodney W. Grimes.Fn vwarn
9358f0484fSRodney W. Grimesfunctions, the error message string affiliated with the current value of
9458f0484fSRodney W. Grimesthe global variable
9558f0484fSRodney W. Grimes.Va errno
9658f0484fSRodney W. Grimesis output.
9758f0484fSRodney W. GrimesIn all cases, the output is followed by a newline character.
9858f0484fSRodney W. Grimes.Pp
9958f0484fSRodney W. GrimesThe
10058f0484fSRodney W. Grimes.Fn err ,
10158f0484fSRodney W. Grimes.Fn verr ,
10258f0484fSRodney W. Grimes.Fn errx ,
10358f0484fSRodney W. Grimesand
10458f0484fSRodney W. Grimes.Fn verrx
10558f0484fSRodney W. Grimesfunctions do not return, but exit with the value of the argument
10658f0484fSRodney W. Grimes.Fa eval .
1073688be0eSGarrett WollmanThe
1083688be0eSGarrett Wollman.Fn err_set_exit
1093688be0eSGarrett Wollmanfunction can be used to specify a function which is called before
1103688be0eSGarrett Wollman.Xr exit 2
1113688be0eSGarrett Wollmanto perform any necessary cleanup; passing a null function pointer for
1123688be0eSGarrett Wollman.Va exitf
1133688be0eSGarrett Wollmanresets the hook to do nothing.
11458f0484fSRodney W. Grimes.Sh EXAMPLES
11558f0484fSRodney W. GrimesDisplay the current errno information string and exit:
11658f0484fSRodney W. Grimes.Bd -literal -offset indent
11758f0484fSRodney W. Grimesif ((p = malloc(size)) == NULL)
11858f0484fSRodney W. Grimes	err(1, NULL);
11958f0484fSRodney W. Grimesif ((fd = open(file_name, O_RDONLY, 0)) == -1)
12058f0484fSRodney W. Grimes	err(1, "%s", file_name);
12158f0484fSRodney W. Grimes.Ed
12258f0484fSRodney W. Grimes.Pp
12358f0484fSRodney W. GrimesDisplay an error message and exit:
12458f0484fSRodney W. Grimes.Bd -literal -offset indent
12558f0484fSRodney W. Grimesif (tm.tm_hour < START_TIME)
12658f0484fSRodney W. Grimes	errx(1, "too early, wait until %s", start_time_string);
12758f0484fSRodney W. Grimes.Ed
12858f0484fSRodney W. Grimes.Pp
12958f0484fSRodney W. GrimesWarn of an error:
13058f0484fSRodney W. Grimes.Bd -literal -offset indent
13158f0484fSRodney W. Grimesif ((fd = open(raw_device, O_RDONLY, 0)) == -1)
13258f0484fSRodney W. Grimes	warnx("%s: %s: trying the block device",
13358f0484fSRodney W. Grimes	    raw_device, strerror(errno));
13458f0484fSRodney W. Grimesif ((fd = open(block_device, O_RDONLY, 0)) == -1)
13558f0484fSRodney W. Grimes	err(1, "%s", block_device);
13658f0484fSRodney W. Grimes.Ed
13758f0484fSRodney W. Grimes.Sh SEE ALSO
13858f0484fSRodney W. Grimes.Xr strerror 3
13958f0484fSRodney W. Grimes.Sh HISTORY
14058f0484fSRodney W. GrimesThe
14158f0484fSRodney W. Grimes.Fn err
14258f0484fSRodney W. Grimesand
14358f0484fSRodney W. Grimes.Fn warn
14458f0484fSRodney W. Grimesfunctions first appeared in 4.4BSD.
145