summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/err.366
-rw-r--r--lib/libc/gen/err.c142
2 files changed, 124 insertions, 84 deletions
diff --git a/lib/libc/gen/err.3 b/lib/libc/gen/err.3
index 698e6de..1654a6b 100644
--- a/lib/libc/gen/err.3
+++ b/lib/libc/gen/err.3
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93
-.\" $Id: err.3,v 1.7 1997/03/19 00:43:13 bde Exp $
+.\" $Id: err.3,v 1.8 1998/04/22 19:59:55 rnordier Exp $
.\"
.Dd April 13, 1995
.Dt ERR 3
@@ -38,10 +38,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 ,
.Nm err_set_file ,
@@ -52,23 +56,32 @@
.Ft void
.Fn err "int eval" "const char *fmt" "..."
.Ft void
+.Fn errc "int eval" "int code" "const char *fmt" "..."
+.Ft void
.Fn errx "int eval" "const char *fmt" "..."
.Ft void
.Fn warn "const char *fmt" "..."
.Ft void
+.Fn warnc "int code" "const char *fmt" "..."
+.Ft void
.Fn warnx "const char *fmt" "..."
+.Fd #include <stdio.h>
.Ft void
-.Fn err_set_file "void *fp"
+.Fn err_set_file "FILE *fp"
.Ft void
.Fn err_set_exit "void (*exitf)(int)"
.Fd #include <stdarg.h>
.Ft void
.Fn verr "int eval" "const char *fmt" "va_list args"
.Ft void
+.Fn verrc "int eval" "int code" "const char *fmt" "va_list args"
+.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 vwarnc "int code" "const char *fmt" "va_list args"
+.Ft void
.Fn vwarnx "const char *fmt" "va_list args"
.Sh DESCRIPTION
The
@@ -85,22 +98,37 @@ If the
.Va fmt
argument is not NULL, the formatted error message is output.
In the case of the
+.Fn errc ,
+.Fn verrc ,
+.Fn warnc ,
+and
+.Fn vwarnc
+functions,
+the error message string affiliated with the
+.Va code
+argument is also output,
+preceded by another colon and space if necessary.
+In all cases, the output is followed by a newline character.
+.Pp
+The
.Fn err ,
.Fn verr ,
.Fn warn ,
and
.Fn vwarn
-functions,
-the error message string affiliated with the current value of
-the global variable
-.Va errno
-is also output,
-preceded by another colon and space if necessary.
-In all cases, the output is followed by a newline character.
+functions use the global variable
+.Va errno
+rather than the
+.Va code
+argument of the
+.Fn errc
+family
.Pp
The
.Fn err ,
.Fn verr ,
+.Fn errc ,
+.Fn verrc ,
.Fn errx ,
and
.Fn verrx
@@ -136,6 +164,14 @@ if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
if ((fd = open(block_device, O_RDONLY, 0)) == -1)
err(1, "%s", block_device);
.Ed
+.Pp
+Warn of an error without using the global variable
+.Va errno :
+.Bd -literal -offset indent
+error = my_function(); /* returns a value from <errno.h> */
+if (error != 0)
+ warnc(error, "my_function");
+.Ed
.Sh SEE ALSO
.Xr exit 3 ,
.Xr strerror 3
@@ -146,3 +182,15 @@ and
.Fn warn
functions first appeared in
.Bx 4.4 .
+The
+.Fn err_set_file
+and
+.Fn err_set_exit
+functions first appeared in
+.Fx 2.1 .
+The
+.Fn errc
+and
+.Fn warnc
+functions first appeared in
+.Fx 3.0 .
diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c
index bf7d347..ede1465 100644
--- a/lib/libc/gen/err.c
+++ b/lib/libc/gen/err.c
@@ -29,11 +29,13 @@
* 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.
+ * From: @(#)err.c 8.1 (Berkeley) 6/4/93
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] =
+ "$Id$";
+#endif /* LIBC_RCS and not lint */
#include <err.h>
#include <errno.h>
@@ -41,17 +43,18 @@ static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
#include <stdlib.h>
#include <string.h>
-#ifdef __STDC__
#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
extern char *__progname; /* Program name, from crt0. */
static FILE *err_file; /* file to use for error output */
static void (*err_exit)(int);
+/*
+ * This is declared to take a `void *' so that the caller is not required
+ * to include <stdio.h> first. However, it is really a `FILE *', and the
+ * manual page documents it as such.
+ */
void
err_set_file(void *fp)
{
@@ -68,22 +71,11 @@ err_set_exit(void (*ef)(int))
}
void
-#ifdef __STDC__
err(int eval, const char *fmt, ...)
-#else
-err(eval, fmt, va_alist)
- int eval;
- const char *fmt;
- va_dcl
-#endif
{
va_list ap;
-#if __STDC__
va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- verr(eval, fmt, ap);
+ verrc(eval, errno, fmt, ap);
va_end(ap);
}
@@ -93,38 +85,43 @@ verr(eval, fmt, ap)
const char *fmt;
va_list ap;
{
- int sverrno;
+ verrc(eval, errno, fmt, ap);
+}
+
+void
+errc(int eval, int code, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ verrc(eval, code, fmt, ap);
+ va_end(ap);
+}
- sverrno = errno;
- if (! err_file)
+void
+verrc(eval, code, fmt, ap)
+ int eval;
+ int code;
+ const char *fmt;
+ va_list ap;
+{
+ if (err_file == 0)
err_set_file((FILE *)0);
- (void)fprintf(err_file, "%s: ", __progname);
+ fprintf(err_file, "%s: ", __progname);
if (fmt != NULL) {
- (void)vfprintf(err_file, fmt, ap);
- (void)fprintf(err_file, ": ");
+ vfprintf(err_file, fmt, ap);
+ fprintf(err_file, ": ");
}
- (void)fprintf(err_file, "%s\n", strerror(sverrno));
- if(err_exit)
+ fprintf(err_file, "%s\n", strerror(code));
+ if (err_exit)
err_exit(eval);
exit(eval);
}
void
-#if __STDC__
errx(int eval, const char *fmt, ...)
-#else
-errx(eval, fmt, va_alist)
- int eval;
- const char *fmt;
- va_dcl
-#endif
{
va_list ap;
-#if __STDC__
va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
verrx(eval, fmt, ap);
va_end(ap);
}
@@ -135,33 +132,23 @@ verrx(eval, fmt, ap)
const char *fmt;
va_list ap;
{
- if (! err_file)
+ if (err_file == 0)
err_set_file((FILE *)0);
- (void)fprintf(err_file, "%s: ", __progname);
+ fprintf(err_file, "%s: ", __progname);
if (fmt != NULL)
- (void)vfprintf(err_file, fmt, ap);
- (void)fprintf(err_file, "\n");
+ vfprintf(err_file, fmt, ap);
+ fprintf(err_file, "\n");
if (err_exit)
err_exit(eval);
exit(eval);
}
void
-#if __STDC__
warn(const char *fmt, ...)
-#else
-warn(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
va_list ap;
-#if __STDC__
va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- vwarn(fmt, ap);
+ vwarnc(errno, fmt, ap);
va_end(ap);
}
@@ -170,35 +157,40 @@ vwarn(fmt, ap)
const char *fmt;
va_list ap;
{
- int sverrno;
+ vwarnc(errno, fmt, ap);
+}
- sverrno = errno;
- if (! err_file)
+void
+warnc(int code, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vwarnc(code, fmt, ap);
+ va_end(ap);
+}
+
+void
+vwarnc(code, fmt, ap)
+ int code;
+ const char *fmt;
+ va_list ap;
+{
+ if (err_file == 0)
err_set_file((FILE *)0);
- (void)fprintf(err_file, "%s: ", __progname);
+ fprintf(err_file, "%s: ", __progname);
if (fmt != NULL) {
- (void)vfprintf(err_file, fmt, ap);
- (void)fprintf(err_file, ": ");
+ vfprintf(err_file, fmt, ap);
+ fprintf(err_file, ": ");
}
- (void)fprintf(err_file, "%s\n", strerror(sverrno));
+ fprintf(err_file, "%s\n", strerror(code));
}
void
-#ifdef __STDC__
warnx(const char *fmt, ...)
-#else
-warnx(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
va_list ap;
-#ifdef __STDC__
va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- vwarnx(fmt, ap);
+ vwarn(fmt, ap);
va_end(ap);
}
@@ -207,10 +199,10 @@ vwarnx(fmt, ap)
const char *fmt;
va_list ap;
{
- if (! err_file)
+ if (err_file == 0)
err_set_file((FILE *)0);
- (void)fprintf(err_file, "%s: ", __progname);
+ fprintf(err_file, "%s: ", __progname);
if (fmt != NULL)
- (void)vfprintf(err_file, fmt, ap);
- (void)fprintf(err_file, "\n");
+ vfprintf(err_file, fmt, ap);
+ fprintf(err_file, "\n");
}
OpenPOWER on IntegriCloud