Subject: FILE I/O: fread() fails for GCC(Cygnus & DJ's) and TC++
From: [email-masked] (Rich Kucera)

25 Apr 1997 12:30:46 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="IMA.Boundary.076379168"
Original-To: [email-masked]
Original-Sender: [email-masked]

--IMA.Boundary.076379168
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Description: cc:Mail note part

     On Linux & MPRAS,  the sample program listed below manages to
     read through all thirty POINT structures with no problems. 
     
     The program won't port however,  because it appears that
     any DOS-based (FAT?) compiler (Cygnus GCC & DJ's GCC and Turbo C),
     creates a binary that quits halfway through the data(15 points read).
     
     I'm probably missing something about file I/O,  or it
     could be some low-level file I/O problem.  I don't know,  help.
     
     Visual Basic had no problem with this data.   The gnu-win32 utilities
     such as HEAD.EXE ALSO QUIT after getting about 95 bytes into this
     data.  
     
     I checked the representation for signed short for every compiler
     tested and they all use 2 BYTES,  so no problem there?  I used
     sizeof().
     
     There should be 180 bytes composing 30 POINT structures.

The data follows here and is attached in raw form in a zip file:

     Here is the test program(also attached):

#include <stdio.h>

typedef struct POINT {
  signed short CODE, LAT, LON;   
} POINT;

main(argc, argv)
int argc;    
char *argv[];
{  

  int num_points_read;
  POINT NEWPOINT;
  FILE *INFILE;
  if( ( INFILE = fopen( "data.pnt", "r" ) ) == (FILE *) NULL ) {
    printf("Can't open %s.\n", "data.pnt");
    exit( 2 ); 
  }
  num_points_read = 0;

  while ( fread(&NEWPOINT, sizeof(POINT), 1, INFILE) == 1 ) {

    num_points_read++;
  }                 /* while () */

  printf("\n%d points read from %s\n\n",
       num_points_read, 
         "data.pnt");

  if (INFILE != NULL) {    fclose(INFILE); }
    exit( 0 ); 
     
     }

     /* THE END */

--IMA.Boundary.076379168
Content-Type: application/octet-stream; name="gena.c"
Content-Transfer-Encoding: base64
Content-Description: Unknown data type
Content-Disposition: attachment; filename="gena.c"

--IMA.Boundary.076379168
Content-Type: application/octet-stream; name="data.zip"
Content-Transfer-Encoding: base64
Content-Description: Unknown data type
Content-Disposition: attachment; filename="data.zip"

UEsDBBQAAAAIAId5mCJdcZG5lwAAALQAAAAIAAAAZGF0YS5wbnQdzC0PQWEchvH/c+bseiYI
oi5QFEEQbaIuiarkE/gIJIGkSb6BoBzFGcHL5iUIBEFi58w95dpvd7idlf0gDSzv+6mzrO/J
X7ppxt50tLxoq09a2u80/22oV+raz9TkC1X5REU9UtKypyjvKMgxOXmNlyNCPUc4ecU3CWzJ
R13wSJzNuakzDkloU2J5ogY2ZquO2GgZavkBUEsBAjILFAAAAAgAh3mYIl1xkbmXAAAAtAAA
AAgAAAAAAAAAAAAgALaBAAAAAGRhdGEucG50UEsFBgAAAAABAAEANgAAAL0AAAAAAA==
--IMA.Boundary.076379168--
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".