|
|
@@ -1199,21 +1199,26 @@ open_read(ifstream &stream) const {
|
|
|
// or set_binary().
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
bool Filename::
|
|
|
-open_write(ofstream &stream) const {
|
|
|
+open_write(ofstream &stream, bool truncate) const {
|
|
|
assert(is_text() || is_binary());
|
|
|
|
|
|
int open_mode = ios::out;
|
|
|
|
|
|
+ if (truncate) {
|
|
|
+ open_mode |= ios::trunc;
|
|
|
+
|
|
|
+ } else {
|
|
|
#ifdef WIN32_VC
|
|
|
- // Windows insists on having this set to prevent the file from being
|
|
|
- // truncated when we open it. Makes ios::trunc kind of pointless,
|
|
|
- // doesn't it? On the other hand, setting ios::in also seems to
|
|
|
- // imply ios::nocreate (!), so we should only set this if the file
|
|
|
- // already exists.
|
|
|
- if (exists()) {
|
|
|
- open_mode |= ios::in;
|
|
|
- }
|
|
|
+ // Windows insists on having ios::in set to prevent the file from
|
|
|
+ // being truncated when we open it. Makes ios::trunc kind of
|
|
|
+ // pointless, doesn't it? On the other hand, setting ios::in also
|
|
|
+ // seems to imply ios::nocreate (!), so we should only set this if
|
|
|
+ // the file already exists.
|
|
|
+ if (exists()) {
|
|
|
+ open_mode |= ios::in;
|
|
|
+ }
|
|
|
#endif
|
|
|
+ }
|
|
|
|
|
|
#ifdef HAVE_IOS_BINARY
|
|
|
// For some reason, some systems (like Irix) don't define
|