[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Read a fixed length of input each time
From: |
Andrew J. Schorr |
Subject: |
Re: Read a fixed length of input each time |
Date: |
Tue, 23 Jun 2020 09:03:11 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Tue, Jun 23, 2020 at 01:27:18AM -0600, arnold@skeeve.com wrote:
> It is fairly easy to write a C extension that would do this.
It should be quite trivial to do this. The get_file API makes it easy to open a
file or pipe or coprocess. For example, you can take a look at how the
gawkextlib select extension uses the get_file call in various functions such as
set_non_blocking() or input_fd(). Here's a simple example:
bash-4.2$ gawk -lselect 'BEGIN {print input_fd("/etc/passwd", "<")}'
3
bash-4.2$ strace -eopen gawk -lselect 'BEGIN {print input_fd("/etc/passwd",
"<")}'
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libsigsegv.so.2", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libreadline.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libmpfr.so.4", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libgmp.so.10", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
open("/proc/self/maps", O_RDONLY) = 3
open("/usr/lib64/gconv/gconv-modules.cache", O_RDONLY) = 3
open("/usr/lib64/gawk/select.so", O_RDONLY|O_CLOEXEC) = 3
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libgawkextlib.so.0", O_RDONLY|O_CLOEXEC) = 3
open("/etc/passwd", O_RDONLY) = 3
3
+++ exited with 0 +++
The only thing missing is a thin wrapper around the read() system call. Maybe I
should just add read() and write() to the select extension. It just didn't seem
terribly useful for awk scripts which typically use getline for input and
print/printf for output. What's the usage case? I thought maybe for socket I/O
it could be useful to have read and write, but we don't have a socket library
at this point...
Regards,
Andy
- Read a fixed length of input each time, Peng Yu, 2020/06/22
- Re: Read a fixed length of input each time, arnold, 2020/06/23
- Re: Read a fixed length of input each time,
Andrew J. Schorr <=
- Re: Read a fixed length of input each time, Neil R. Ormos, 2020/06/23
- Re: Read a fixed length of input each time, Andrew J. Schorr, 2020/06/23
- Re: Read a fixed length of input each time, Peng Yu, 2020/06/23
- Re: Read a fixed length of input each time, Andrew J. Schorr, 2020/06/23
- Re: Read a fixed length of input each time, Peng Yu, 2020/06/23
- Re: Read a fixed length of input each time, Andrew J. Schorr, 2020/06/23
- Re: Read a fixed length of input each time, Peng Yu, 2020/06/23
- RE: Read a fixed length of input each time, Tom Gray, 2020/06/23
- Re: Read a fixed length of input each time, Neil R. Ormos, 2020/06/23
- Re: Read a fixed length of input each time, Andrew J. Schorr, 2020/06/23