diff options
Diffstat (limited to 'libbuild2/utility.cxx')
-rw-r--r-- | libbuild2/utility.cxx | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/libbuild2/utility.cxx b/libbuild2/utility.cxx index 78d2df2..7f40688 100644 --- a/libbuild2/utility.cxx +++ b/libbuild2/utility.cxx @@ -8,7 +8,7 @@ #include <cerrno> // ENOENT #include <cstring> // strlen(), str[n]cmp() -#include <iostream> // cerr +#include <iostream> // cin cout cerr #include <libbuild2/target.hxx> #include <libbuild2/context.hxx> @@ -100,6 +100,36 @@ namespace build2 dir_path home; const dir_path* relative_base = &work; + istream& + open_file_or_stdin (const path& f, ifdstream& ifs) + { + if (f.string () != "-") + { + ifs.open (f); + return ifs; + } + else + { + cin.exceptions (ifdstream::failbit | ifdstream::badbit); + return cin; + } + } + + ostream& + open_file_or_stdout (const path& f, ofdstream& ofs) + { + if (f.string () != "-") + { + ofs.open (f); + return ofs; + } + else + { + cout.exceptions (ofdstream::failbit | ofdstream::badbit); + return cout; + } + } + path relative (const path_target& t) { |