pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: abysmal check-portability speed



On Thu, 26 Sep 2024, Robert Elz wrote:

>  |    $ printf "foo\nbar\n" | mksh -c 'read -n 128 foo; echo $foo'
>  |    foo bar
>
>That looks like a bug to me

No, it works *exactly* as documented.

>, though the mksh doc for read -n is fairly pathetic

Huh?

    -n z   Instead of reading till end-of-line, read up to z bytes but
	   return as soon as any bytes are read, e.g. from a slow ter‐
	   minal device, or if EOF or a timeout occurs.

What exactly is unclear with that?

If you enter 8 bytes (f o o \n b a r \n EOF) into a 'read -n 128',
the read(2) syscall will be run with an argument of 128 and return
those 8 bytes, so that is the result of such.

$ printf 'foo\nbar\n' | mksh -c 'read -n 128 foo; echo $foo'
foo bar
$ (printf 'foo\n'; printf 'bar\n') | mksh -c 'read -n 128 foo; echo $foo'
foo

In the second example, the read(2) syscall will only return
those four octets.

>  |    $ printf "foo\nbar\n" | bash -c 'read -n 128 foo; echo $foo'
>  |    foo
>
>If/when we add -n, it will certainly act like that, and not:

That’s positively harmful.

Consider:

	$ (printf 'foo\nbar\n'; printf 'baz\n') | mksh -c '
	>         read -n 128 foo
	>         echo one: $foo
	>         read -n 128 foo
	>         echo two: $foo
	> '
	one: foo bar
	two: baz

If you make the first read builtin stop at the newline,
then you get:

	one: foo
	two: baz

The read builtin must retain correct position of the file
descriptor used at any time (the second “read -n 128 foo”
could be an external program instead, so no, you cannot
just buffer internally, and no you cannot (in general)
seek backwards either).

So, I fear that the method you want to implement is impossible.

bye,
//mirabilos
PS: Please keep me Cc’d on replies, I’m not subscribed to
    the list, bsiegert@ pointed out this thread to me.
-- 
(gnutls can also be used, but if you are compiling lynx for your own use,
there is no reason to consider using that package)
	-- Thomas E. Dickey on the Lynx mailing list, about OpenSSL


Home | Main Index | Thread Index | Old Index