www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/29/13:26:14

From: "Greg Wellenius" <gwelleni AT hsph DOT harvard DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Problem reading DOS binary files
Date: Wed, 29 Dec 1999 10:48:46 -0500
Organization: Harvard University Network Operations Center
Lines: 41
Message-ID: <84ddkm$r3i$1@plato.harvard.edu>
NNTP-Posting-Host: 12.6.221.159
X-Trace: plato.harvard.edu 946485718 27762 12.6.221.159 (29 Dec 1999 16:41:58 GMT)
X-Complaints-To: usenet AT harvard DOT edu
NNTP-Posting-Date: 29 Dec 1999 16:41:58 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3612.1700
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I'm having problems reading binary files using fstream's 'read' function.

In the following loop, I read two bytes, skip ahead 6 bytes, and so on until
I reach an EOF. The loop exits long before the true end of file is reached.

-------------------------
short tmpdata;

// Open file read only
fstream dataFile.open( fileName, ios::in );
      if ( !dataFile ) {
         cerr << "File could not be opened." << endl;
         exit (1);
      }

// Read two bytes, skip six
for (int i=0; !dataFile.eof(); i++) {
   dataFile.read( reinterpret_cast<char *>(&tmpData), 2 );
   dataFile.seekg( 6, ios::cur );
}

------------------------------

The DJGPP v2 faq (sec 9.3) says that:

> Problems with read/write access to binary files via `fstream' class in C++
> programs are due to a bug in the GNU iostream library.  This bug causes
> truncation of files, even if you never write to the file.  The library
> distributed with GCC version 2.8.1 is free of that bug, so upgrade.

I'm using the library distributed with djgpp 2.95.2 (ie libstdcxx.a included
in gpp2952b.zip) and I still seem to have this problem. The workaround
provided in that same section of the FAQ cannot work.

Any ideas?

Thanks

greg


- Raw text -


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