[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?
From: |
Chet Ramey |
Subject: |
Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read? |
Date: |
Tue, 4 May 2021 09:28:04 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 |
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 chet@case.edu http://tiswww.cwru.edu/~chet/
- Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Koichi Murase, 2021/05/02
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Chet Ramey, 2021/05/03
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Chet Ramey, 2021/05/03
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Koichi Murase, 2021/05/03
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Koichi Murase, 2021/05/04
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?,
Chet Ramey <=
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Koichi Murase, 2021/05/04
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Chet Ramey, 2021/05/04
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Koichi Murase, 2021/05/07
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Chet Ramey, 2021/05/07
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Koichi Murase, 2021/05/07
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Chet Ramey, 2021/05/09
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Koichi Murase, 2021/05/09
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Robert Elz, 2021/05/04
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Chet Ramey, 2021/05/04
- Re: Why does "mapfile -d delim" (delim != '\n') use unbuffered read?, Andreas Schwab, 2021/05/04