From 23d4deb111bfff9c282c20989573c4b0775e4c16 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 7 Nov 2019 11:11:45 +0200 Subject: Add path_name struct, open_file_or{stdin,stdout}() functions --- libbutl/fdstream.mxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libbutl/fdstream.mxx') 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 / + // (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 -- cgit v1.1