ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-apps/2001/04/22/18:52:15

Mailing-List: contact cygwin-apps-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-apps-owner AT sourceware DOT cygnus DOT com
List-Subscribe: <mailto:cygwin-apps-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-apps/>
List-Post: <mailto:cygwin-apps AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-apps-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/lists.html#faqs>
Delivered-To: mailing list cygwin-apps AT sources DOT redhat DOT com
Date: Sun, 22 Apr 2001 18:52:48 -0400
From: Christopher Faylor <cgf AT redhat DOT com>
To: cygapp <cygwin-apps AT cygwin DOT com>
Subject: Re: ash stdin mode is set to O_TEXT
Message-ID: <20010422185247.C25103@redhat.com>
Reply-To: cygwin-apps AT cygwin DOT com
Mail-Followup-To: cygapp <cygwin-apps AT cygwin DOT com>
References: <11216876326 DOT 20010421202556 AT logos-m DOT ru> <20010421131957 DOT B4033 AT redhat DOT com> <20010422135957 DOT O15499 AT cygbert DOT vinschen DOT de> <3AE2DBAC DOT 749E6F98 AT yahoo DOT com> <20010423003623 DOT W15499 AT cygbert DOT vinschen DOT de>
Mime-Version: 1.0
User-Agent: Mutt/1.3.11i
In-Reply-To: <20010423003623.W15499@cygbert.vinschen.de>; from cygwin-apps@cygwin.com on Mon, Apr 23, 2001 at 12:36:23AM +0200

On Mon, Apr 23, 2001 at 12:36:23AM +0200, Corinna Vinschen wrote:
>On Sun, Apr 22, 2001 at 09:25:00AM -0400, Earnie Boyd wrote:
>> Corinna Vinschen wrote:
>> > 
>> > On Sat, Apr 21, 2001 at 01:19:57PM -0400, Christopher Faylor wrote:
>> > > On Sat, Apr 21, 2001 at 08:25:56PM +0400, egor duda wrote:
>> > > >ash stdin mode is set to O_TEXT, so it's impossible to checkin/chechout
>> > > >binary files from cvs when CVS_RSH is sh script.
>> > > >
>> > > >maybe O_TEXT should be set only in interactive mode?  or shouldn't be
>> > > >set at all?
>> > >
>> > > Corinna and I have discussed this in the past.  The problem is that the
>> > > 'read' command should always be text mode whether it is interactive or
>> > > not.  Also, if sh is reading a shell script via:
>> > >
>> > > sh < foo
>> > >
>> > > the input should be in O_TEXT mode.
>> > >
>> > > But then, if ash is reading from a pipe, stdin should, IMO, be in binary
>> > > mode.
>> > 
>> > That's really tricky:
>> > 
>> >         sh < foo                O_TEXT?
>> >         cat foo | sh            O_BINARY?
>> > 
>> 
>> Correct, and from what I remember of the bash code it knows when it's
>> about to read/write from/to a pipe/redirect.  Wouldn't you just use the
>> appropriate setmode on the duplicated file handle?
>
>I'm not sure if I understand you right. Do you mean sth. like that:
>
>	struct stat s;
>	fstat(STDIN_FILENO, &s);
>	if (S_ISCHR(s.st_mode) || S_ISREG(s.st_mode))
>	  setmode(STDIN_FILENO, O_TEXT);
>	else
>	  setmode(STDIN_FILENO, O_BINARY);

Actually, the 'cat foo | sh' example should still default to text mode.
sh shouldn't interpret CRs when a pipe is opened.

I think what is really needed here is for sh to not use setmode at all.
It should probably set its stdin to binary and do the CR stripping itself.

cgf

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019