Added the non-fatal MaybeReadFileToString() function
Applications which read files to string typically had to previously
die upon encountering an error, which could sometimes be unideal in
the larger scope of the program. A MaybeReadFileToString() function
was added for cases where a program must read from a file, but shouldn't
ever die.
Change-Id: I1877d41276674c12b1f8443a1d0162dc46261a6b
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/util/file.h b/aos/util/file.h
index 3b2231a..0cba867 100644
--- a/aos/util/file.h
+++ b/aos/util/file.h
@@ -22,7 +22,12 @@
// Returns the complete contents of filename. LOG(FATAL)s if any errors are
// encountered.
-::std::string ReadFileToStringOrDie(const std::string_view filename);
+std::string ReadFileToStringOrDie(const std::string_view filename);
+
+// Returns the complete contents of filename. Returns nullopt, but never dies
+// if any errors are encountered.
+std::optional<std::string> MaybeReadFileToString(
+ const std::string_view filename);
// Creates filename if it doesn't exist and sets the contents to contents.
void WriteStringToFileOrDie(const std::string_view filename,