This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[LONG] Bug with fstream.open() ?


Hi,

I discovered GCC 2.95.2 fopen() and GCC 3.0.4 fopen() behave differently 
for ios::in|ios::out openmode: the first one does an open with 
O_RDWR|O_CREAT and the second one with O_RDWR (i.e. an old program 
working with GCC 2.95.2 doesn't work anymore the GCC 3.0.4 because the 
program fails on unexistant files).

That's probably due to a change in the C++ standards or something like 
that (including a too tolerant compilator).

So I tested fstream.open() behavior on two plateforms (i686-pc-linux-gnu 
and sparc-sun-solaris2.8) with 3 differents compilers (GCC 2.95.2, GCC 
3.0.4 and CC 5.0). I catched syscalls with strace and truss.

Below the code used to test:

8<-----------------------------------------
#include <fstream.h>
#include <iostream.h>

using namespace std;

void my_open( char * fich, ios_base::openmode mode) {
// GCC 2.95.2 void my_open( char * fich, int mode) {
   fstream fst;
   fst.open(fich, mode);
}

int main() {
   my_open("ios::in", ios::in);
   my_open("ios::out", ios::out);
   my_open("ios::in|ios::out", ios::in|ios::out);
   my_open("ios::in|ios::ate", ios::in|ios::ate);
   my_open("ios::out|ios::app", ios::out|ios::app);
   my_open("ios::out|ios::ate", ios::out|ios::ate);
   my_open("ios::out|ios::trunc", ios::out|ios::trunc);
   my_open("ios::in|ios::out|ios::app", ios::in|ios::out|ios::app);
   my_open("ios::in|ios::out|ios::ate", ios::in|ios::out|ios::ate);
   my_open("ios::in|ios::out|ios::trunc", ios::in|ios::out|ios::trunc);
}
8<-----------------------------------------

And here the results:

8<-----------------------------------------
GCC 2.95.2 i686-pc-linux-gnu
open("ios::in", O_RDONLY|0x8000)
open("ios::out", O_WRONLY|O_CREAT|O_TRUNC|0x8000, 0664)
open("ios::in|ios::out", O_RDWR|O_CREAT|0x8000, 0664)
open("ios::in|ios::ate", O_RDONLY|O_CREAT|0x8000, 0664)
open("ios::out|ios::app", O_WRONLY|O_APPEND|O_CREAT|0x8000, 0664)
open("ios::out|ios::ate", O_WRONLY|O_CREAT|0x8000, 0664)
open("ios::out|ios::trunc", O_WRONLY|O_CREAT|O_TRUNC|0x8000, 0664)
open("ios::in|ios::out|ios::app", O_RDWR|O_APPEND|O_CREAT|0x8000, 0664)
open("ios::in|ios::out|ios::ate", O_RDWR|O_CREAT|0x8000, 0664)
open("ios::in|ios::out|ios::trunc", O_RDWR|O_CREAT|O_TRUNC|0x8000, 0664)

GCC 2.95.2 sparc-sun-solaris2.8
open("ios::in", O_RDONLY)
open("ios::out", O_WRONLY|O_CREAT|O_TRUNC, 0664)
open("ios::in|ios::out", O_RDWR|O_CREAT, 0664)
open("ios::in|ios::ate", O_RDONLY|O_CREAT, 0664)
open("ios::out|ios::app", O_WRONLY|O_APPEND|O_CREAT, 0664)
open("ios::out|ios::ate", O_WRONLY|O_CREAT, 0664)
open("ios::out|ios::trunc", O_WRONLY|O_CREAT|O_TRUNC, 0664)
open("ios::in|ios::out|ios::app", O_RDWR|O_APPEND|O_CREAT, 0664)
open("ios::in|ios::out|ios::ate", O_RDWR|O_CREAT, 0664)
open("ios::in|ios::out|ios::trunc", O_RDWR|O_CREAT|O_TRUNC, 0664)

GCC 3.0.4 i686-pc-linux-gnu or sparc-sun-solaris2.8
open("ios::in", O_RDONLY)
open("ios::out", O_WRONLY|O_CREAT|O_TRUNC, 0666)
open("ios::in|ios::out", O_RDWR)
open("ios::in|ios::ate", O_RDONLY)
open("ios::out|ios::app", O_WRONLY|O_APPEND|O_CREAT, 0666)
open("ios::out|ios::ate", O_WRONLY|O_CREAT|O_TRUNC, 0666)
open("ios::out|ios::trunc", O_WRONLY|O_CREAT|O_TRUNC, 0666)
open("ios::in|ios::out|ios::ate", O_RDWR)
open("ios::in|ios::out|ios::trunc", O_RDWR|O_CREAT|O_TRUNC, 0666)

Sun CC 5.0 sparc-sun-solaris2.8
open("ios::in", O_RDONLY)
open("ios::out", O_WRONLY|O_CREAT|O_TRUNC, 0666)
open("ios::in|ios::out", O_RDWR)
open("ios::in|ios::ate", O_RDONLY)
open("ios::out|ios::app", O_WRONLY|O_APPEND|O_CREAT, 0666)
open("ios::out|ios::ate", O_WRONLY|O_CREAT|O_TRUNC, 0666)
open("ios::out|ios::trunc", O_WRONLY|O_CREAT|O_TRUNC, 0666)
open("ios::in|ios::out|ios::app", O_RDWR|O_APPEND|O_CREAT, 0666)
open("ios::in|ios::out|ios::ate", O_RDWR)
open("ios::in|ios::out|ios::trunc", O_RDWR|O_CREAT|O_TRUNC, 0666)
8<-----------------------------------------

Conclusions: GCC 2.95.2 and GCC 3.0 behaves differently with 
ios::in|ios::out, ios::in|ios::ate, ios::out|ios:ate, 
ios:in|ios::out|io:ate and ios::in|ios::out|ios::ate. According to 
Dinkum C++ library documentation, these openmodes are respectively 'r+', 
   'r','w','w','r+' and seem to be correct in GCC 3.0.4. There is also 
changes in UMASK, probably correct too.

But ios::in|ios::out|ios::app ('a+') doesn't appear in GCC 3.0.4 (it 
does in GCC 2.95.2 and CC 5.0), and it's probably a bug.

Did I miss the point or miscode something, or is it really a bug?

-- 
Benoît Sibaud
R&D Engineer - France Telecom


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