MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / WriteStringToFile

Function WriteStringToFile

Bcore/src/main/cpp/android-base/file.cpp:104–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102
103#if !defined(_WIN32)
104bool WriteStringToFile(const std::string& content, const std::string& path,
105 mode_t mode, uid_t owner, gid_t group,
106 bool follow_symlinks) {
107 int flags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_BINARY |
108 (follow_symlinks ? 0 : O_NOFOLLOW);
109 android_lkchan::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode)));
110 if (fd == -1) {
111 PLOG(ERROR) << "android_lkchan::WriteStringToFile open failed";
112 return false;
113 }
114
115 // We do an explicit fchmod here because we assume that the caller really
116 // meant what they said and doesn't want the umask-influenced mode.
117 if (fchmod(fd, mode) == -1) {
118 PLOG(ERROR) << "android_lkchan::WriteStringToFile fchmod failed";
119 return CleanUpAfterFailedWrite(path);
120 }
121 if (fchown(fd, owner, group) == -1) {
122 PLOG(ERROR) << "android_lkchan::WriteStringToFile fchown failed";
123 return CleanUpAfterFailedWrite(path);
124 }
125 if (!WriteStringToFd(content, fd)) {
126 PLOG(ERROR) << "android_lkchan::WriteStringToFile write failed";
127 return CleanUpAfterFailedWrite(path);
128 }
129 return true;
130}
131#endif
132
133bool WriteStringToFile(const std::string& content, const std::string& path,

Callers

nothing calls this directly

Calls 3

CleanUpAfterFailedWriteFunction · 0.85
WriteStringToFdFunction · 0.85
c_strMethod · 0.80

Tested by

no test coverage detected