blob: 9ee2fb4c61d582d87d8b2a3ac12385ec475e9661 [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#ifndef AOS_UTIL_FILE_H_
2#define AOS_UTIL_FILE_H_
Brian Silverman61175fb2016-03-13 15:35:56 -04003
4#include <string>
James Kuszmaul3ae42262019-11-08 12:33:41 -08005#include <string_view>
Austin Schuhcb108412019-10-13 16:09:54 -07006
Brian Silverman61175fb2016-03-13 15:35:56 -04007namespace aos {
8namespace util {
9
10// Returns the complete contents of filename. LOG(FATAL)s if any errors are
11// encountered.
James Kuszmaul3ae42262019-11-08 12:33:41 -080012::std::string ReadFileToStringOrDie(const std::string_view filename);
Brian Silverman61175fb2016-03-13 15:35:56 -040013
Alex Perrycb7da4b2019-08-28 19:35:56 -070014// Creates filename if it doesn't exist and sets the contents to contents.
James Kuszmaul3ae42262019-11-08 12:33:41 -080015void WriteStringToFileOrDie(const std::string_view filename,
16 const std::string_view contents);
Alex Perrycb7da4b2019-08-28 19:35:56 -070017
Austin Schuhfccb2d02020-01-26 16:11:19 -080018void MkdirP(std::string_view path, mode_t mode);
19
James Kuszmaulf8178092020-05-10 18:46:45 -070020bool PathExists(std::string_view path);
21
Brian Silverman61175fb2016-03-13 15:35:56 -040022} // namespace util
23} // namespace aos
24
John Park33858a32018-09-28 23:05:48 -070025#endif // AOS_UTIL_FILE_H_