From 92082c21d1baaf5105f2d4cfcf9ec1b0f63bd13f Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 19 Oct 2002 02:27:54 +0000 Subject: [PATCH] handle open_write() correctly on windows --- dtool/src/dtoolutil/filename.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dtool/src/dtoolutil/filename.cxx b/dtool/src/dtoolutil/filename.cxx index 40e19be38e..319e5719e0 100644 --- a/dtool/src/dtoolutil/filename.cxx +++ b/dtool/src/dtoolutil/filename.cxx @@ -1204,6 +1204,17 @@ open_write(ofstream &stream) const { int open_mode = ios::out; +#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; + } +#endif + #ifdef HAVE_IOS_BINARY // For some reason, some systems (like Irix) don't define // ios::binary.