Write config.xml with CR/LF terminators on Windows.
authorCarl Hetherington <cth@carlh.net>
Wed, 28 Nov 2018 23:30:48 +0000 (23:30 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 28 Nov 2018 23:30:48 +0000 (23:30 +0000)
ChangeLog
src/lib/config.cc

index b4d1b460b38d6ddba77494656e4adfa3f414cbf8..fece69ded405850ae2d9d89c7a50791621957357 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-11-28  Carl Hetherington  <cth@carlh.net>
+
+       * Write config.xml with CR/LF terminators on Windows (#1402).
+
 2018-11-26  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.13.73 released.
index 489e66db98af367eb14b6824642d3be633083708..ddb4bf25a22346f8f3a6e5f7fd8ab742fcdfa43d 100644 (file)
@@ -947,11 +947,22 @@ Config::write_config () const
 #endif
 
        try {
-               doc.write_to_file_formatted(config_file().string());
+               string const s = doc.write_to_string_formatted ();
+               boost::filesystem::path const cf = config_file ();
+               FILE* f = fopen_boost (cf, "w");
+               if (!f) {
+                       throw FileError (_("Could not open file for writing"), cf);
+               }
+               size_t const w = fwrite (s.c_str(), 1, s.length(), f);
+               if (w != s.length()) {
+                       fclose (f);
+                       throw FileError (_("Could not write whole file"), cf);
+               }
+               fclose (f);
        } catch (xmlpp::exception& e) {
                string s = e.what ();
                trim (s);
-               throw FileError (s, path("config.xml"));
+               throw FileError (s, config_file());
        }
 }