This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Fw: fwrite/fread problem


This is being reported to Microsoft, but involves CDK gcc too.
 
-----Original Message-----
From: Mitch English <i166224@thegrid.net>
To: compmail@microsoft.com <compmail@microsoft.com>
Date: Monday, May 11, 1998 2:28 PM
Subject: fwrite/fread problem

CASE_ID_NUM: SRX980511601277
MESSAGE:
Hello,
I have a problem with fwrite/fread functions in a C console app.
I have attached a simple program that demonstrates the problem and log that it prints out and a hex dump of the data file.
In the log you will see after the writes (indicated by AW) that after wrtieing the elventh time, fs[10], that the file pointer provided by ftell is increment by one byte tha would be expected, and in the hex file, the data appears corrupted.  A value of 0d0a where I would expect just 000a.
After the first read, indicated by AR, ftell indicates an offset of 700 instead of 4.
Also I attached aout.log produced by the same program built with OpenNT gcc compiler.  This works as expected.
The Cygnus CDK gcc compiler failed though, because, I think, it uses native MS VC++ libraries.  In the a.log file you can see that it fails as the vc compiled program does on the writes, but curiously does not have the read error.
Problem did not occur under the SUN workshop or gcc compilers.
Thanks for help, and call the 818.785.8677 number if I'm not at 818.994.9422.
mitch
#include <stdio.h>
#include <sys/types.h>
#include <memory.h>
void main()
{
  

#define MAX 200
  int fs[MAX];
  typedef FILE* FilePtr;
  FilePtr SymFile;

  int i,k;
  
#define UpdateBinary "w+"
#define WriteBinary  "w"
#define ReadBinary   "r"
  SymFile=fopen( "simple.dat",  UpdateBinary); /*error occurs with WriteBinary too*/
  memset(fs,0,MAX*sizeof(int));
  for(i=0;i<MAX;i++) {
	fs[i]=i;
    printf("   ftell=%d sizeof(int)=%d fs[%d]=%d\n",ftell(SymFile),sizeof(int),i,fs[i]);
	k=fwrite(&fs[i],sizeof(int),1,SymFile);
    printf("AW ftell=%d sizeof(int)=%d fs[%d]=%d k=%d ferror(SymFile)=%d\n",
	           ftell(SymFile),sizeof(int),i,fs[i],    k,ferror(SymFile));
  }
  /*fclose(SymFile);*/
  /*SymFile=fopen( "simple.dat",  ReadBinary); eroor occurs with explict modes too*/
  fseek( SymFile, 0, SEEK_SET );
  printf("************************************************************************\n");
  memset(fs,0,MAX*sizeof(int));
  for(i=0;i<MAX;i++) {
    printf("   ftell=%d sizeof(int)=%d fs[%d]=%d\n",ftell(SymFile),sizeof(int),i,fs[i]);
	k=fread(&fs[i],sizeof(int),1,SymFile);
    printf("AR ftell=%d sizeof(int)=%d fs[%d]=%d k=%d ferror(SymFile)=%d \n",
	           ftell(SymFile),sizeof(int),i,fs[i],  k,ferror(SymFile));
  }
  fclose(SymFile);
}

simple.hex

simple.log

aout.log

a.log


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]