This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
FILE I/O: fread() fails for GCC(Cygnus & DJ's) and TC++
- To: gnu-win32 at cygnus dot com
- Subject: FILE I/O: fread() fails for GCC(Cygnus & DJ's) and TC++
- From: Rich dot Kucera at ccmail dot irs dot gov (Rich Kucera)
- Date: Thu, 24 Apr 1997 15:56:43 -0400
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:
begin 640 data.pnt
M 0 J"(7^ @ 2"'?^ 0 *"''^ @#[!VC^! #T!V#^ 0#P!UK^ 0#L!T_^
@#G
M!T?^ @#G!T3^ @#B!SS^ 0#@!SC^ @#A!S3^ 0#=!R_^ 0#<!RG^ @#:!R7^
M 0#6!QK^
@#3!P[^ 0#-!PC^ @#,!P7^! #,!P'^ @#'!_O] @##!_K] @"T
M!^O] 0"N!^/]
0"G!]O]!0"A!]/] 0"@!]/] @"<!]7] @"6!]+] 0"5!]/]
end
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 */
Unknown data type
Unknown data type