| 812 | #endif |
| 813 | |
| 814 | static int yaml_replace_file(const char *temp_path, const char *path, bool destination_exists) { |
| 815 | #ifdef _WIN32 |
| 816 | wchar_t *wide_temp = cbm_utf8_to_wide(temp_path); |
| 817 | wchar_t *wide_path = cbm_utf8_to_wide(path); |
| 818 | if (!wide_temp || !wide_path) { |
| 819 | free(wide_temp); |
| 820 | free(wide_path); |
| 821 | return YAML_ERROR; |
| 822 | } |
| 823 | BOOL replaced = destination_exists ? ReplaceFileW(wide_path, wide_temp, NULL, |
| 824 | REPLACEFILE_WRITE_THROUGH, NULL, NULL) |
| 825 | : MoveFileExW(wide_temp, wide_path, MOVEFILE_WRITE_THROUGH); |
| 826 | free(wide_temp); |
| 827 | free(wide_path); |
| 828 | return replaced ? 0 : YAML_ERROR; |
| 829 | #else |
| 830 | if (!destination_exists) { |
| 831 | if (link(temp_path, path) != 0) { |
| 832 | return YAML_ERROR; |
| 833 | } |
| 834 | if (cbm_unlink(temp_path) != 0) { |
| 835 | return YAML_ERROR; |
| 836 | } |
| 837 | return yaml_sync_parent_directory(path); |
| 838 | } |
| 839 | if (rename(temp_path, path) != 0) { |
| 840 | return YAML_ERROR; |
| 841 | } |
| 842 | return yaml_sync_parent_directory(path); |
| 843 | #endif |
| 844 | } |
| 845 | |
| 846 | static int yaml_write_atomic(const char *path, const char *data, size_t len, |
| 847 | const char *expected_data, size_t expected_len, |
no test coverage detected