X-Spam-Check-By: sourceware.org DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=rph6syWSiV2uevnGqMVKd548+Myi65E+/vyveRuiMrTMBJNZCv6WAjWognpNvECQMTvrPffqnwF/Z2QdXkORMb+CWZ0p66LBJrqQzwg30uhqiARUSVZaNBlJfUHW5QEFIkGtLlJVZvAo/f5OKmYUw/SqKCCjRNoUQtirBTVMil4= Message-ID: Date: Thu, 22 Feb 2007 12:37:24 -0500 From: "Lev Bishop" To: cygwin AT cygwin DOT com Subject: Re: Why binary mode? In-Reply-To: <45DDC06C.8050702@huarp.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <45DD6C91 DOT 5040406 AT hima DOT com> <45DD8A8F DOT 2050406 AT hima DOT com> <45DDC06C DOT 8050702 AT huarp DOT harvard DOT edu> Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On 2/22/07, Norton Allen wrote: > 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 > 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). It has been discussed to add a cygwin-local cat --text option, but rejected on the basis that since it would be cygwin-only and nonstandard, one might as well use the equally nonstandard d2u instead of cat. I believe there was at one point some attempt to get such an option upstream, but upstream resisted this. I'm sure this is mentionned in the archives somewhere. Lev -- 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/