public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re:File reading problem with -mno-cygwin
@ 2002-09-04  7:00 jdhagen
  2002-09-04  8:27 ` File " Andrew DeFaria
  0 siblings, 1 reply; 7+ messages in thread
From: jdhagen @ 2002-09-04  7:00 UTC (permalink / raw)
  To: cygwin

As Corinna mentioned, opening the file in binary
mode would eliminate the problem.

The data file "sf" actually contains a byte 0x1A that
is interpreted in text mode on DOS / Windows
systems as end-of-file.

In binary mode, this won't be interpreted as end-
of-file.


Joe



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: File reading problem with -mno-cygwin
  2002-09-04  7:00 Re:File reading problem with -mno-cygwin jdhagen
@ 2002-09-04  8:27 ` Andrew DeFaria
  2002-09-04 12:41   ` Andrew DeFaria
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew DeFaria @ 2002-09-04  8:27 UTC (permalink / raw)
  To: cygwin

jdhagen@chorus.net wrote:

> As Corinna mentioned, opening the file in binary mode would eliminate 
> the problem.
>
> The data file "sf" actually contains a byte 0x1A that is interpreted 
> in text mode on DOS / Windows
> systems as end-of-file.
>
> In binary mode, this won't be interpreted as end-of-file.

Thanks. Actually I figured this out about 1 - 2 hours after I posted. I 
still have some other problems in my process but this one that I 
isolated has been resolved.




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: File reading problem with -mno-cygwin
  2002-09-04  8:27 ` File " Andrew DeFaria
@ 2002-09-04 12:41   ` Andrew DeFaria
  2002-09-04 20:53     ` Joe Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew DeFaria @ 2002-09-04 12:41 UTC (permalink / raw)
  To: cygwin

Andrew DeFaria wrote:

> jdhagen@chorus.net wrote:
>
>> As Corinna mentioned, opening the file in binary mode would eliminate 
>> the problem.
>>
>> The data file "sf" actually contains a byte 0x1A that is interpreted 
>> in text mode on DOS / Windows
>> systems as end-of-file.
>>
>> In binary mode, this won't be interpreted as end-of-file.
>
> Thanks. Actually I figured this out about 1 - 2 hours after I posted. 
> I still have some other problems in my process but this one that I 
> isolated has been resolved.

One question remains however and that is why would it work in Cygwin but 
not in -mno-cygwin? My theory is that opening a file with "r" under 
Cygwin is equivalent to "rb".




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: File reading problem with -mno-cygwin
  2002-09-04 12:41   ` Andrew DeFaria
@ 2002-09-04 20:53     ` Joe Hagen
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Hagen @ 2002-09-04 20:53 UTC (permalink / raw)
  To: cygwin

Andrew DeFaria wrote:
> 
> One question remains however and that is why would it work in Cygwin
> but not in -mno-cygwin? My theory is that opening a file with "r"
> under Cygwin is equivalent to "rb".

Andrew,

Using the -mno-cygwin option directs the code to link
against MSVCRT.DLL, so Cygwin is bypassed completely.

If you examine the Microsoft C runtime source, you'll see that
they explicitly check for a CTRL-Z as an end-of-file marker
if a file is opened in text mode.  I think this behavior, along with
the LF to CRLF conversions, is an extension that is done by
Microsoft if you're in text mode.  

I don't believe the Cygwin runtime treats CTRL-Z as a special case,
which explains the difference.

The CTRL-Z as EOF was a leftover from CP/M, but got propgated
into MSDOS/Windows.


Joe


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: File reading problem with -mno-cygwin
@ 2002-09-04 12:53 Richard Campbell
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Campbell @ 2002-09-04 12:53 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'

>One question remains however and that is why would it work in Cygwin but 
>not in -mno-cygwin? My theory is that opening a file with "r" under 
>Cygwin is equivalent to "rb".

Not in all situations.  Under cygwin, opening with "r" may be equivalent
to "rb", or it may not.  Depends on how your filesystem was mounted, some
environment options, and a few other factors.

-Richard Campbell.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: File reading problem with -mno-cygwin
  2002-09-03 19:33 Andrew DeFaria
@ 2002-09-04  2:01 ` Corinna Vinschen
  0 siblings, 0 replies; 7+ messages in thread
From: Corinna Vinschen @ 2002-09-04  2:01 UTC (permalink / raw)
  To: cygwin

On Tue, Sep 03, 2002 at 07:33:20PM -0700, Andrew DeFaria wrote:
>  if ((fp = fopen ("sf", "r")) == NULL) {

Try          fopen ("sf", "rb")

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* File reading problem with -mno-cygwin
@ 2002-09-03 19:33 Andrew DeFaria
  2002-09-04  2:01 ` Corinna Vinschen
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew DeFaria @ 2002-09-03 19:33 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 3276 bytes --]

OK, this one's really got me stumped and I need to resolve this quickly. 
I'd really appreciate any help that can be offered. I'm getting 
difference in the behavior of fread (I believe) depending on whether 
I've compiled with -mno-cygwin or not. I think this example is simple 
enough. Here's the code:

#include <stdlib.h>
#include <stdio.h>

#define BUFLEN (1 << 8)

int main (void) {
  FILE *fp;
  unsigned char buf [BUFLEN];
  long bytes_processed = 0;
  int bytes_read;
  int i = 0;
  int j = 0;

  if ((fp = fopen ("sf", "r")) == NULL) {
    printf ("Unable to open sf file\n");
    exit (1);
  } /* if */

  while ((bytes_read = fread (buf, 1, BUFLEN, fp)) > 0) {
    j = j + bytes_read;
    printf ("Pass #%d; %d bytes read this pass; %d total bytes processed 
so far\n", ++i, bytes_read, j);
  } /* while */
}

Pretty simple eh? Here's how I compile it:

$ gcc foo.c -o foo
$ gcc -mno-cygwin foo.c -o foo.no_cygwin

This little example requires the attached file, named sf. It's merely 
/etc/group packed into a file format with some headers and a checksum. 
Those additions add binary data to the file which I think is causing the 
problems in some strange way because if I use just a plain ASCII copy of 
/etc/group as the "sf" file it works OK. However with the attached "sf" 
file (with binary data in it) I get the following differing results:

$ foo
Pass #1; 256 bytes read this pass; 256 total bytes processed so far
Pass #2; 256 bytes read this pass; 512 total bytes processed so far
Pass #3; 256 bytes read this pass; 768 total bytes processed so far
Pass #4; 256 bytes read this pass; 1024 total bytes processed so far
Pass #5; 256 bytes read this pass; 1280 total bytes processed so far
Pass #6; 256 bytes read this pass; 1536 total bytes processed so far
Pass #7; 256 bytes read this pass; 1792 total bytes processed so far
Pass #8; 256 bytes read this pass; 2048 total bytes processed so far
Pass #9; 256 bytes read this pass; 2304 total bytes processed so far
Pass #10; 256 bytes read this pass; 2560 total bytes processed so far
Pass #11; 256 bytes read this pass; 2816 total bytes processed so far
Pass #12; 4 bytes read this pass; 2820 total bytes processed so far
$ foo.no_cygwin
Pass #1; 256 bytes read this pass; 256 total bytes processed so far
Pass #2; 256 bytes read this pass; 512 total bytes processed so far
Pass #3; 256 bytes read this pass; 768 total bytes processed so far
Pass #4; 256 bytes read this pass; 1024 total bytes processed so far
Pass #5; 256 bytes read this pass; 1280 total bytes processed so far
Pass #6; 256 bytes read this pass; 1536 total bytes processed so far
Pass #7; 256 bytes read this pass; 1792 total bytes processed so far
Pass #8; 256 bytes read this pass; 2048 total bytes processed so far
Pass #9; 256 bytes read this pass; 2304 total bytes processed so far
Pass #10; 256 bytes read this pass; 2560 total bytes processed so far
Pass #11; 252 bytes read this pass; 2812 total bytes processed so far

As you can see, with -mno-cygwin I only make 11 passes of the loop and 
only read a total of 2812 bytes. However without -mno-cygwin I make 12 
passes and read a total of 2820 bytes. The question is why?!? The other 
question is: Is there a way to get the -mno-cygwin to behave properly.

Thanks in advance.

[-- Attachment #2: sf --]
[-- Type: application/octet-stream, Size: 2820 bytes --]

[-- Attachment #3: Type: text/plain, Size: 214 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-09-05  3:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-04  7:00 Re:File reading problem with -mno-cygwin jdhagen
2002-09-04  8:27 ` File " Andrew DeFaria
2002-09-04 12:41   ` Andrew DeFaria
2002-09-04 20:53     ` Joe Hagen
  -- strict thread matches above, loose matches on Subject: below --
2002-09-04 12:53 Richard Campbell
2002-09-03 19:33 Andrew DeFaria
2002-09-04  2:01 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).