aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-08-12 15:47:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-08-12 15:47:28 +0200
commit0a8569041e821facad3fec80fe90c04a77f261df (patch)
tree38ccf997b8c11e5ee5b4fc5dbadcbbc7577c8ad6
parent943f6c3129b351946e81ef08a6a0531f828a7812 (diff)
Fix fdstream fdopen_mode ctors to better match ios::openmode semantics
-rw-r--r--libbutl/fdstream.cxx20
1 files changed, 18 insertions, 2 deletions
diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx
index 053ef13..7d1e755 100644
--- a/libbutl/fdstream.cxx
+++ b/libbutl/fdstream.cxx
@@ -791,7 +791,15 @@ namespace butl
ifdstream::
ifdstream (const char* f, fdopen_mode m, iostate e)
- : ifdstream (fdopen (f, m | fdopen_mode::in), e)
+ : ifdstream (
+ fdopen (f,
+ // If fdopen_mode::in is not specified, then emulate the
+ // ios::in semantics.
+ //
+ (m & fdopen_mode::in) == fdopen_mode::in
+ ? m
+ : m | translate_mode (in)),
+ e)
{
}
@@ -892,7 +900,15 @@ namespace butl
ofdstream::
ofdstream (const char* f, fdopen_mode m, iostate e)
- : ofdstream (fdopen (f, m | fdopen_mode::out), e)
+ : ofdstream (
+ fdopen (f,
+ // If fdopen_mode::out is not specified, then emulate the
+ // ios::out semantics.
+ //
+ (m & fdopen_mode::out) == fdopen_mode::out
+ ? m
+ : m | translate_mode (out)),
+ e)
{
}