delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/05/15:09:25

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: "Gary R. Van Sickle" <g DOT r DOT vansickle AT worldnet DOT att DOT net>
To: "'Mailing List: CygWin'" <cygwin AT cygwin DOT com>
Subject: RE: BUG: alternatives
Date: Sat, 5 Nov 2005 14:09:11 -0600
Message-ID: <001201c5e244$c9e50490$020aa8c0@DFW5RB41>
MIME-Version: 1.0
In-Reply-To: <436CF5E9.30106@cwilson.fastmail.fm>
X-IsSubscribed: yes

> From:  Charles Wilson
> Sent: Saturday, November 05, 2005 12:12 PM
> To: Mailing List: CygWin
> Subject: Re: BUG: alternatives
> 
> Gary R. Van Sickle wrote:
> > More investigation reveals that it's textmode mounts that 
> alternatives 
> > doesn't like, not necessarily (although almost certainly as 
> well as) 
> > \r\n line endings.
> > 
> 
> I'm pretty sure the problem is here:
> 
>      if (read(fd, buf, sb.st_size) != sb.st_size) {
>          close(fd);
>          fprintf(stderr, _("failed to read %s: %s\n"), path,
>                  strerror(errno));
>          return 1;
>      }
> 
> Since one effect of 'textmode' conversions is that the 
> bytecount "read" 
> differs from the size reported by the filesystem, textmode 
> files will always fail this test.
>

Ok, yep.

> (1) I could remove this test -- but then you lose the error 
> checking it's attempting to do: make sure the entire file was 
> read into buf, and nothing was lost.
> 

I'm not sure the test is actually valid anyway.  IIRC (and I may not, POSIX
may prove me wrong here), there's no guarantee that read() will return the
number of bytes you requested, so at a minium to make this 100% correct
you'd have to do something like this:

// Read entire file
while(read(...) != 0)
{
}

// Check if there was a read() failure or if it just ran out of bytes to
read.
[...]

> (2) I could always open the file in binmode, and change the 
> parseLine routine to ignore trailing '\r' on each line. 
> (We'll assume that no alternatives config file will ever 
> contain a vertical-feed character).
> 
> Suggestions?

Something like (2) is the only way to do things correctly under any and all
circumstances.  What I usually do is accept either an '\r' or an '\n' as an
EOL character, and then ignore blank lines.  That way, whichever combination
of '\r's and '\n's you have, even abberations like '\r\r\n' which
occaisionally show up, you can read it with no problem.

-- 
Gary R. Van Sickle
 


--
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/

- Raw text -


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