File reading problem with -mno-cygwin

Andrew DeFaria ADeFaria@Salira.com
Tue Sep 3 19:33:00 GMT 2002


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sf
Type: application/octet-stream
Size: 2820 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20020903/61bfcb9b/attachment.obj>
-------------- next part --------------
--
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/


More information about the Cygwin mailing list