blob: bf216bbac818a57815acde336df4e5941772b3ea [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 Silvermana9f2ec92020-10-06 18:00:53 -07007#include "glog/logging.h"
8
Brian Silverman61175fb2016-03-13 15:35:56 -04009namespace aos {
10namespace util {
11
12// Returns the complete contents of filename. LOG(FATAL)s if any errors are
13// encountered.
James Kuszmaul3ae42262019-11-08 12:33:41 -080014::std::string ReadFileToStringOrDie(const std::string_view filename);
Brian Silverman61175fb2016-03-13 15:35:56 -040015
Alex Perrycb7da4b2019-08-28 19:35:56 -070016// Creates filename if it doesn't exist and sets the contents to contents.
James Kuszmaul3ae42262019-11-08 12:33:41 -080017void WriteStringToFileOrDie(const std::string_view filename,
18 const std::string_view contents);
Alex Perrycb7da4b2019-08-28 19:35:56 -070019
Brian Silvermana9f2ec92020-10-06 18:00:53 -070020// Returns true if it succeeds or false if the filesystem is full.
21bool MkdirPIfSpace(std::string_view path, mode_t mode);
22
23inline void MkdirP(std::string_view path, mode_t mode) {
24 CHECK(MkdirPIfSpace(path, mode));
25}
Austin Schuhfccb2d02020-01-26 16:11:19 -080026
James Kuszmaulf8178092020-05-10 18:46:45 -070027bool PathExists(std::string_view path);
28
Brian Silverman61175fb2016-03-13 15:35:56 -040029} // namespace util
30} // namespace aos
31
John Park33858a32018-09-28 23:05:48 -070032#endif // AOS_UTIL_FILE_H_