Bug 59933 - C++ regression failure with fstream
Summary: C++ regression failure with fstream
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.3
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-02-15 05:05 UTC by Sam Varshavchik
Modified: 2008-05-01 15:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-02-15 05:05:58 UTC
Embargoed:


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

Description Sam Varshavchik 2002-02-15 05:05:21 UTC
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 05:05:53 UTC
Created attachment 45781 [details]
test program for this bug.

Comment 2 Benjamin Kosnik 2002-02-19 07:31:26 UTC
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.