read -d no longer accepts NUL as line delimiter from tty

Martin D Kealey <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAN_U6MV-L_Zyj-eSgspL2iULUW6axrRWkydnc1q9i91mi4k6xA@mail.gmail.com>
When I go

    read -d '' VAR

it doesn't accept the line of input when I type the NUL byte (variously ^@,
^`, or ctrl-space depending on the keyboard).

It turns out that's because  _POSIX_VDISABLE is '\0' on my system; I
suspect that's typical, though I have seen systems where it's '\xff'.

So when delim is _POSIX_VDISABLE, simply switch back to the old method:

diff --git a/builtins/read.def b/builtins/read.def
index 70e08126d..c939e991e 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -627,7 +627,7 @@ read_builtin (WORD_LIST *list)

          ttset = ttattrs;
+
+         #ifdef _POSIX_VDISABLE
+         const int vdis = _POSIX_VDISABLE;
+         #else
+         const int vdis = pathconf("/dev/tty", _PC_VDISABLE);
+         #endif

-         if (nchars > 0)
+         if (nchars > 0 || delim == vdis)
            rc = silent ? ttfd_cbreak (fd, &ttset) : ttfd_onechar (fd,
&ttset);
-         else          /* delim != '\n' */
+         else          /* delim ∉ {'\n', _POSIX_VDISABLE} */
            {

-Martin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.