Lines Matching defs:path
55 bool KernelInterface::EchoToPath(const char* path, const char* content)
57 int fd = open(path, O_WRONLY);
59 HILOGE("echo %{public}s > %{public}s failed: file is not open", content, path);
63 HILOGE("echo %{public}s > %{public}s failed: write failed", content, path);
68 HILOGI("echo %{public}s > %{public}s", content, path);
72 bool KernelInterface::IsFileExists(const std::string& path)
74 if (path.empty()) {
78 if (stat(path.c_str(), &st) == 0 && S_ISREG(st.st_mode)) {
84 bool KernelInterface::CreateFile(const std::string& path, const mode_t& mode)
86 if (path.empty()) {
89 if (IsFileExists(path)) {
93 std::ofstream fout(path);
99 if (chmod(path.c_str(), mode) != 0) {
106 bool KernelInterface::CreateFile(const std::string& path)
108 return CreateFile(path, FILE_MODE_644);
111 bool KernelInterface::RemoveFile(const std::string& path)
113 return OHOS::RemoveFile(path);
116 bool KernelInterface::WriteToFile(const std::string& path, const std::string& content, bool truncated)
122 if (strlen(path.c_str()) == 0 || strlen(path.c_str()) > PATH_MAX) {
123 HILOGE("file path is invalid");
126 ptrRet = realpath(path.c_str(), actualPath);
128 HILOGE("file path cannot be canonicalized");
131 HILOGD("path:%{public}s, actualPath:%{public}s", path.c_str(), actualPath);
135 content.c_str(), truncated ? ">" : ">>", path.c_str());
141 content.c_str(), truncated ? ">" : ">>", path.c_str());
148 HILOGD("echo %{public}s %{public}s %{public}s", content.c_str(), truncated ? ">" : ">>", path.c_str());
152 bool KernelInterface::ReadFromFile(const std::string& path, std::string& content)
154 return OHOS::LoadStringFromFile(path, content);
157 bool KernelInterface::ReadLinesFromFile(const std::string& path, std::vector<std::string>& lines)
159 if (!IsFileExists(path)) {
160 HILOGE("no such file: %{public}s", path.c_str());
164 std::ifstream inf(path, std::ifstream::in);
166 HILOGE("ifstream(%{public}s) failed", path.c_str());
178 bool KernelInterface::IsDirExists(const std::string& path)
180 if (path.empty()) {
184 if (stat(path.c_str(), &st) == 0 && S_ISDIR(st.st_mode)) {
202 bool KernelInterface::IsExists(const std::string& path)
204 return OHOS::FileExists(path);
207 bool KernelInterface::IsEmptyDir(const std::string& path)
209 return OHOS::IsEmptyFolder(path);
212 bool KernelInterface::CreateDir(const std::string& path)
214 return OHOS::ForceCreateDirectory(path); // default mode 755
217 bool KernelInterface::RemoveDirRecursively(const std::string& path)
219 return OHOS::ForceRemoveDirectory(path) || (remove(path.c_str()) == 0);
222 std::string KernelInterface::RmDelimiter(const std::string& path)
224 if (path.empty()) {
225 return path;
227 return OHOS::ExcludeTrailingPathDelimiter(path);
230 std::string KernelInterface::AddDelimiter(const std::string& path)
232 if (path.empty()) {
233 return path;
235 return OHOS::IncludeTrailingPathDelimiter(path);
432 std::string path = JoinPath(ROOT_PROC_PATH, std::to_string(pid), "status");
434 if (!ReadFromFile(path, content)) {
435 HILOGE("read file failed. %{public}s", path.c_str());
462 bool KernelInterface::ReadSwapOutKBSinceKernelBoot(const std::string &path, const std::string &tagStr,
466 if (!ReadFromFile(path, contentStr)) {
583 std::string path = JoinPath(memcgPath, FILE_MEMCG_PROCS);
585 if (!ReadLinesFromFile(path, strLines)) {
586 HILOGE("read file and split to lines failed : %{public}s", path.c_str());
600 HILOGD("there are %{public}zu pids in %{public}s", memcgPids.size(), path.c_str());