Skip to contentSkip to conversation

input: Replace stdin_state.canon with bufferable

PATCH New Herbert Xu 1 participant 1 message May 3

lore
Share & tools
lore

Herbert Xu

author
#0 lore raw

PATCH 1/1 input: Replace stdin_state.canon with bufferable

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.

src/input.c +10 -6
index 591f28a..0fb2f18 100644
@@ -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)
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt