NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/48521: err.h / err(3): add missing errc(3)/verrc(3)/warnc(3)/vwarnc(3) family



>Number:         48521
>Category:       lib
>Synopsis:       See subject
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 14 13:45:00 +0000 2014
>Originator:     =09
>Release:        NetBSD 6.99.28
>Organization:
=09
>Environment:
=09
=09
System: NetBSD nhead 6.99.28 NetBSD 6.99.28 (GENERIC) #0: Fri Jan 3 05:24:4=
6 UTC 2014 
builds%b8.netbsd.org@localhost:/home/builds/ab/HEAD/i386/201401022300Z-obj=
/home/builds/ab/HEAD/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
        The *c() family, which exists in FreeBSD and derivatives, is helpful
        whenever something has to be done in the error case (like necessary
        cleanup), while still being able to inform the user about the original
        error that caused the problem.
>How-To-Repeat:
=09
>Fix:
  I'll attach a diff (i've got rid of send-pr(1), finally) against
  HEAD of end of november.  I didn't compile it, but it's only
  marginal anyway.

  Btw.:
                send-pr: `yes! oh - yes! oh - yes! oh...' is not a valid value 
for
                `Confidential'.
                Errors were found with the problem report.
                a)bort, e)dit or s)end?

--=_01389637904=-v4jN/VUt61w5ShXTFjnqqzOcm3pjnQ=_
Content-Type: text/x-diff; charset=ISO8859-15
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="netbsd.diff"

diff -Napru net.orig/include/err.h net/include/err.h
--- net.orig/include/err.h      2014-01-14 12:13:10.000000000 +0100
+++ net/include/err.h   2014-01-14 13:21:12.000000000 +0100
@@ -42,6 +42,10 @@ __dead void  err(int, const char *, ...)
                     __printflike(2, 3) __dead;
 __dead void    verr(int, const char *, va_list)
                    __printflike(2, 0) __dead;
+__dead void    errc(int, int, const char *, ...)
+                    __printflike(3, 4) __dead;
+__dead void    verrc(int, int, const char *, va_list)
+                   __printflike(3, 0) __dead;
 __dead void    errx(int, const char *, ...)
                     __printflike(2, 3) __dead;
 __dead void    verrx(int, const char *, va_list)
@@ -50,6 +54,10 @@ void         warn(const char *, ...)
                    __printflike(1, 2);
 void           vwarn(const char *, va_list)
                    __printflike(1, 0);
+void           warnc(int, const char *, ...)
+                   __printflike(2, 3);
+void           vwarnc(int, const char *, va_list)
+                   __printflike(2, 0);
 void           warnx(const char *, ...)
                    __printflike(1, 2);
 void           vwarnx(const char *, va_list)
diff -Napru net.orig/lib/libc/gen/_errc.c net/lib/libc/gen/_errc.c
--- net.orig/lib/libc/gen/_errc.c       1970-01-01 01:00:00.000000000 +0100
+++ net/lib/libc/gen/_errc.c    2014-01-14 13:08:19.000000000 +0100
@@ -0,0 +1,25 @@
+/*     $NetBSD$        */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD$");
+#endif /* LIBC_SCCS and not lint */
+
+#if defined(__indr_reference)
+__indr_reference(_errc, errc)
+#else
+
+#include <stdarg.h>
+
+__dead void _verrc(int, const char *, va_list);
+
+__dead void
+errc(int status, int code, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       _verrc(status, code, fmt, ap);
+       va_end(ap);
+}
+#endif
diff -Napru net.orig/lib/libc/gen/_verrc.c net/lib/libc/gen/_verrc.c
--- net.orig/lib/libc/gen/_verrc.c      1970-01-01 01:00:00.000000000 +0100
+++ net/lib/libc/gen/_verrc.c   2014-01-14 13:07:39.000000000 +0100
@@ -0,0 +1,22 @@
+/*     $NetBSD$        */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD$");
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdarg.h>
+
+#if defined(__indr_reference)
+__indr_reference(_verrc, verrc)
+#else
+
+__dead void _verrc(int, int, const char *, va_list);
+
+void
+verrc(int status, int code, const char *fmt, va_list ap)
+{
+       _verrc(status, code, fmt, ap);
+}
+
+#endif
diff -Napru net.orig/lib/libc/gen/_vwarnc.c net/lib/libc/gen/_vwarnc.c
--- net.orig/lib/libc/gen/_vwarnc.c     1970-01-01 01:00:00.000000000 +0100
+++ net/lib/libc/gen/_vwarnc.c  2014-01-14 13:04:54.000000000 +0100
@@ -0,0 +1,22 @@
+/*     $NetBSD$        */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD$");
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdarg.h>
+
+#if defined(__indr_reference)
+__indr_reference(_vwarnc, vwarnc)
+#else
+
+void _vwarnc(int, const char *, va_list);
+
+void
+vwarnc(int code, const char *fmt, va_list ap)
+{
+       _vwarnc(code, fmt, ap);
+}
+
+#endif
diff -Napru net.orig/lib/libc/gen/_warnc.c net/lib/libc/gen/_warnc.c
--- net.orig/lib/libc/gen/_warnc.c      1970-01-01 01:00:00.000000000 +0100
+++ net/lib/libc/gen/_warnc.c   2014-01-14 13:05:26.000000000 +0100
@@ -0,0 +1,25 @@
+/*     $NetBSD$        */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD$");
+#endif /* LIBC_SCCS and not lint */
+
+#if defined(__indr_reference)
+__indr_reference(_warnc, warnc)
+#else
+
+#include <stdarg.h>
+
+void _vwarnc(int, const char *, va_list);
+
+void
+warnc(int code, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       _vwarnc(code, fmt, ap);
+       va_end(ap);
+}
+#endif
diff -Napru net.orig/lib/libc/gen/err.3 net/lib/libc/gen/err.3
--- net.orig/lib/libc/gen/err.3 2014-01-14 12:06:06.000000000 +0100
+++ net/lib/libc/gen/err.3      2014-01-14 13:22:30.000000000 +0100
@@ -35,10 +35,14 @@
 .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
@@ -51,6 +55,10 @@
 .Ft void
 .Fn verr "int status" "const char *fmt" "va_list args"
 .Ft void
+.Fn errc "int status" "int code" "const char *fmt" "..."
+.Ft void
+.Fn verrc "int status" "int code" "const char *fmt" "va_list args"
+.Ft void
 .Fn errx "int status" "const char *fmt" "..."
 .Ft void
 .Fn verrx "int status" "const char *fmt" "va_list args"
@@ -59,6 +67,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"
@@ -89,6 +101,16 @@ is output next, preceded by a colon char
 .Fa fmt
 is not
 .Dv NULL .
+The
+.Fn errc ,
+.Fn verrc ,
+.Fn warnc
+and
+.Fn vwarnc
+functions use the given error
+.Fa code
+argument instead of the global variable
+.Va errno .
 In all cases, the output is followed by a newline character.
 The
 .Fn errx ,
@@ -101,7 +123,9 @@ functions will not output this error mes
 The
 .Fn err ,
 .Fn verr ,
-.Fn errx ,
+.Fn errc ,
+.Fn verrc ,
+.Fn errx
 and
 .Fn verrx
 functions do not return, but instead cause the program to terminate
diff -Napru net.orig/lib/libc/gen/errc.c net/lib/libc/gen/errc.c
--- net.orig/lib/libc/gen/errc.c        1970-01-01 01:00:00.000000000 +0100
+++ net/lib/libc/gen/errc.c     2014-01-14 13:03:37.000000000 +0100
@@ -0,0 +1,59 @@
+/*     $NetBSD$        */
+
+/*-
+ * 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.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD$");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <err.h>
+#include <stdarg.h>
+
+#ifdef __weak_alias
+__weak_alias(errc, _errc)
+#endif
+
+#if !HAVE_ERR_H
+__dead void
+errc(int status, int code, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       verrc(status, code, fmt, ap);
+       va_end(ap);
+}
+#endif
diff -Napru net.orig/lib/libc/gen/verrc.c net/lib/libc/gen/verrc.c
--- net.orig/lib/libc/gen/verrc.c       1970-01-01 01:00:00.000000000 +0100
+++ net/lib/libc/gen/verrc.c    2014-01-14 13:09:11.000000000 +0100
@@ -0,0 +1,65 @@
+/*     $NetBSD$        */
+
+/*-
+ * 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.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD$");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <err.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __weak_alias
+__weak_alias(verrc, _verrc)
+#endif
+
+#if !HAVE_ERR_H
+__dead void
+verrc(int status, int code, const char *fmt, va_list ap)
+{
+       (void)fprintf(stderr, "%s: ", getprogname());
+       if (fmt != NULL) {
+               (void)vfprintf(stderr, fmt, ap);
+               (void)fprintf(stderr, ": ");
+       }
+       (void)fprintf(stderr, "%s\n", strerror(code));
+       exit(status);
+}
+#endif
diff -Napru net.orig/lib/libc/gen/vwarnc.c net/lib/libc/gen/vwarnc.c
--- net.orig/lib/libc/gen/vwarnc.c      1970-01-01 01:00:00.000000000 +0100
+++ net/lib/libc/gen/vwarnc.c   2014-01-14 13:06:25.000000000 +0100
@@ -0,0 +1,64 @@
+/*     $NetBSD$        */
+
+/*-
+ * 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.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD$");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <err.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __weak_alias
+__weak_alias(vwarnc, _vwarnc)
+#endif
+
+#if !HAVE_ERR_H
+void
+vwarnc(int code, const char *fmt, va_list ap)
+{
+       (void)fprintf(stderr, "%s: ", getprogname());
+       if (fmt != NULL) {
+               (void)vfprintf(stderr, fmt, ap);
+               (void)fprintf(stderr, ": ");
+       }
+       (void)fprintf(stderr, "%s\n", strerror(code));
+}
+#endif
diff -Napru net.orig/lib/libc/gen/warnc.c net/lib/libc/gen/warnc.c
--- net.orig/lib/libc/gen/warnc.c       1970-01-01 01:00:00.000000000 +0100
+++ net/lib/libc/gen/warnc.c    2014-01-14 13:07:03.000000000 +0100
@@ -0,0 +1,59 @@
+/*     $NetBSD$        */
+
+/*-
+ * 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.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD$");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <err.h>
+#include <stdarg.h>
+
+#ifdef __weak_alias
+__weak_alias(warnc, _warnc)
+#endif
+
+#if !HAVE_ERR_H
+void
+warnc(int code, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       vwarnc(code, fmt, ap);
+       va_end(ap);
+}
+#endif

--=_01389637904=-v4jN/VUt61w5ShXTFjnqqzOcm3pjnQ=_--

>Unformatted:
 This is a multi-part message in MIME format.
 
 --=_01389637904=-v4jN/VUt61w5ShXTFjnqqzOcm3pjnQ=_
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: inline
 
 
 =09
 =09


Home | Main Index | Thread Index | Old Index