| 852 | #endif |
| 853 | |
| 854 | static int yaml_replace_file(const char *temp_path, const char *path, bool destination_exists) { |
| 855 | #ifdef _WIN32 |
| 856 | wchar_t *wide_temp = cbm_utf8_to_wide(temp_path); |
| 857 | wchar_t *wide_path = cbm_utf8_to_wide(path); |
| 858 | if (!wide_temp || !wide_path) { |
| 859 | free(wide_temp); |
| 860 | free(wide_path); |
| 861 | return YAML_ERROR; |
| 862 | } |
| 863 | BOOL replaced = destination_exists ? ReplaceFileW(wide_path, wide_temp, NULL, |
| 864 | REPLACEFILE_WRITE_THROUGH, NULL, NULL) |
| 865 | : MoveFileExW(wide_temp, wide_path, MOVEFILE_WRITE_THROUGH); |
| 866 | free(wide_temp); |
| 867 | free(wide_path); |
| 868 | return replaced ? 0 : YAML_ERROR; |
| 869 | #else |
| 870 | if (!destination_exists) { |
| 871 | if (link(temp_path, path) != 0) { |
| 872 | return YAML_ERROR; |
| 873 | } |
| 874 | if (cbm_unlink(temp_path) != 0) { |
| 875 | return YAML_ERROR; |
| 876 | } |
| 877 | return yaml_sync_parent_directory(path); |
| 878 | } |
| 879 | if (rename(temp_path, path) != 0) { |
| 880 | return YAML_ERROR; |
| 881 | } |
| 882 | return yaml_sync_parent_directory(path); |
| 883 | #endif |
| 884 | } |
| 885 | |
| 886 | static const char *yaml_temp_name(const char *temp_path) { |
| 887 | const char *slash = strrchr(temp_path, '/'); |
no test coverage detected