From 3f968459bfe541032bb6892348dd83cb16e0a1bb Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?=
Date: Sat, 4 Jul 2009 01:19:00 +0100 Subject: [PATCH] make -u unbuffer input files as per the documentation * sed/execute.c: call setvbuf() to turn off input buffering * sed/sed.c: rename unbuffered_output to more accurate unbuffered * sed/sed.h: ditto --- sed/execute.c | 8 ++++++-- sed/sed.c | 4 ++-- sed/sed.h | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sed/execute.c b/sed/execute.c index 6fbfff6..66cb809 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -557,7 +557,7 @@ static inline void flush_output(fp) FILE *fp; { - if (fp != stdout || unbuffered_output) + if (fp != stdout || unbuffered) ck_fflush(fp); } @@ -783,7 +783,11 @@ open_next_file(name, input) panic(_("couldn't open temporary file %s: %s"), input->out_file_name, strerror(errno)); } else - output_file.fp = stdout; + { + if (input->fp && unbuffered) + setvbuf (input->fp, NULL, _IONBF, 0); + output_file.fp = stdout; + } } diff --git a/sed/sed.c b/sed/sed.c index d9a238f..723958d 100644 --- a/sed/sed.c +++ b/sed/sed.c @@ -61,7 +61,7 @@ char *program_name; int extended_regexp_flags = 0; /* If set, fflush(stdout) on every line output. */ -bool unbuffered_output = false; +bool unbuffered = false; /* If set, don't write out the line unless explicitly told to */ bool no_default_output = false; @@ -307,7 +307,7 @@ main(argc, argv) break; case 'u': - unbuffered_output = true; + unbuffered = true; break; case 'v': diff --git a/sed/sed.h b/sed/sed.h index d657a42..6b4101d 100644 --- a/sed/sed.h +++ b/sed/sed.h @@ -211,8 +211,9 @@ extern void fmt P_ ((const char *line, const char *line_end, int max_length, FIL extern int extended_regexp_flags; -/* If set, fflush(stdout) on every line output. */ -extern bool unbuffered_output; +/* If set, fflush(stdout) on every line output, + and turn off stream buffering on inputs. */ +extern bool unbuffered; /* If set, don't write out the line unless explicitly told to. */ extern bool no_default_output; -- 1.6.2.5