const char kExtensionNameKey[] = "@name";
} // namespace
-ExtensionConfigParser::ExtensionConfigParser(std::string config_xml) {
- config_xml_ = config_xml;
-}
+ExtensionConfigParser::ExtensionConfigParser(std::string config_xml)
+ : config_xml_(config_xml) {}
std::unique_ptr<parser::DictionaryValue>
ExtensionConfigParser::LoadExtensionConfig(const std::string& config_xml) {
void WriteBytes(unsigned char* buffer, std::size_t count, FILE* stream) {
// original file is treated as destination!
+ if (count <= 0) {
+ return;
+ }
std::size_t bytes_written = 0;
- std::size_t bytes_to_write = 0;
do {
- bytes_to_write = count - bytes_written;
- bytes_written = std::fwrite(buffer + bytes_written,
- sizeof(unsigned char),
- count - bytes_written,
- stream);
- if ((bytes_written != bytes_to_write)) {
+ std::size_t bytes_appended = std::fwrite(
+ buffer + bytes_written,
+ sizeof(unsigned char),
+ count - bytes_written,
+ stream);
+ if ((bytes_appended == 0)) {
LOG(ERROR) << "Error while writing data";
- free(buffer);
- fclose(stream);
+ return;
}
- } while ((bytes_written != bytes_to_write));
+ bytes_written += bytes_appended;
+ } while ((bytes_written < count));
}
} // namespace
FILE *output = OpenFile(encFile.string().c_str(), "wb");
if (output == nullptr) {
LOG(ERROR) << "Cannot create encrypted file: " << encFile.string();
+ fclose(input);
return false;
}