Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 From: "Gary R. Van Sickle" To: "'Mailing List: CygWin'" Subject: RE: BUG: alternatives Date: Sat, 5 Nov 2005 14:09:11 -0600 Message-ID: <001201c5e244$c9e50490$020aa8c0@DFW5RB41> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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/