X-Spam-Check-By: sourceware.org
Message-ID: <45DDC06C.8050702@huarp.harvard.edu>
Date: Thu, 22 Feb 2007 11:10:20 -0500
From: Norton Allen <allen@huarp.harvard.edu>
User-Agent: Thunderbird 1.5.0.9 (Windows/20061207)
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: Re: Why binary mode?
References: <45DD6C91.5040406@hima.com> <45DD8A8F.2050406@hima.com> <ba40711f0702220753t216d8fbcs453e52c4414af21c@mail.gmail.com>
In-Reply-To: <ba40711f0702220753t216d8fbcs453e52c4414af21c@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Received-SPF: pass (ent.arp.harvard.edu: 24.61.82.50 is authenticated by a trusted mechanism)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

Lev Bishop wrote:
> On 2/22/07, Sven Severus wrote:
>> But in a textmode mounted directory, 'echo peng >p.txt' creates
>> a 6 byte long file containing 'p' 'e' 'n' 'g' '\r' '\n'.
>> OK, exactly as expected. Now I thought, 'cat p.txt' would open
>> this file for reading in textmode, according to the default rule.
>>
>> This is, what I expect, after reading the Cygwin FAQ:
>> "When processing in text mode, [...] written to the file [...]
>> you in fact get "Hello\r\n". Upon reading this combination,
>> the \r is removed [...]".
>> Why is it in fact not removed when reading with cat?
>
> Because cat is required by posix to read in binmode. Try, for example:
> $ echo peng >p.txt && read CO <p.txt && od -c <<<"$CO"
> 0000000   p   e   n   g  \n
> 0000005
Which apparently means that the original doc he referred to (Cygwin 
User's Guide, chapter "Text and Binary modes" ) should be updated. I 
think the fact that cat reads in binmode is surprising (though it makes 
sense if you think about it) so the behavior should be prominently 
noted. Certainly the shell idiom of using cat to read text files is 
widespread. Makes you wonder whether cat shouldn't have an option added 
to read in text mode (that'd be an upstream question).


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

