Bug 59933 - C++ regression failure with fstream
C++ regression failure with fstream
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.3
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-02-15 00:05 EST by Sam Varshavchik
Modified: 2008-05-01 11:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-02-15 00:05:58 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
test program for this bug. (134 bytes, text/plain)
2002-02-15 00:05 EST, Sam Varshavchik
no flags Details

  None (edit)
Description Sam Varshavchik 2002-02-15 00:05:21 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020205

Description of problem:

The constructor std::fstream(const char *filename, std::ios::in | std::ios::out)
does not create the file if it doesn't exist (the resulting open() does not have
O_CREAT mode set).

std::fstream(const char *filename, ios::out) does set O_CREAT, but then the file
is opened in write-only mode.  There does not appear to be any way to create a
file with fstream in read/write mode???

Version-Release number of selected component (if applicable):
libstdc++-devel-3.1-0.21



How reproducible:
Always

Steps to Reproduce:
1.  Compile the attached file.
2.  strace it



Actual Results:  strace output:

open("testfile", O_RDWR)                = -1 ENOENT (No such file or directory)


Expected Results:  strace output:

open("testfile", O_RDWR|O_CREAT|O_LARGEFILE, 0664) = 3

(this is under gcc 2.96)


Additional info:


Changing the open mode in the constructor to std::ios::out results in the
following syscall:

open("testfile", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3

So the file is now created, but it's open in write-only mode only.  There does
not appear to be any way in gcc 3.1 to create a file in read/write mode. 
Doesn't seem right.
Comment 1 Sam Varshavchik 2002-02-15 00:05:53 EST
Created attachment 45781 [details]
test program for this bug.
Comment 2 Benjamin Kosnik 2002-02-19 02:31:26 EST
You might want to take a look at:

27.8.1.3 - Member functions [lib.filebuf.members]
filebuf::open(const char* s,ios_base::openmode mode );

There's a table that explains the open modes. In particular:

in out trunc  equiv stdio
+  +   -      "r+"  
+  +   +      "w+"

So, what you need to do to get the behavior you'd like with current,
standards-conforming semantics is pretty simple:

  fstream f("testfile", ios::in | ios::out | ios::trunc);

best,
benjamin

Note You need to log in before you can comment on or make changes to this bug.