henman | 17 Jul 01:57

Under Cygwin ZSH, "diff -" fails unless forced into text mode


I saw the following question at the cygwin group and figure that it is a zsh related question.   

I tried to see if setopt NO_MULTIOS had any bearing on the problem, but it didn't.

The question follows:

--------  extract
From: <Gerald.Williams <at> infineon.com>
To: <cygwin <at> cygwin.com>
Date: Wed, 16 Jul 2008 23:19:02 +0200
Subject: Under Cygwin ZSH, "diff -" fails unless forced into text mode

Does anyone know why, under Cygwin ZSH, the following fails?

 zsh% cat foo | diff - foo
 diff: -: Illegal seek
 zsh%

It passes if I force it into text mode:

 zsh% cat foo | diff -a - foo
 zsh%

And of course it works in bash:

 bash% cat foo | diff - foo
 bash%

It doesn't matter whether I'm running under a console window or
(Continue reading)

Peter Stephenson | 17 Jul 20:56
Favicon

Re: Under Cygwin ZSH, "diff -" fails unless forced into text mode

On Thu, 17 Jul 2008 08:59:29 +0900
henman <at> tech.email.ne.jp wrote:
> I saw the following question at the cygwin group and figure that it is
> a zsh related question.   
> 
> I tried to see if setopt NO_MULTIOS had any bearing on the problem,
> but it didn't.
> 
> The question follows:
> 
> 
> --------  extract
> From: <Gerald.Williams <at> infineon.com>
> To: <cygwin <at> cygwin.com>
> Date: Wed, 16 Jul 2008 23:19:02 +0200
> Subject: Under Cygwin ZSH, "diff -" fails unless forced into text mode
> 
> Does anyone know why, under Cygwin ZSH, the following fails?
> 
>  zsh% cat foo | diff - foo
>  diff: -: Illegal seek
>  zsh%

The short, but unsatisfactory, answer is that it's not required to
work.  diff expects to have a seekable file, for which a pipe doesn't
necessarily qualify: it depends partly on the OS and also partly on how
far back you need to seek, so you sometimes get away with it.

This is why zsh has both <(...) and =(...) process subtitution forms:
the second is a bit less efficient because it's guaranteed to expand to
(Continue reading)

Gerald.Williams | 17 Jul 23:01

RE: Under Cygwin ZSH, "diff -" fails unless forced into text mode

Peter Stephenson wrote:
>>  zsh% cat foo | diff - foo
>>  diff: -: Illegal seek
>>  zsh%
>
> The short, but unsatisfactory, answer is that it's not required to
> work.  diff expects to have a seekable file, for which a pipe doesn't
> necessarily qualify: it depends partly on the OS and also partly on how
> far back you need to seek, so you sometimes get away with it.

I'd call expecting stdin to be seekable a bug in diff,
although presumably ZSH-USERS isn't the right forum for
that discussion. (I guess HELP-GNU-UTILS would be.)

>> It passes if I force it into text mode:
>>
>>  zsh% cat foo | diff -a - foo
>>  zsh%
>
> There's some Cygwin-specific code in main.c to force read-only files
> into text mode.  This is a fairly murky area and I have no idea how that
> affects pipes.

I'm not sure where you're headed with that one, but it
appears that ZSH is making the pipe appear as a binary
stream in this case. Forcing it *back* to text is what
fixes the problem.

I know there are similar issues with UTF-8 encodings on
Linux, and I have at times worked around it by setting
(Continue reading)

Peter Stephenson | 18 Jul 10:52
Favicon

Re: Under Cygwin ZSH, "diff -" fails unless forced into text mode

On Thu, 17 Jul 2008 23:01:39 +0200
<Gerald.Williams <at> infineon.com> wrote:
> > There's some Cygwin-specific code in main.c to force read-only files
> > into text mode.  This is a fairly murky area and I have no idea how that
> > affects pipes.
> 
> I'm not sure where you're headed with that one, but it
> appears that ZSH is making the pipe appear as a binary
> stream in this case. Forcing it *back* to text is what
> fixes the problem.

I meant I supect the code that sometimes fixes things up may well not be
kicking in in this case, but I don't understand it.  Cygwin needs to
do strange things and it's not clear to me why binary mode would make a
pipe harder to seek on than text mode; I would expect the opposite.

I don't even know how Cygwin expects you to set the mode on a pipe;
possibly with fcntl().

--

-- 
Peter Stephenson <pws <at> csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


Gmane