[PATCH] input: Replace stdin_state.canon with bufferable
Herbert Xu <[email protected]> Sun, 3 May 2026 12:30:44 +0800
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
The field canon is never used except to check whether the fd 0 is bufferable. Replace it with a bufferable flag instead. Also move the termios struct onto the stack since it's never used again after retrieving the canon field. Signed-off-by: Herbert Xu <[email protected]> diff --git a/src/input.c b/src/input.c index 591f28a..0fb2f18 100644 --- a/src/input.c +++ b/src/input.c @@ -64,11 +64,10 @@ MKINIT struct stdin_state { - tcflag_t canon; off_t seekable; - struct termios tios; int pip[2]; int pending; + tcflag_t bufferable; }; MKINIT struct parsefile basepf; /* top level input file */ @@ -133,12 +132,17 @@ POSTEXITRESET { void input_init(void) { struct stdin_state *st = &stdin_state; + struct termios tios; int istty; - istty = tcgetattr(0, &st->tios) + 1; - st->seekable = istty ? 0 : lseek(0, 0, SEEK_CUR) + 1; - st->canon = istty ? st->tios.c_lflag & ICANON : 0; + istty = tcgetattr(0, &tios) + 1; stdin_istty = istty; + if (istty) + st->bufferable = tios.c_lflag & ICANON; + else { + st->seekable = lseek(0, 0, SEEK_CUR) + 1; + st->bufferable = !!st->seekable; + } } static bool stdin_bufferable(void) @@ -148,7 +152,7 @@ static bool stdin_bufferable(void) if (stdin_istty < 0) input_init(); - return st->canon || st->seekable; + return st->bufferable; } static void flush_tee(void *buf, int nr, int pending) -- Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt