add support for fmt == NULL, so can display "prog: errno_msg"
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 20 Mar 1993 04:07:09 +0000 (20:07 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 20 Mar 1993 04:07:09 +0000 (20:07 -0800)
SCCS-vsn: lib/libc/gen/err.c 5.2
SCCS-vsn: lib/libc/gen/err.3 5.2

usr/src/lib/libc/gen/err.3
usr/src/lib/libc/gen/err.c

index 47f3916..4eb0752 100644 (file)
@@ -3,7 +3,7 @@
 .\"
 .\" %sccs.include.redist.roff%
 .\"
 .\"
 .\" %sccs.include.redist.roff%
 .\"
-.\"    @(#)err.3       5.1 (Berkeley) %G%
+.\"    @(#)err.3       5.2 (Berkeley) %G%
 .\"
 .Dd ""
 .Dt ERR 3
 .\"
 .Dd ""
 .Dt ERR 3
@@ -43,19 +43,23 @@ and
 .Fn warn
 family of functions display a formatted error message on the standard
 error output.
 .Fn warn
 family of functions display a formatted error message on the standard
 error output.
-In all cases, the error message is preceded by the last component
-of the program name, a colon character, and a space.
+In all cases, the last component of the program name, a colon character,
+and a space are output.
+If the
+.Va fmt
+argument is not NULL, the formatted error message, a colon character,
+and a space are output.
 In the case of the
 .Fn err ,
 .Fn verr ,
 .Fn warn ,
 and
 .Fn vwarn
 In the case of the
 .Fn err ,
 .Fn verr ,
 .Fn warn ,
 and
 .Fn vwarn
-functions, a colon character, a space and the error message string
-affiliated with the current value of the global variable
+functions, the error message string affiliated with the current value of
+the global variable
 .Va errno 
 .Va errno 
-are displayed after the formatted error message.
-In all cases, the message is followed by a newline character.
+is output.
+In all cases, the output is followed by a newline character.
 .Pp
 The
 .Fn err ,
 .Pp
 The
 .Fn err ,
@@ -68,6 +72,8 @@ functions do not return, but exit with the value of the argument
 .Sh EXAMPLES
 Display the current errno information string and exit:
 .Bd -literal -offset indent
 .Sh EXAMPLES
 Display the current errno information string and exit:
 .Bd -literal -offset indent
+if ((p = malloc(size)) == NULL)
+       err(1, NULL);
 if ((fd = open(file_name, O_RDONLY, 0)) == -1)
        err(1, "%s", file_name);
 .Ed
 if ((fd = open(file_name, O_RDONLY, 0)) == -1)
        err(1, "%s", file_name);
 .Ed
index c5bd9cf..faae4d5 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)err.c      5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)err.c      5.2 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <err.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <err.h>
@@ -53,8 +53,11 @@ verr(eval, fmt, ap)
 
        sverrno = errno;
        (void)fprintf(stderr, "%s: ", __progname);
 
        sverrno = errno;
        (void)fprintf(stderr, "%s: ", __progname);
-       (void)vfprintf(stderr, fmt, ap);
-       (void)fprintf(stderr, ": %s\n", strerror(sverrno));
+       if (fmt != NULL) {
+               (void)vfprintf(stderr, fmt, ap);
+               (void)fprintf(stderr, ": ");
+       }
+       (void)fprintf(stderr, "%s\n", strerror(sverrno));
        exit(eval);
 }
 
        exit(eval);
 }
 
@@ -85,7 +88,8 @@ verrx(eval, fmt, ap)
        va_list ap;
 {
        (void)fprintf(stderr, "%s: ", __progname);
        va_list ap;
 {
        (void)fprintf(stderr, "%s: ", __progname);
-       (void)vfprintf(stderr, fmt, ap);
+       if (fmt != NULL)
+               (void)vfprintf(stderr, fmt, ap);
        (void)fprintf(stderr, "\n");
        exit(eval);
 }
        (void)fprintf(stderr, "\n");
        exit(eval);
 }
@@ -119,8 +123,11 @@ vwarn(fmt, ap)
 
        sverrno = errno;
        (void)fprintf(stderr, "%s: ", __progname);
 
        sverrno = errno;
        (void)fprintf(stderr, "%s: ", __progname);
-       (void)vfprintf(stderr, fmt, ap);
-       (void)fprintf(stderr, ": %s\n", strerror(sverrno));
+       if (fmt != NULL) {
+               (void)vfprintf(stderr, fmt, ap);
+               (void)fprintf(stderr, ": ");
+       }
+       (void)fprintf(stderr, "%s\n", strerror(sverrno));
 }
 
 void
 }
 
 void
@@ -149,6 +156,7 @@ vwarnx(fmt, ap)
        va_list ap;
 {
        (void)fprintf(stderr, "%s: ", __progname);
        va_list ap;
 {
        (void)fprintf(stderr, "%s: ", __progname);
-       (void)vfprintf(stderr, fmt, ap);
+       if (fmt != NULL)
+               (void)vfprintf(stderr, fmt, ap);
        (void)fprintf(stderr, "\n");
 }
        (void)fprintf(stderr, "\n");
 }