🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #883

Bug in ifstreams under OS/2

#883
From: mrhagger
Date: Wed, 02 Sep 1992 19:25
53 lines
2411 bytes
Hi,

I have discovered what seems to be a bug in libgpp as ported to OS/2.  I am
using the current libgpp.zoo obtained from ftp-os2.nmsu.edu at the end of
August in the gcc2-2.2.2 package; I can't find more exact info about exactly
what is the origin of this port.  (I had the same problem with an earlier 
version from a few months ago.)

The following program:

        #include <iostream.h>
        #include <fstream.h>
        
        int main(...)
        {
          char c;
        
          ifstream fi("try.dat");
        
          while (fi.read((void *)&c, sizeof(c)))
          {
            cerr << (int)c << endl;
          }
        
          return 0;
        }
       
seems to read the first character of the file try.dat twice.  Thus if try.dat
is a (FAT or HPFS) file containing the eight bytes:
        0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08
then the program outputs
        1 1 2 3 4 5 6 7 8    /* on separate lines, of course */
.  The first byte is read twice.  Similar behavior is obtained when c is
declared to be short int or int; the output is that which would be correct
for a file which had the first byte doubled.

Ideally one would like the program to be able to read the file in binary mode
(with no CR/LF -> LF translations, etc.) but there doesn't seem to be any way
to specify this using fstreams.  I compared the results of this program to the
results of using FILE's opened using fopen("...", MODE) where MODE is either
"r" or "rb" (on other files).  In each case the FILE I/O is performed 
correctly, with or without translation, respectively.  By contrast, the 
ostream example ALWAYS performs translation (i.e., no binary mode), and in
addition always reads the first byte twice, at least when the reading is done
with fi.read().

Feel free to contact me if you would like more information or a better
description of the problem, or if I have sent this bug report to the wrong
place.

Michael Haggerty
mrhagger@athena.mit.edu
(617)876-0682
Technical Details
Message-ID: <9209021925.AA26050@e40-008-6.MIT.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!athena.mit.edu!mrhagger

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!athena.mit.edu!mrhagger
From: mrhagger@athena.mit.edu
Subject: Bug in ifstreams under OS/2
Message-ID: <9209021925.AA26050@e40-008-6.MIT.EDU>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 2 Sep 1992 19:25:43 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 54