On 5/4/21 2:31 AM, Koichi Murase wrote:
I'm still thinking about whether it is possible to use buffered read
in more cases of mapfile.
(1) Suggestion: use buffered read for a regular file for delim != '\n'?
It won't work on any system that doesn't return -1/ESPIPE when you try
to lseek on a terminal device.
I found a related interesting discussion in a FreeBSD mailing list:
https://lists.freebsd.org/pipermail/freebsd-hackers/2011-November/036863.html
The BUGS section mentioned in this FreeBSD discussion can be found on
the FreeBSD man page:
https://www.freebsd.org/cgi/man.cgi?query=lseek&sektion=2
lseek(2) may succeed on non-seekable streams including some terminal
device (mentioned in Chet's reply) and a tape device (mentioned in the
above FreeBSD discussion).
Let's take a step back. I think we can make the code simpler and still
handle all the cases we need to. I don't think tape devices are worth
worrying about.
The issue with the BSDs and terminal devices is that the current code
only checks for -1/ESPIPE, but they return a different value for errno
(EINVAL? I forget.) I believe AIX returns something else. Rather than
check for specific errno values, we can just decide not to buffer input
if lseek fails for any reason.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/