+ fclose(fr);
+
+ if(ferror(fw)) {
+ error = true;
+ }
+
+ if(fclose(fw)) {
+ error = true;
+ }
+
+ // If any error occured during reading or writing, exit.
+ if(error) {
+ unlink(tmpname);
+ return false;
+ }
+
+ // Try to atomically replace the old config file with the new one.
+#ifdef HAVE_MINGW
+ char bakname[PATH_MAX];
+ snprintf(bakname, sizeof(bakname), "%s.bak", filename);
+
+ if(rename(filename, bakname) || rename(tmpname, filename)) {
+ rename(bakname, filename);
+#else
+
+ if(rename(tmpname, filename)) {
+#endif
+ return false;
+ } else {
+#ifdef HAVE_MINGW
+ unlink(bakname);
+#endif
+ return true;
+ }
+}
+
+bool append_config_file(meshlink_handle_t *mesh, const char *name, const char *key, const char *value) {
+ return modify_config_file(mesh, name, key, value, 0);