-/* $OpenBSD: err.h,v 1.11 2014/04/21 16:13:24 guenther Exp $ */
+/* $OpenBSD: err.h,v 1.12 2014/04/22 00:33:02 guenther Exp $ */
/* $NetBSD: err.h,v 1.11 1994/10/26 00:55:52 cgd Exp $ */
/*-
__attribute__((__format__ (printf, 2, 3)));
__dead void verr(int, const char *, __va_list)
__attribute__((__format__ (printf, 2, 0)));
+__dead void errc(int, int, const char *, ...)
+ __attribute__((__format__ (printf, 3, 4)));
+__dead void verrc(int, int, const char *, __va_list)
+ __attribute__((__format__ (printf, 3, 0)));
__dead void errx(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3)));
__dead void verrx(int, const char *, __va_list)
__attribute__((__format__ (printf, 1, 2)));
void vwarn(const char *, __va_list)
__attribute__((__format__ (printf, 1, 0)));
+void warnc(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vwarnc(int, const char *, __va_list)
+ __attribute__((__format__ (printf, 2, 0)));
void warnx(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
void vwarnx(const char *, __va_list)
__attribute__((__format__ (printf, 2, 3)));
__dead void _verr(int, const char *, __va_list)
__attribute__((__format__ (printf, 2, 0)));
+__dead void _errc(int, int, const char *, ...)
+ __attribute__((__format__ (printf, 3, 4)));
+__dead void _verrc(int, int, const char *, __va_list)
+ __attribute__((__format__ (printf, 3, 0)));
__dead void _errx(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3)));
__dead void _verrx(int, const char *, __va_list)
__attribute__((__format__ (printf, 1, 2)));
void _vwarn(const char *, __va_list)
__attribute__((__format__ (printf, 1, 0)));
+void _warnc(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void _vwarnc(int, const char *, __va_list)
+ __attribute__((__format__ (printf, 2, 0)));
void _warnx(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
void _vwarnx(const char *, __va_list)
-# $OpenBSD: Makefile.inc,v 1.62 2013/06/17 19:11:54 guenther Exp $
+# $OpenBSD: Makefile.inc,v 1.63 2014/04/22 00:33:02 guenther Exp $
# gen sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen ${LIBCSRCDIR}/gen
basename.c clock.c clock_getcpuclockid.c \
closedir.c confstr.c ctermid.c ctype_.c \
daemon.c devname.c dirfd.c dirname.c disklabel.c elf_hash.c err.c \
- errx.c errlist.c errno.c exec.c \
+ errc.c errx.c errlist.c errno.c exec.c \
fdatasync.c fnmatch.c fpclassify.c frexp.c \
fstab.c ftok.c fts.c ftw.c getbsize.c getcap.c getcwd.c \
getdomainname.c getgrent.c getgrouplist.c gethostname.c \
tolower_.c ttyname.c \
ttyslot.c toupper_.c ualarm.c uname.c unvis.c usleep.c \
utime.c valloc.c vis.c wait.c wait3.c waitpid.c warn.c \
- warnx.c vwarn.c vwarnx.c verr.c verrx.c
+ warnc.c warnx.c vwarn.c vwarnc.c vwarnx.c verr.c verrc.c verrx.c
# indirect reference stubs, to be removed soon.
SRCS+= _sys_errlist.c _sys_nerr.c _sys_siglist.c
-.\" $OpenBSD: err.3,v 1.17 2013/06/05 03:39:22 tedu Exp $
+.\" $OpenBSD: err.3,v 1.18 2014/04/22 00:33:02 guenther Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: June 5 2013 $
+.Dd $Mdocdate: April 22 2014 $
.Dt ERR 3
.Os
.Sh NAME
.Nm err ,
.Nm verr ,
+.Nm errc ,
+.Nm verrc ,
.Nm errx ,
.Nm verrx ,
.Nm warn ,
.Nm vwarn ,
+.Nm warnc ,
+.Nm vwarnc ,
.Nm warnx ,
.Nm vwarnx
.Nd formatted error messages
.Ft void
.Fn verr "int eval" "const char *fmt" "va_list args"
.Ft void
+.Fn errc "int eval" "int code" "const char *fmt" "..."
+.Ft void
+.Fn verrc "int eval" "int code" "const char *fmt" "va_list args"
+.Ft void
.Fn errx "int eval" "const char *fmt" "..."
.Ft void
.Fn verrx "int eval" "const char *fmt" "va_list args"
.Ft void
.Fn vwarn "const char *fmt" "va_list args"
.Ft void
+.Fn warnc "int code" "const char *fmt" "..."
+.Ft void
+.Fn vwarnc "int code" "const char *fmt" "va_list args"
+.Ft void
.Fn warnx "const char *fmt" "..."
.Ft void
.Fn vwarnx "const char *fmt" "va_list args"
The
.Fa fmt
specification (and associated arguments) may be any format allowed by
-.Xr printf 3 ,
-a simple string, or
+.Xr printf 3
+or
.Dv NULL .
If the
.Fa fmt
the formatted error message is output.
.Pp
In the case of the
-.Fn err ,
-.Fn verr ,
-.Fn warn ,
+.Fn errx ,
+.Fn verrx ,
+.Fn warnx ,
and
-.Fn vwarn
-functions only, the error message string affiliated with the current value of
-the global variable
-.Va errno
-is output (see
+.Fn vwarnx
+functions only, no additional text is output,
+so the output looks like the following:
+.Bd -literal -offset indent
+progname: fmt
+.Ed
+.Pp
+The other functions all output an error message string affiliated with
+an error value (see
.Xr strerror 3 ) ,
preceded by a colon character and a space if
.Fa fmt
.Pp
if it is.
.Pp
-The counterpart functions,
-.Fn errx ,
-.Fn verrx ,
-.Fn warnx ,
+In the case of the
+.Fn err ,
+.Fn verr ,
+.Fn warn ,
and
-.Fn vwarnx ,
-do not output the error message string, so the output looks like the following:
-.Bd -literal -offset indent
-progname: fmt
-.Ed
+.Fn vwarn
+functions, the error value used is the current value of the global variable
+.Va errno ,
+while for the
+.Fn errc ,
+.Fn verrc ,
+.Fn warnc ,
+and
+.Fn vwarnc
+function the argument
+.Fa code
+is used.
.Pp
In all cases, the output is followed by a newline character.
.Pp
The
.Fn err ,
.Fn verr ,
+.Fn errc ,
+.Fn verrc ,
.Fn errx ,
and
.Fn verrx
--- /dev/null
+/* $OpenBSD: errc.c,v 1.1 2014/04/22 00:33:02 guenther Exp $ */
+/*-
+ * 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. 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.
+ */
+
+#include <err.h>
+#include <stdarg.h>
+
+__dead void
+_errc(int eval, int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ _verrc(eval, code, fmt, ap);
+ va_end(ap);
+}
+
+__weak_alias(errc, _errc);
+
--- /dev/null
+/* $OpenBSD: verrc.c,v 1.1 2014/04/22 00:33:02 guenther Exp $ */
+/*-
+ * 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. 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.
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+extern char *__progname; /* Program name, from crt0. */
+
+__dead void
+_verrc(int eval, int code, const char *fmt, va_list ap)
+{
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL) {
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, ": ");
+ }
+ (void)fprintf(stderr, "%s\n", strerror(code));
+ exit(eval);
+}
+
+__weak_alias(verrc, _verrc);
+
--- /dev/null
+/* $OpenBSD: vwarnc.c,v 1.1 2014/04/22 00:33:02 guenther Exp $ */
+/*-
+ * 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. 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.
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+extern char *__progname; /* Program name, from crt0. */
+
+void
+_vwarnc(int code, const char *fmt, va_list ap)
+{
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL) {
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, ": ");
+ }
+ (void)fprintf(stderr, "%s\n", strerror(code));
+}
+
+__weak_alias(vwarnc, _vwarnc);
+
--- /dev/null
+/* $OpenBSD: warnc.c,v 1.1 2014/04/22 00:33:02 guenther Exp $ */
+/*-
+ * 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. 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.
+ */
+
+#include <err.h>
+#include <stdarg.h>
+
+void
+_warnc(int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ _vwarnc(code, fmt, ap);
+ va_end(ap);
+}
+
+__weak_alias(warnc, _warnc);
+