SCCS-vsn: usr.bin/tail/extern.h 5.2
SCCS-vsn: usr.bin/tail/forward.c 5.5
SCCS-vsn: usr.bin/tail/misc.c 5.2
SCCS-vsn: usr.bin/tail/read.c 5.2
SCCS-vsn: usr.bin/tail/reverse.c 5.4
SCCS-vsn: usr.bin/tail/tail.1 6.9
SCCS-vsn: usr.bin/tail/tail.c 5.8
*
* %sccs.include.redist.c%
*
*
* %sccs.include.redist.c%
*
- * @(#)extern.h 5.1 (Berkeley) %G%
+ * @(#)extern.h 5.2 (Berkeley) %G%
void bytes __P((FILE *, off_t));
void lines __P((FILE *, off_t));
void bytes __P((FILE *, off_t));
void lines __P((FILE *, off_t));
-void err __P((const char *fmt, ...));
+void err __P((int fatal, const char *fmt, ...));
void ierr __P((void));
void oerr __P((void));
void ierr __P((void));
void oerr __P((void));
-static char sccsid[] = "@(#)forward.c 5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)forward.c 5.5 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#endif /* not lint */
#include <sys/types.h>
if (S_ISREG(sbp->st_mode)) {
if (sbp->st_size < off)
off = sbp->st_size;
if (S_ISREG(sbp->st_mode)) {
if (sbp->st_size < off)
off = sbp->st_size;
- if (fseek(fp, off, SEEK_SET) == -1)
+ if (fseek(fp, off, SEEK_SET) == -1) {
} else while (off--)
if ((ch = getc(fp)) == EOF) {
} else while (off--)
if ((ch = getc(fp)) == EOF) {
break;
case FLINES:
if (off == 0)
break;
for (;;) {
if ((ch = getc(fp)) == EOF) {
break;
case FLINES:
if (off == 0)
break;
for (;;) {
if ((ch = getc(fp)) == EOF) {
break;
}
if (ch == '\n' && !--off)
break;
}
if (ch == '\n' && !--off)
case RBYTES:
if (S_ISREG(sbp->st_mode)) {
if (sbp->st_size >= off &&
case RBYTES:
if (S_ISREG(sbp->st_mode)) {
if (sbp->st_size >= off &&
- fseek(fp, -off, SEEK_END) == -1)
+ fseek(fp, -off, SEEK_END) == -1) {
} else if (off == 0) {
while (getc(fp) != EOF);
} else if (off == 0) {
while (getc(fp) != EOF);
} else
bytes(fp, off);
break;
case RLINES:
if (S_ISREG(sbp->st_mode))
if (!off) {
} else
bytes(fp, off);
break;
case RLINES:
if (S_ISREG(sbp->st_mode))
if (!off) {
- if (fseek(fp, 0L, SEEK_END) == -1)
+ if (fseek(fp, 0L, SEEK_END) == -1) {
} else
rlines(fp, off, sbp);
else if (off == 0) {
while (getc(fp) != EOF);
} else
rlines(fp, off, sbp);
else if (off == 0) {
while (getc(fp) != EOF);
} else
lines(fp, off);
break;
} else
lines(fp, off);
break;
while ((ch = getc(fp)) != EOF)
if (putchar(ch) == EOF)
oerr();
while ((ch = getc(fp)) != EOF)
if (putchar(ch) == EOF)
oerr();
(void)fflush(stdout);
if (!fflag)
break;
/* Sleep(3) is eight system calls. Do it fast. */
if (select(0, &zero, &zero, &zero, &second) == -1)
(void)fflush(stdout);
if (!fflag)
break;
/* Sleep(3) is eight system calls. Do it fast. */
if (select(0, &zero, &zero, &zero, &second) == -1)
- err("select: %s", strerror(errno));
+ err(1, "select: %s", strerror(errno));
return;
if ((p = mmap(NULL,
return;
if ((p = mmap(NULL,
- size, PROT_READ, MAP_FILE, fileno(fp), (off_t)0)) == (caddr_t)-1)
- err("%s", strerror(errno));
+ size, PROT_READ, MAP_FILE, fileno(fp), (off_t)0)) == (caddr_t)-1) {
+ err(0, "%s", strerror(errno));
+ return;
+ }
/* Last char is special, ignore whether newline or not. */
for (p += size - 1; --size;)
/* Last char is special, ignore whether newline or not. */
for (p += size - 1; --size;)
/* Set the file pointer to reflect the length displayed. */
size = sbp->st_size - size;
WR(p, size);
/* Set the file pointer to reflect the length displayed. */
size = sbp->st_size - size;
WR(p, size);
- if (fseek(fp, sbp->st_size, SEEK_SET) == -1)
+ if (fseek(fp, sbp->st_size, SEEK_SET) == -1) {
-static char sccsid[] = "@(#)misc.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)misc.c 5.2 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#endif /* not lint */
#include <sys/types.h>
- err("%s: %s", fname, strerror(errno));
+ err(0, "%s: %s", fname, strerror(errno));
- err("stdout: %s", strerror(errno));
+ err(1, "stdout: %s", strerror(errno));
-err(const char *fmt, ...)
+err(int fatal, const char *fmt, ...)
+err(fatal, fmt, va_alist)
+ int fatal;
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
- exit(1);
- /* NOTREACHED */
+ if (fatal)
+ exit(1);
+ rval = 1;
-static char sccsid[] = "@(#)read.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)read.c 5.2 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#endif /* not lint */
#include <sys/types.h>
char *sp;
if ((sp = p = malloc(off)) == NULL)
char *sp;
if ((sp = p = malloc(off)) == NULL)
- err("%s", strerror(errno));
+ err(1, "%s", strerror(errno));
for (wrap = 0, ep = p + off; (ch = getc(fp)) != EOF;) {
*p = ch;
for (wrap = 0, ep = p + off; (ch = getc(fp)) != EOF;) {
*p = ch;
if (rflag) {
for (t = p - 1, len = 0; t >= sp; --t, ++len)
if (rflag) {
for (t = p - 1, len = 0; t >= sp; --t, ++len)
char *sp;
if ((lines = malloc(off * sizeof(*lines))) == NULL)
char *sp;
if ((lines = malloc(off * sizeof(*lines))) == NULL)
- err("%s", strerror(errno));
+ err(1, "%s", strerror(errno));
sp = NULL;
blen = cnt = recno = wrap = 0;
sp = NULL;
blen = cnt = recno = wrap = 0;
while ((ch = getc(fp)) != EOF) {
if (++cnt > blen) {
if ((sp = realloc(sp, blen += 1024)) == NULL)
while ((ch = getc(fp)) != EOF) {
if (++cnt > blen) {
if ((sp = realloc(sp, blen += 1024)) == NULL)
- err("%s", strerror(errno));
+ err(1, "%s", strerror(errno));
p = sp + cnt - 1;
}
*p++ = ch;
p = sp + cnt - 1;
}
*p++ = ch;
lines[recno].blen = cnt + 256;
if ((lines[recno].l = realloc(lines[recno].l,
lines[recno].blen)) == NULL)
lines[recno].blen = cnt + 256;
if ((lines[recno].l = realloc(lines[recno].l,
lines[recno].blen)) == NULL)
- err("%s", strerror(errno));
+ err(1, "%s", strerror(errno));
}
bcopy(sp, lines[recno].l, lines[recno].len = cnt);
cnt = 0;
}
bcopy(sp, lines[recno].l, lines[recno].len = cnt);
cnt = 0;
if (cnt) {
lines[recno].l = sp;
lines[recno].len = cnt;
if (cnt) {
lines[recno].l = sp;
lines[recno].len = cnt;
-static char sccsid[] = "@(#)reverse.c 5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)reverse.c 5.4 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#endif /* not lint */
#include <sys/param.h>
- if ((p =
- mmap(NULL, size, PROT_READ, MAP_FILE, fd, (off_t)0)) == (caddr_t)-1)
- err("%s", strerror(errno));
+ if ((p = mmap(NULL,
+ size, PROT_READ, MAP_FILE, fd, (off_t)0)) == (caddr_t)-1) {
+ err(0, "%s", strerror(errno));
+ return;
+ }
p += size - 1;
if (style == RBYTES && off < size)
p += size - 1;
if (style == RBYTES && off < size)
if (enomem || (tl = malloc(sizeof(BF))) == NULL ||
(tl->l = malloc(BSZ)) == NULL) {
if (!mark)
if (enomem || (tl = malloc(sizeof(BF))) == NULL ||
(tl->l = malloc(BSZ)) == NULL) {
if (!mark)
- err("%s", strerror(errno));
+ err(1, "%s", strerror(errno));
tl = enomem ? tl->next : mark;
enomem += tl->len;
} else if (mark) {
tl = enomem ? tl->next : mark;
enomem += tl->len;
} else if (mark) {
.\"
.\" %sccs.include.redist.roff%
.\"
.\"
.\" %sccs.include.redist.roff%
.\"
-.\" @(#)tail.1 6.8 (Berkeley) %G%
+.\" @(#)tail.1 6.9 (Berkeley) %G%
.Fl c Ar number |
.Fl n Ar number
.Oc
.Fl c Ar number |
.Fl n Ar number
.Oc
.Sh DESCRIPTION
The
.Nm tail
.Sh DESCRIPTION
The
.Nm tail
data to be appended to the input.
The
.Fl f
data to be appended to the input.
The
.Fl f
-option is ignored on pipes but not on FIFO's.
+option is ignored if the standard input is a pipe, but not if it is a FIFO.
.It Fl n Ar number
The location is
.Ar number
.It Fl n Ar number
The location is
.Ar number
option is to display all of the input.
.El
.Pp
option is to display all of the input.
.El
.Pp
+If more than a single file is specified, each file is preceded by a
+header consisting of the string
+.Dq ==> XXX <==
+where
+.Dq XXX
+is the name of the file.
+.Pp
The
.Nm tail
utility exits 0 on success, and >0 if an error occurs.
The
.Nm tail
utility exits 0 on success, and >0 if an error occurs.
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)tail.c 5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)tail.c 5.8 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#endif /* not lint */
#include <sys/types.h>
FILE *fp;
long off;
enum STYLE style;
FILE *fp;
long off;
enum STYLE style;
usage(); \
off = strtol(optarg, &p, 10) * (units); \
if (*p) \
usage(); \
off = strtol(optarg, &p, 10) * (units); \
if (*p) \
- err("illegal offset -- %s", optarg); \
+ err(1, "illegal offset -- %s", optarg); \
switch(optarg[0]) { \
case '+': \
if (off) \
switch(optarg[0]) { \
case '+': \
if (off) \
- if (fname = *argv) {
- if ((fp = fopen(fname, "r")) == NULL)
- ierr();
- } else {
+ if (*argv)
+ for (first = 1; fname = *argv++;) {
+ if ((fp = fopen(fname, "r")) == NULL) {
+ ierr();
+ continue;
+ }
+ if (argc > 1) {
+ (void)printf("%s==> %s <==\n",
+ first ? "" : "\n", fname);
+ first = 0;
+ }
+
+ if (rflag)
+ reverse(fp, style, off, &sb);
+ else
+ forward(fp, style, off, &sb);
+ }
+ else {
fp = stdin;
fname = "stdin";
fp = stdin;
fname = "stdin";
- if (fstat(fileno(fp), &sb))
- ierr();
+ if (fstat(fileno(fp), &sb)) {
+ ierr();
+ exit(1);
+ }
- /*
- * Determine if input is a pipe. 4.4BSD will set the SOCKET
- * bit in the st_mode field for pipes. Fix this then.
- */
- if (lseek(fileno(fp), 0L, SEEK_CUR) == -1 && errno == ESPIPE) {
- errno = 0;
- fflag = 0; /* POSIX.2 requires this. */
- }
+ /*
+ * Determine if input is a pipe. 4.4BSD will set the SOCKET
+ * bit in the st_mode field for pipes. Fix this then.
+ */
+ if (lseek(fileno(fp), 0L, SEEK_CUR) == -1 && errno == ESPIPE) {
+ errno = 0;
+ fflag = 0; /* POSIX.2 requires this. */
+ }
- if (rflag)
- reverse(fp, style, off, &sb);
- else
- forward(fp, style, off, &sb);
+ if (rflag)
+ reverse(fp, style, off, &sb);
+ else
+ forward(fp, style, off, &sb);
+ }
/* Malloc space for dash, new option and argument. */
len = strlen(*argv);
if ((start = p = malloc(len + 3)) == NULL)
/* Malloc space for dash, new option and argument. */
len = strlen(*argv);
if ((start = p = malloc(len + 3)) == NULL)
- err("%s", strerror(errno));
+ err(1, "%s", strerror(errno));
*p++ = 'n';
break;
default:
*p++ = 'n';
break;
default:
- err("illegal option -- %s", *argv);
+ err(1, "illegal option -- %s", *argv);
}
*p++ = *argv[0];
(void)strcpy(p, ap);
}
*p++ = *argv[0];
(void)strcpy(p, ap);