www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/04/25/12:30:46

From: Rich DOT Kucera AT ccmail DOT irs DOT gov (Rich Kucera)
Subject: FILE I/O: fread() fails for GCC(Cygnus & DJ's) and TC++
25 Apr 1997 12:30:46 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <0009386C.1950.cygnus.gnu-win32@ccmail.irs.gov>
Mime-Version: 1.0
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

--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:
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 */
     
     
--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"

I2luY2x1ZGUgPHN0ZGlvLmg+Cgp0eXBlZGVmIHN0cnVjdCBQT0lOVCB7CiAgc2lnbmVkIHNo
b3J0IENPREUsIExBVCwgTE9OOyAgIAp9IFBPSU5UOwoKbWFpbihhcmdjLCBhcmd2KQoKaW50
IGFyZ2M7ICAgIApjaGFyICphcmd2W107Cgp7ICANCg0KICBpbnQgbnVtX3BvaW50c19yZWFk
OwogIFBPSU5UIE5FV1BPSU5UOwoKICBGSUxFICpJTkZJTEU7CgogIGlmKCAoIElORklMRSA9
IGZvcGVuKCAiZGF0YS5wbnQiLCAiciIgKSApID09IChGSUxFICopIE5VTEwgKSB7CiAgICBw
cmludGYoIkNhbid0IG9wZW4gJXMuXG4iLCAiZGF0YS5wbnQiKTsKICAgIGV4aXQoIDIgKTsg
DQogIH0KCiAgbnVtX3BvaW50c19yZWFkID0gMDsKCiAgd2hpbGUgKCBmcmVhZCgmTkVXUE9J
TlQsIHNpemVvZihQT0lOVCksIDEsIElORklMRSkgPT0gMSApIHsKDQogICAgbnVtX3BvaW50
c19yZWFkKys7DQoKICB9ICAgICAgICAgICAgICAgICAvKiB3aGlsZSAoKSAqLwogIAogIHBy
aW50ZigiXG4lZCBwb2ludHMgcmVhZCBmcm9tICVzXG5cbiIsDQogICAgICAgbnVtX3BvaW50
c19yZWFkLCANCgkgImRhdGEucG50Iik7DQoKICBpZiAoSU5GSUxFICE9IE5VTEwpIHsKICAg
IGZjbG9zZShJTkZJTEUpOwogIH0NCgogIGV4aXQoIDAgKTsKICAKfSAKCgoK
--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
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019