summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2014-04-22 00:33:03 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2014-04-22 00:33:03 +0000
commitbf36b14ca33238cecebe45a31d905b4ef547ff70 (patch)
tree443249c78f4f685df1e2927ee90d88eebc0fc412
parent667969c3f2cbf1378b0032235fbcf3420ac8f0b6 (diff)
Add errc/verrc/warnc/vwarnc family: versions of err/... that take the errno
value to use for the strerror() message as an argument. Originally from FreeBSD 3.0 Patch from Steffen Nurpmeso (sdaoden (at) gmail.com) with minor tweaks.
-rw-r--r--include/err.h18
-rw-r--r--lib/libc/gen/Makefile.inc6
-rw-r--r--lib/libc/gen/err.367
-rw-r--r--lib/libc/gen/errc.c45
-rw-r--r--lib/libc/gen/verrc.c52
-rw-r--r--lib/libc/gen/vwarnc.c50
-rw-r--r--lib/libc/gen/warnc.c45
7 files changed, 258 insertions, 25 deletions
diff --git a/include/err.h b/include/err.h
index de7f37017fc..af9736851ec 100644
--- a/include/err.h
+++ b/include/err.h
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -44,6 +44,10 @@ __dead void err(int, const char *, ...)
__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)
@@ -52,6 +56,10 @@ void warn(const char *, ...)
__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)
@@ -64,6 +72,10 @@ __dead void _err(int, const char *, ...)
__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)
@@ -72,6 +84,10 @@ void _warn(const char *, ...)
__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)
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index a6b77b0154a..b4261b1f17d 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,4 +1,4 @@
-# $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
@@ -7,7 +7,7 @@ SRCS+= alarm.c assert.c auth_subr.c authenticate.c \
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 \
@@ -25,7 +25,7 @@ SRCS+= alarm.c assert.c auth_subr.c authenticate.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
diff --git a/lib/libc/gen/err.3 b/lib/libc/gen/err.3
index 43439de5a3d..d5b473da627 100644
--- a/lib/libc/gen/err.3
+++ b/lib/libc/gen/err.3
@@ -1,4 +1,4 @@
-.\" $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.
@@ -27,16 +27,20 @@
.\" 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
@@ -47,6 +51,10 @@
.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"
@@ -55,6 +63,10 @@
.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"
@@ -73,8 +85,8 @@ The text that follows depends on the function being called.
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
@@ -83,15 +95,19 @@ argument is not
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
@@ -113,22 +129,31 @@ progname: error message string
.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
diff --git a/lib/libc/gen/errc.c b/lib/libc/gen/errc.c
new file mode 100644
index 00000000000..345bdc2e465
--- /dev/null
+++ b/lib/libc/gen/errc.c
@@ -0,0 +1,45 @@
+/* $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);
+
diff --git a/lib/libc/gen/verrc.c b/lib/libc/gen/verrc.c
new file mode 100644
index 00000000000..5babb671522
--- /dev/null
+++ b/lib/libc/gen/verrc.c
@@ -0,0 +1,52 @@
+/* $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);
+
diff --git a/lib/libc/gen/vwarnc.c b/lib/libc/gen/vwarnc.c
new file mode 100644
index 00000000000..1cfc518cdac
--- /dev/null
+++ b/lib/libc/gen/vwarnc.c
@@ -0,0 +1,50 @@
+/* $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);
+
diff --git a/lib/libc/gen/warnc.c b/lib/libc/gen/warnc.c
new file mode 100644
index 00000000000..0ad8df27dd5
--- /dev/null
+++ b/lib/libc/gen/warnc.c
@@ -0,0 +1,45 @@
+/* $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);
+