18 #if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500)
24 # include <shellapi.h>
50 char file_new[MAX_PATH];
54 FILE *f = fopen(file_new,
"w");
55 if (f == NULL)
return false;
61 if (item->comment != NULL) fputs(item->comment, f);
64 if (strchr(item->name,
' ') != NULL ||
65 item->name[0] ==
'[') {
66 fprintf(f,
"\"%s\"", item->name);
68 fprintf(f,
"%s", item->name);
71 fprintf(f,
" = %s\n", item->value == NULL ?
"" : item->value);
82 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
83 int ret = fdatasync(fileno(f));
85 if (ret != 0)
return false;
90 #if defined(WIN32) || defined(WIN64)
94 TCHAR tfilename[MAX_PATH + 1], tfile_new[MAX_PATH + 1];
95 _tcsncpy(tfilename,
OTTD2FS(filename), MAX_PATH);
96 _tcsncpy(tfile_new,
OTTD2FS(file_new), MAX_PATH);
98 tfilename[MAX_PATH - 1] =
'\0';
99 tfile_new[MAX_PATH - 1] =
'\0';
100 tfilename[_tcslen(tfilename) + 1] =
'\0';
101 tfile_new[_tcslen(tfile_new) + 1] =
'\0';
104 SHFILEOPSTRUCT shfopt;
106 shfopt.wFunc = FO_MOVE;
107 shfopt.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;
108 shfopt.pFrom = tfile_new;
109 shfopt.pTo = tfilename;
110 SHFileOperation(&shfopt);
112 if (rename(file_new, filename) < 0) {
113 DEBUG(misc, 0,
"Renaming %s to %s failed; configuration not saved", file_new, filename);