mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
add truncate parameter to open_write
This commit is contained in:
parent
1e38e768d5
commit
35afd13237
@ -1199,21 +1199,26 @@ open_read(ifstream &stream) const {
|
|||||||
// or set_binary().
|
// or set_binary().
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool Filename::
|
bool Filename::
|
||||||
open_write(ofstream &stream) const {
|
open_write(ofstream &stream, bool truncate) const {
|
||||||
assert(is_text() || is_binary());
|
assert(is_text() || is_binary());
|
||||||
|
|
||||||
int open_mode = ios::out;
|
int open_mode = ios::out;
|
||||||
|
|
||||||
|
if (truncate) {
|
||||||
|
open_mode |= ios::trunc;
|
||||||
|
|
||||||
|
} else {
|
||||||
#ifdef WIN32_VC
|
#ifdef WIN32_VC
|
||||||
// Windows insists on having this set to prevent the file from being
|
// Windows insists on having ios::in set to prevent the file from
|
||||||
// truncated when we open it. Makes ios::trunc kind of pointless,
|
// being truncated when we open it. Makes ios::trunc kind of
|
||||||
// doesn't it? On the other hand, setting ios::in also seems to
|
// pointless, doesn't it? On the other hand, setting ios::in also
|
||||||
// imply ios::nocreate (!), so we should only set this if the file
|
// seems to imply ios::nocreate (!), so we should only set this if
|
||||||
// already exists.
|
// the file already exists.
|
||||||
if (exists()) {
|
if (exists()) {
|
||||||
open_mode |= ios::in;
|
open_mode |= ios::in;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_IOS_BINARY
|
#ifdef HAVE_IOS_BINARY
|
||||||
// For some reason, some systems (like Irix) don't define
|
// For some reason, some systems (like Irix) don't define
|
||||||
|
@ -150,7 +150,7 @@ PUBLISHED:
|
|||||||
bool scan_directory(vector_string &contents) const;
|
bool scan_directory(vector_string &contents) const;
|
||||||
|
|
||||||
bool open_read(ifstream &stream) const;
|
bool open_read(ifstream &stream) const;
|
||||||
bool open_write(ofstream &stream) const;
|
bool open_write(ofstream &stream, bool truncate = false) const;
|
||||||
bool open_append(ofstream &stream) const;
|
bool open_append(ofstream &stream) const;
|
||||||
bool open_read_write(fstream &stream) const;
|
bool open_read_write(fstream &stream) const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user