From f272ebc9041a375d2f545d0e4f606eebfe7b3aa6 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 10 Jan 2014 14:30:27 +0000 Subject: PR libstdc++/59687 * doc/xml/manual/backwards_compatibility.xml (backwards.third.nocreate_noreplace): Correct and expand. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@206525 138bc75d-0d04-0410-961f-82ee72b054a4 --- .../doc/xml/manual/backwards_compatibility.xml | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'libstdc++-v3/doc/xml') diff --git a/libstdc++-v3/doc/xml/manual/backwards_compatibility.xml b/libstdc++-v3/doc/xml/manual/backwards_compatibility.xml index 869b63f1992..2a2f77d216a 100644 --- a/libstdc++-v3/doc/xml/manual/backwards_compatibility.xml +++ b/libstdc++-v3/doc/xml/manual/backwards_compatibility.xml @@ -782,18 +782,25 @@ AC_DEFUN([AC_HEADER_EXT_HASH_SET], [ - The existence of ios::nocreate being used for -input-streams has been confirmed, most probably because the author -thought it would be more correct to specify nocreate explicitly. So -it can be left out for input-streams. +Historically these flags were used with iostreams to control whether +new files are created or not when opening a file stream, similar to the +O_CREAT and O_EXCL flags for the +open(2) system call. Because iostream modes correspond +to fopen(3) modes these flags are not supported. +For input streams a new file will not be created anyway, so +ios::nocreate is not needed. +For output streams, a new file will be created if it does not exist, which is +consistent with the behaviour of fopen. -For output streams, nocreate is probably the default, -unless you specify std::ios::trunc ? To be safe, you can -open the file for reading, check if it has been opened, and then -decide whether you want to create/replace or not. To my knowledge, -even older implementations support app, ate -and trunc (except for app ?). +When one of these flags is needed a possible alternative is to attempt +to open the file using std::ifstream first to determine whether +the file already exists or not. This may not be reliable however, because +whether the file exists or not could change between opening the +std::istream and re-opening with an output stream. If you need +to check for existence and open a file as a single operation then you will +need to use OS-specific facilities outside the C++ standard library, such +as open(2). -- cgit v1.2.3