From e8a986ae95d322bf1d0df30c3516e0d283ce1d3d Mon Sep 17 00:00:00 2001 From: jh Date: Wed, 2 Apr 2014 17:10:17 +0000 Subject: [PATCH] MFC r251565: Print file names without stdio buffering to avoid mixing buffered and unbuffered ouput. PR: bin/176886 git-svn-id: svn://svn.freebsd.org/base/stable/9@264047 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.bin/tail/extern.h | 1 + usr.bin/tail/forward.c | 4 ++-- usr.bin/tail/misc.c | 14 ++++++++++++++ usr.bin/tail/tail.c | 4 +--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/usr.bin/tail/extern.h b/usr.bin/tail/extern.h index 16a3e19a4..dfc63d074 100644 --- a/usr.bin/tail/extern.h +++ b/usr.bin/tail/extern.h @@ -67,5 +67,6 @@ void ierr(const char *); void oerr(void); int mapprint(struct mapinfo *, off_t, off_t); int maparound(struct mapinfo *, off_t); +void printfn(const char *, int); extern int Fflag, fflag, qflag, rflag, rval, no_files; diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c index e1e0638d7..71f38f93f 100644 --- a/usr.bin/tail/forward.c +++ b/usr.bin/tail/forward.c @@ -243,7 +243,7 @@ show(file_info_t *file) while ((ch = getc(file->fp)) != EOF) { if (last != file && no_files > 1) { if (!qflag) - (void)printf("\n==> %s <==\n", file->file_name); + printfn(file->file_name, 1); last = file; } if (putchar(ch) == EOF) @@ -320,7 +320,7 @@ follow(file_info_t *files, enum STYLE style, off_t off) active = 1; n++; if (no_files > 1 && !qflag) - (void)printf("\n==> %s <==\n", file->file_name); + printfn(file->file_name, 1); forward(file->fp, file->file_name, style, off, &file->st); if (Fflag && fileno(file->fp) != STDIN_FILENO) n++; diff --git a/usr.bin/tail/misc.c b/usr.bin/tail/misc.c index 3b21e4e3f..69443257f 100644 --- a/usr.bin/tail/misc.c +++ b/usr.bin/tail/misc.c @@ -113,3 +113,17 @@ maparound(struct mapinfo *mip, off_t offset) return (0); } + +/* + * Print the file name without stdio buffering. + */ +void +printfn(const char *fn, int print_nl) +{ + + if (print_nl) + WR("\n", 1); + WR("==> ", 4); + WR(fn, strlen(fn)); + WR(" <==\n", 5); +} diff --git a/usr.bin/tail/tail.c b/usr.bin/tail/tail.c index a40646abd..091a47c7f 100644 --- a/usr.bin/tail/tail.c +++ b/usr.bin/tail/tail.c @@ -203,10 +203,8 @@ main(int argc, char *argv[]) continue; } if (argc > 1 && !qflag) { - (void)printf("%s==> %s <==\n", - first ? "" : "\n", fn); + printfn(fn, !first); first = 0; - (void)fflush(stdout); } if (rflag) -- 2.45.0