+ if (flags & FORCE7BIT && ! isascii((unsigned char) ch)) {
+ putchar ('?');
+ } else {
+ putchar (ch);
+ }
+}
+
+/* linefeed_typed() makes a single read(2) from stdin and returns true
+ * if a linefeed character is amongst the characters read.
+ * A read error is treated as if linefeed wasn't typed.
+ *
+ * Typing on a TTY can cause read() to return data without typing Enter
+ * by using the TTY's EOF character instead, normally ASCII EOT, Ctrl-D.
+ * The linefeed can also be escaped with the TTY's LNEXT character,
+ * normally ASCII SYN, Ctrl-V, by typing Ctrl-V Ctrl-J.
+ * It's not possible to distinguish between the user typing a buffer's
+ * worth of characters and then EOT, or more than the buffer can hold.
+ * Either way, the result depends on ASCII LF, either from typing Enter
+ * or an escaped Ctrl-J, being amongst the read characters.
+ */
+static bool linefeed_typed(void)
+{
+ char buf[128];
+ ssize_t n;
+
+ n = read(0, buf, sizeof buf);
+ if (n == -1) {
+ advise("stdin", "read");
+ return false; /* Treat as EOF. */
+ }
+
+ return memchr(buf, '\n', n);