MCPcopy Create free account
hub / github.com/Kitware/CMake / FileWrite

Method FileWrite

Source/cmQtAutoGenerator.cxx:164–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164bool cmQtAutoGenerator::FileWrite(std::string const& filename,
165 std::string const& content,
166 std::string* error)
167{
168 // Make sure the parent directory exists
169 if (!cmQtAutoGenerator::MakeParentDirectory(filename)) {
170 if (error) {
171 *error = "Could not create parent directory.";
172 }
173 return false;
174 }
175 cmsys::ofstream ofs;
176 ofs.open(filename.c_str(),
177 (std::ios::out | std::ios::binary | std::ios::trunc));
178
179 // Use lambda to save destructor calls of ofs
180 return [&ofs, &content, error]() -> bool {
181 if (!ofs) {
182 if (error) {
183 *error = "Opening file for writing failed.";
184 }
185 return false;
186 }
187 ofs << content;
188 if (!ofs.good()) {
189 if (error) {
190 *error = "File writing failed.";
191 }
192 return false;
193 }
194 return true;
195 }();
196}
197
198bool cmQtAutoGenerator::FileDiffers(std::string const& filename,
199 std::string const& content)

Callers

nothing calls this directly

Calls 3

c_strMethod · 0.80
goodMethod · 0.80
openMethod · 0.45

Tested by

no test coverage detected