+ /*
+ * Flush to disk and replace atomically
+ */
+ fflush (file); /* Flush from run-time */
+ if (ferror (file))
+ {
+ vlc_unlink (temporary);
+ vlc_mutex_unlock (&lock);
+ msg_Err (p_this, "cannot write configuration file");
+ clearerr (file);
+ goto error;
+ }
+#ifndef WIN32
+#ifdef __APPLE__
+ fsync (fd); /* Flush from OS */
+#else
+ fdatasync (fd); /* Flush from OS */
+#endif
+ /* Atomically replace the file... */
+ if (vlc_rename (temporary, permanent))
+ vlc_unlink (temporary);
+ /* (...then synchronize the directory, err, TODO...) */
+ /* ...and finally close the file */
+ vlc_mutex_unlock (&lock);
+#endif
+ fclose (file);
+#ifdef WIN32
+ /* Windows cannot remove open files nor overwrite existing ones */
+ vlc_unlink (permanent);
+ if (vlc_rename (temporary, permanent))
+ vlc_unlink (temporary);
+ vlc_mutex_unlock (&lock);
+#endif