xref: /freebsd/lib/libc/gen/err.3 (revision 7a30f183974d754fc6cdeff060de0bcf8557a753)
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
337a30f183SBruce Evans.\"	$Id: err.3,v 1.6 1997/02/22 14:58:02 peter Exp $
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 errx "int eval" "const char *fmt" "..."
5658f0484fSRodney W. Grimes.Ft void
5758f0484fSRodney W. Grimes.Fn warn "const char *fmt" "..."
5858f0484fSRodney W. Grimes.Ft void
5958f0484fSRodney W. Grimes.Fn warnx "const char *fmt" "..."
6058f0484fSRodney W. Grimes.Ft void
613688be0eSGarrett Wollman.Fn err_set_file "void *fp"
623688be0eSGarrett Wollman.Ft void
633688be0eSGarrett Wollman.Fn err_set_exit "void (*exitf)(int)"
647a30f183SBruce Evans.Fd #include <stdarg.h>
657a30f183SBruce Evans.Ft void
667a30f183SBruce Evans.Fn verr "int eval" "const char *fmt" "va_list args"
677a30f183SBruce Evans.Ft void
687a30f183SBruce Evans.Fn verrx "int eval" "const char *fmt" "va_list args"
697a30f183SBruce Evans.Ft void
707a30f183SBruce Evans.Fn vwarn "const char *fmt" "va_list args"
717a30f183SBruce Evans.Ft void
727a30f183SBruce Evans.Fn vwarnx "const char *fmt" "va_list args"
7358f0484fSRodney W. Grimes.Sh DESCRIPTION
7458f0484fSRodney W. GrimesThe
7558f0484fSRodney W. Grimes.Fn err
7658f0484fSRodney W. Grimesand
7758f0484fSRodney W. Grimes.Fn warn
7858f0484fSRodney W. Grimesfamily of functions display a formatted error message on the standard
793688be0eSGarrett Wollmanerror output, or on another file specified using the
803688be0eSGarrett Wollman.Fn err_set_file
813688be0eSGarrett Wollmanfunction.
8258f0484fSRodney W. GrimesIn all cases, the last component of the program name, a colon character,
8358f0484fSRodney W. Grimesand a space are output.
8458f0484fSRodney W. GrimesIf the
8558f0484fSRodney W. Grimes.Va fmt
8658f0484fSRodney W. Grimesargument is not NULL, the formatted error message, a colon character,
8758f0484fSRodney W. Grimesand a space are output.
8858f0484fSRodney W. GrimesIn the case of the
8958f0484fSRodney W. Grimes.Fn err ,
9058f0484fSRodney W. Grimes.Fn verr ,
9158f0484fSRodney W. Grimes.Fn warn ,
9258f0484fSRodney W. Grimesand
9358f0484fSRodney W. Grimes.Fn vwarn
9458f0484fSRodney W. Grimesfunctions, the error message string affiliated with the current value of
9558f0484fSRodney W. Grimesthe global variable
9658f0484fSRodney W. Grimes.Va errno
9758f0484fSRodney W. Grimesis output.
9858f0484fSRodney W. GrimesIn all cases, the output is followed by a newline character.
9958f0484fSRodney W. Grimes.Pp
10058f0484fSRodney W. GrimesThe
10158f0484fSRodney W. Grimes.Fn err ,
10258f0484fSRodney W. Grimes.Fn verr ,
10358f0484fSRodney W. Grimes.Fn errx ,
10458f0484fSRodney W. Grimesand
10558f0484fSRodney W. Grimes.Fn verrx
10658f0484fSRodney W. Grimesfunctions do not return, but exit with the value of the argument
10758f0484fSRodney W. Grimes.Fa eval .
1083688be0eSGarrett WollmanThe
1093688be0eSGarrett Wollman.Fn err_set_exit
1103688be0eSGarrett Wollmanfunction can be used to specify a function which is called before
11178b0b234SMike Pritchard.Xr exit 3
1123688be0eSGarrett Wollmanto perform any necessary cleanup; passing a null function pointer for
1133688be0eSGarrett Wollman.Va exitf
1143688be0eSGarrett Wollmanresets the hook to do nothing.
11558f0484fSRodney W. Grimes.Sh EXAMPLES
11658f0484fSRodney W. GrimesDisplay the current errno information string and exit:
11758f0484fSRodney W. Grimes.Bd -literal -offset indent
11858f0484fSRodney W. Grimesif ((p = malloc(size)) == NULL)
11958f0484fSRodney W. Grimes	err(1, NULL);
12058f0484fSRodney W. Grimesif ((fd = open(file_name, O_RDONLY, 0)) == -1)
12158f0484fSRodney W. Grimes	err(1, "%s", file_name);
12258f0484fSRodney W. Grimes.Ed
12358f0484fSRodney W. Grimes.Pp
12458f0484fSRodney W. GrimesDisplay an error message and exit:
12558f0484fSRodney W. Grimes.Bd -literal -offset indent
12658f0484fSRodney W. Grimesif (tm.tm_hour < START_TIME)
12758f0484fSRodney W. Grimes	errx(1, "too early, wait until %s", start_time_string);
12858f0484fSRodney W. Grimes.Ed
12958f0484fSRodney W. Grimes.Pp
13058f0484fSRodney W. GrimesWarn of an error:
13158f0484fSRodney W. Grimes.Bd -literal -offset indent
13258f0484fSRodney W. Grimesif ((fd = open(raw_device, O_RDONLY, 0)) == -1)
13358f0484fSRodney W. Grimes	warnx("%s: %s: trying the block device",
13458f0484fSRodney W. Grimes	    raw_device, strerror(errno));
13558f0484fSRodney W. Grimesif ((fd = open(block_device, O_RDONLY, 0)) == -1)
13658f0484fSRodney W. Grimes	err(1, "%s", block_device);
13758f0484fSRodney W. Grimes.Ed
13858f0484fSRodney W. Grimes.Sh SEE ALSO
13978b0b234SMike Pritchard.Xr exit 3 ,
14058f0484fSRodney W. Grimes.Xr strerror 3
14158f0484fSRodney W. Grimes.Sh HISTORY
14258f0484fSRodney W. GrimesThe
14358f0484fSRodney W. Grimes.Fn err
14458f0484fSRodney W. Grimesand
14558f0484fSRodney W. Grimes.Fn warn
1467bdf80e5SMike Pritchardfunctions first appeared in
1477bdf80e5SMike Pritchard.Bx 4.4 .
148