aboutsummaryrefslogtreecommitdiff
path: root/libbutl/fdstream.mxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-11-07 11:11:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-11-07 11:11:45 +0200
commit23d4deb111bfff9c282c20989573c4b0775e4c16 (patch)
tree9763c7e2cbce36581673eb69b652f67e2f7cfa6f /libbutl/fdstream.mxx
parentb2ac741e2b806f4565beeef34b12c95b6b3fdd41 (diff)
Add path_name struct, open_file_or{stdin,stdout}() functions
Diffstat (limited to 'libbutl/fdstream.mxx')
-rw-r--r--libbutl/fdstream.mxx18
1 files changed, 18 insertions, 0 deletions
diff --git a/libbutl/fdstream.mxx b/libbutl/fdstream.mxx
index 49c5dae..cebbafa 100644
--- a/libbutl/fdstream.mxx
+++ b/libbutl/fdstream.mxx
@@ -645,6 +645,24 @@ LIBBUTL_MODEXPORT namespace butl
bool is_open () const {return buf_.is_open ();}
};
+ // Open a file or, if the file name is `-`, stdin/stdout.
+ //
+ // In case of the stdin/stdout, these functions simply adjust the exception
+ // mask on std::cin/cout to match the i/ofdstreams argument.
+ //
+ // Return a reference to the opened i/ofdstream or cin/cout and, in the
+ // latter case, set the translated name in path_name to <stdin>/<stdout>
+ // (unless it is already present).
+ //
+ // Note that ofdstream::close() should be called explicitly unless stdout
+ // was opened (but harmless to call even if it was).
+ //
+ LIBBUTL_SYMEXPORT std::istream&
+ open_file_or_stdin (path_name&, ifdstream&);
+
+ LIBBUTL_SYMEXPORT std::ostream&
+ open_file_or_stdout (path_name&, ofdstream&);
+
// The std::getline() replacement that provides a workaround for libstdc++'s
// ios::failure ABI fiasco (#66145) by throwing ios::failure, as it is
// defined at libbutl build time (new ABI on recent distributions) rather