MCPcopy Create free account
hub / github.com/Tencent/libpag / WriteToFile

Function WriteToFile

exporter/src/utils/FileHelper.cpp:98–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98bool WriteToFile(const std::string& filePath, const char* data, std::streamsize size,
99 std::ios::openmode mode) {
100 auto path = Utf8ToPath(filePath);
101 auto parentPath = path.parent_path();
102 if (!parentPath.empty() && !fs::exists(parentPath)) {
103 fs::create_directories(parentPath);
104 }
105 std::ofstream file(path, mode);
106 if (!file) {
107 LOGE("Failed to open file: %s", filePath.c_str());
108 return false;
109 }
110
111 file.write(data, size);
112
113 if (file.fail()) {
114 LOGE("Failed to write to file: %s", filePath.c_str());
115 if (file.eof()) {
116 LOGE("eof is set: End-of-File reached on input operation.");
117 }
118 file.close();
119 return false;
120 }
121
122 file.close();
123 return true;
124}
125
126bool DeleteFile(const std::string& path) {
127 return fs::remove_all(path);

Callers 1

exportFileMethod · 0.85

Calls 4

emptyMethod · 0.80
writeMethod · 0.80
Utf8ToPathFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected