Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/tail avoid repeated error messages by making bytes()...



details:   https://anonhg.NetBSD.org/src/rev/5e20d149d3c4
branches:  trunk
changeset: 474801:5e20d149d3c4
user:      cgd <cgd%NetBSD.org@localhost>
date:      Wed Jul 21 06:38:49 1999 +0000

description:
avoid repeated error messages by making bytes(), lines() and rlines() return
meaningful values, which can then be checked to avoid another error message.

diffstat:

 usr.bin/tail/extern.h  |   6 +++---
 usr.bin/tail/forward.c |  39 ++++++++++++++++++++++++---------------
 usr.bin/tail/read.c    |  18 ++++++++++++------
 usr.bin/tail/reverse.c |   8 ++++----
 4 files changed, 43 insertions(+), 28 deletions(-)

diffs (238 lines):

diff -r 46432964cdf0 -r 5e20d149d3c4 usr.bin/tail/extern.h
--- a/usr.bin/tail/extern.h     Wed Jul 21 04:04:21 1999 +0000
+++ b/usr.bin/tail/extern.h     Wed Jul 21 06:38:49 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.3 1994/11/23 07:42:00 jtc Exp $   */
+/*     $NetBSD: extern.h,v 1.4 1999/07/21 06:38:49 cgd Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -44,8 +44,8 @@
 void forward __P((FILE *, enum STYLE, long, struct stat *));
 void reverse __P((FILE *, enum STYLE, long, struct stat *));
 
-void bytes __P((FILE *, off_t));
-void lines __P((FILE *, off_t));
+int bytes __P((FILE *, off_t));
+int lines __P((FILE *, off_t));
 
 void err __P((int fatal, const char *fmt, ...));
 void ierr __P((void));
diff -r 46432964cdf0 -r 5e20d149d3c4 usr.bin/tail/forward.c
--- a/usr.bin/tail/forward.c    Wed Jul 21 04:04:21 1999 +0000
+++ b/usr.bin/tail/forward.c    Wed Jul 21 06:38:49 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: forward.c,v 1.15 1998/12/19 22:27:54 christos Exp $    */
+/*     $NetBSD: forward.c,v 1.16 1999/07/21 06:38:49 cgd Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)forward.c  8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: forward.c,v 1.15 1998/12/19 22:27:54 christos Exp $");
+__RCSID("$NetBSD: forward.c,v 1.16 1999/07/21 06:38:49 cgd Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -58,7 +58,7 @@
 #include <string.h>
 #include "extern.h"
 
-static void rlines __P((FILE *, long, struct stat *));
+static int rlines __P((FILE *, long, struct stat *));
 
 /*
  * forward -- display the file, from an offset, forward.
@@ -149,8 +149,10 @@
                                ierr();
                                return;
                        }
-               } else
-                       bytes(fp, off);
+               } else {
+                       if (bytes(fp, off))
+                               return;
+               }
                break;
        case RLINES:
                if (S_ISREG(sbp->st_mode)) {
@@ -159,16 +161,20 @@
                                        ierr();
                                        return;
                                }
-                       } else
-                               rlines(fp, off, sbp);
+                       } else {
+                               if (rlines(fp, off, sbp))
+                                       return;
+                       }
                } else if (off == 0) {
                        while (getc(fp) != EOF);
                        if (ferror(fp)) {
                                ierr();
                                return;
                        }
-               } else
-                       lines(fp, off);
+               } else {
+                       if (lines(fp, off))
+                               return;
+               }
                break;
        default:
                break;
@@ -234,8 +240,10 @@
 
 /*
  * rlines -- display the last offset lines of the file.
+ *
+ * Non-zero return means than a (non-fatal) error occurred.
  */
-static void
+static int
 rlines(fp, off, sbp)
        FILE *fp;
        long off;
@@ -246,17 +254,17 @@
        char *start;
 
        if (!(size = sbp->st_size))
-               return;
+               return (0);
 
        if (size > SIZE_T_MAX) {
                err(0, "%s: %s", fname, strerror(EFBIG));
-               return;
+               return (1);
        }
 
        if ((start = mmap(NULL, (size_t)size, PROT_READ,
            MAP_FILE|MAP_SHARED, fileno(fp), (off_t)0)) == (caddr_t)-1) {
                err(0, "%s: %s", fname, strerror(EFBIG));
-               return;
+               return (1);
        }
 
        /* Last char is special, ignore whether newline or not. */
@@ -271,10 +279,11 @@
        WR(p, size);
        if (fseek(fp, (long)sbp->st_size, SEEK_SET) == -1) {
                ierr();
-               return;
+               return (1);
        }
        if (munmap(start, (size_t)sbp->st_size)) {
                err(0, "%s: %s", fname, strerror(errno));
-               return;
+               return (1);
        }
+       return (0);
 }
diff -r 46432964cdf0 -r 5e20d149d3c4 usr.bin/tail/read.c
--- a/usr.bin/tail/read.c       Wed Jul 21 04:04:21 1999 +0000
+++ b/usr.bin/tail/read.c       Wed Jul 21 06:38:49 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: read.c,v 1.6 1998/11/03 14:27:09 christos Exp $        */
+/*     $NetBSD: read.c,v 1.7 1999/07/21 06:38:50 cgd Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)read.c     8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: read.c,v 1.6 1998/11/03 14:27:09 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.7 1999/07/21 06:38:50 cgd Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -63,8 +63,10 @@
  * routine has the usual nastiness of trying to find the newlines.  Otherwise,
  * it is displayed from the character closest to the beginning of the input to
  * the end.
+ *
+ * Non-zero return means than a (non-fatal) error occurred.
  */
-void
+int
 bytes(fp, off)
        FILE *fp;
        off_t off;
@@ -86,7 +88,7 @@
        }
        if (ferror(fp)) {
                ierr();
-               return;
+               return (1);
        }
 
        if (rflag) {
@@ -119,6 +121,7 @@
                if ((len = p - sp) == 0)
                        WR(sp, len);
        }
+       return (0);
 }
 
 /*
@@ -130,8 +133,10 @@
  * routine has the usual nastiness of trying to find the newlines.  Otherwise,
  * it is displayed from the line closest to the beginning of the input to
  * the end.
+ *
+ * Non-zero return means than a (non-fatal) error occurred.
  */
-void
+int
 lines(fp, off)
        FILE *fp;
        off_t off;
@@ -180,7 +185,7 @@
        }
        if (ferror(fp)) {
                ierr();
-               return;
+               return (1);
        }
        if (cnt) {
                lines[recno].l = sp;
@@ -204,4 +209,5 @@
                for (cnt = 0; cnt < recno; ++cnt)
                        WR(lines[cnt].l, lines[cnt].len);
        }
+       return (0);
 }
diff -r 46432964cdf0 -r 5e20d149d3c4 usr.bin/tail/reverse.c
--- a/usr.bin/tail/reverse.c    Wed Jul 21 04:04:21 1999 +0000
+++ b/usr.bin/tail/reverse.c    Wed Jul 21 06:38:49 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: reverse.c,v 1.10 1998/02/20 07:35:00 mycroft Exp $     */
+/*     $NetBSD: reverse.c,v 1.11 1999/07/21 06:38:50 cgd Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)reverse.c  8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: reverse.c,v 1.10 1998/02/20 07:35:00 mycroft Exp $");
+__RCSID("$NetBSD: reverse.c,v 1.11 1999/07/21 06:38:50 cgd Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -93,11 +93,11 @@
                switch(style) {
                case FBYTES:
                case RBYTES:
-                       bytes(fp, off);
+                       (void)bytes(fp, off);
                        break;
                case FLINES:
                case RLINES:
-                       lines(fp, off);
+                       (void)lines(fp, off);
                        break;
                case REVERSE:
                        r_buf(fp);



Home | Main Index | Thread Index | Old Index