Subject: Re: cat(1) question: multiple "-"s
To: Steven M. Bellovin <smb@cs.columbia.edu>
From: Johnny Billquist <bqt@update.uu.se>
List: netbsd-users
Date: 04/18/2006 20:07:29
Steven M. Bellovin wrote:
> On Tue, 18 Apr 2006 19:31:13 +0200, Johnny Billquist <bqt@update.uu.se>
> wrote:
> 
>>Doh! And as others have already noted later, zsh don't do anything like 
>>this. It just concatenates the files, and feed the result to stdin.
>>
>>Hmm, I wonder if it wouldn't be possible to simulate eofs on a stream, 
>>but then present more data. I believe that is what really would be 
>>neccesary.
>>Thinking of it, I don't think that it's possible. The only stream that I 
>>know, that can do this, are ttys. Anyone?
> 
> If we had streams, and if pipes were streams, it could be done quite
> easily -- make sure there's a 0-length record present.  Otherwise, it's
> not particularly easy.  It would take a kernel multiplexor that you handed
> several files -- more likely, several file descriptors -- that would read
> the first until it ended, give EOF, then the next, etc.

Well, it also needs to signal eof at the end of each file, and then 
reset the status if another file exists, which to switch over to.

But I'm not sure about your thoughs... You need read() to return 0. I 
don't think a stream have the data stored in records. A stream will 
return as much data as exists, or until the read buffer is full. If no 
data exists, it will wait. It will only return 0 on a EOF situation.
That's what we want to access. I suspect this means that we need some 
oob data to tell that en EOF should be delivered here, or the 
implementation behind the read needs to be changed.
The whole point of a stream is that there isn't any structure to it, 
which includes the absence of a record concept.

But I might be wrong. It's been a long time since I was anywhere near 
that kind of code (back in 4.3BSD...).

A pipe can be wrapped in a stream, by the way, can it not? A stream is 
just distinguished by the fact that it have a FILE descriptor. When 
stdin is redirected to a pipe, it's still a stream?
Or am I confusing things a lot now?

	Johnny

-- 
Johnny Billquist                  || "I'm on a bus
                                   ||  on a psychedelic trip
email: bqt@update.uu.se           ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol