18 #if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500)
19 # define WITH_FDATASYNC
25 # include <shellapi.h>
51 char file_new[MAX_PATH];
55 FILE *f = fopen(file_new,
"w");
56 if (f == NULL)
return false;
62 if (item->comment != NULL) fputs(item->comment, f);
65 if (strchr(item->name,
' ') != NULL ||
66 item->name[0] ==
'[') {
67 fprintf(f,
"\"%s\"", item->name);
69 fprintf(f,
"%s", item->name);
72 fprintf(f,
" = %s\n", item->value == NULL ?
"" : item->value);
84 int ret = fdatasync(fileno(f));
86 if (ret != 0)
return false;
91 #if defined(WIN32) || defined(WIN64)
95 TCHAR tfilename[MAX_PATH + 1], tfile_new[MAX_PATH + 1];
96 _tcsncpy(tfilename,
OTTD2FS(filename), MAX_PATH);
97 _tcsncpy(tfile_new,
OTTD2FS(file_new), MAX_PATH);
99 tfilename[MAX_PATH - 1] =
'\0';
100 tfile_new[MAX_PATH - 1] =
'\0';
101 tfilename[_tcslen(tfilename) + 1] =
'\0';
102 tfile_new[_tcslen(tfile_new) + 1] =
'\0';
105 SHFILEOPSTRUCT shfopt;
107 shfopt.wFunc = FO_MOVE;
108 shfopt.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;
109 shfopt.pFrom = tfile_new;
110 shfopt.pTo = tfilename;
111 SHFileOperation(&shfopt);
113 if (rename(file_new, filename) < 0) {
114 DEBUG(misc, 0,
"Renaming %s to %s failed; configuration not saved", file_new, filename);