This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


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

basic_file.cc


Hi Benjamin,

I cam across what seemed an incompatibility between what the standard says
and what basic_file.cc does. In section 27.8.1.3, it is specified that
both ios::out and ios::out|ios::trunc should be equivalent to the stdio
mode string "w". The manpage for fopen says that "w" means:

Truncate  file  to  zero length or create text file
for writing.   The  stream  is  positioned  at  the
beginning of the file.

and this is confirmed by, for instance, David A. Curry's book "Unix
Systems Programming", O'Reilly 1996.

This means that, in the underlying call to open(), we need the flags
O_WRONLY | O_TRUNC | O_CREAT
This is what we get for ios::out|ios::trunc, but not for ios::out alone.
There is a similar error for ios::out|ios::app.

Here is a diff for basic_file.cc with the changes that I think are
necessary. When I made them and rebuilt the library, the tests done by
make check all still pass.

--- basic_file.cc.save	Wed Aug 11 12:02:43 1999
+++ basic_file.cc	Fri Oct  1 17:42:56 1999
@@ -108,12 +108,12 @@ namespace std {
     
     if (!__testi && __testo && !__testt && !__testa)
       {
-	__p_mode = O_WRONLY;
+	__p_mode = O_WRONLY | O_TRUNC | O_CREAT;
 	__rw_mode = _IO_NO_READS;
       }
     if (!__testi && __testo && !__testt && __testa)
       {
-	__p_mode = O_WRONLY | O_APPEND;
+	__p_mode = O_WRONLY | O_CREAT | O_APPEND;
 	__rw_mode = _IO_NO_READS | _IO_IS_APPENDING;
       }
     if (!__testi && __testo && __testt && !__testa)

Keep up the good work!

Regards, Russell.

PS: I am in Canada not France this term, whence the change in email
address.

Russell Davidson                    email: russell@qed.econ.queensu.ca
Queen's University,
Kingston, Ontario, Canada           phone: 613-533-2264 
K7L 3N6                               Fax: 613-533-6668


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