summaryrefslogtreecommitdiff
path: root/nss-tool/common/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'nss-tool/common/util.cc')
-rw-r--r--nss-tool/common/util.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/nss-tool/common/util.cc b/nss-tool/common/util.cc
index e5af2cb8a..77459155a 100644
--- a/nss-tool/common/util.cc
+++ b/nss-tool/common/util.cc
@@ -199,3 +199,18 @@ std::vector<uint8_t> ReadInputData(std::string dataPath) {
return data;
}
+
+std::istream &GetStreamFromFileOrStdin(std::string &path, std::ifstream &ifs) {
+ if (path.empty()) {
+ return std::cin;
+ }
+
+ ifs.open(path, std::ifstream::binary);
+ if (!ifs.good()) {
+ std::cerr << "IO Error when opening " << path << std::endl;
+ std::cerr << "Input file does not exist or you don't have permissions."
+ << std::endl;
+ }
+
+ return ifs;
+}