Make config_write more atomic to prevent truncation when out of space #871
This is modeled after glib's g_file_set_contents. It doesn't use that
Main differences with g_file_set_contents:
Other than that, it's the same old mkstemp + fsync + rename.
In #817 (comment) I mentioned I wasn't sure if i should keep copying g_file_set_contents(). Few months later, no one is going to refactor config writing to be in-memory, so finishing that WIP code is obviously better than nothing.
The WIP code used g_rename, g_unlink, but those require including gstdio.h and their implementation is all win32 portability code so mehhhh.
This is modeled after glib's g_file_set_contents. It doesn't use that function directly because the writing is done with GIOChannel streaming-like writes and g_file_set_contents expects the whole thing to be in-memory. Main differences with g_file_set_contents: - complete lack of win32 special casing (cygwin/WSL should work though) - no fallocate() (linux only, but we don't know the size upfront, anyway) - always calls fsync (glib skips it on btrfs or when not overwriting) Other than that, it's the same old mkstemp + fsync + rename.