模拟器迁移 P5:2s 配置轮询 + --cfgtest 无头自检;修复 MSVC rename 覆盖与外科保存截断缺陷

This commit is contained in:
2026-09-14 09:33:32 +08:00
parent 97661415ca
commit bc4a7da8a0
6 changed files with 151 additions and 32 deletions
+5 -2
View File
@@ -56,8 +56,10 @@ int cfg_store_read(const char *p_path, uint8_t *p_buf, size_t cap, size_t *p_nre
* 入口参数:p_path - 目标文件路径 const char *
* p_buf - 待写数据(不可为 NULL) const uint8_t *
* len - 数据长度 size_t
* 返回值:0 - 成功;-1 - 写/改名失败(目标文件保持不动,临时文件清理) int
* 限定条件:无
* 返回值:0 - 成功;-1 - 写/改名失败(临时文件清理) int
* 限定条件:MSVC rename() 不覆盖已存在目标(C1117),须先 remove 再 rename
* (tmp 已完整写盘关闭后操作,中断窗口仅毫秒级;目标丢失时引擎
* 下次加载自动重建出厂模板,与 MCU 端 f_rename 直接替换等效)
*/
int cfg_store_write_atomic(const char *p_path, const uint8_t *p_buf, size_t len) {
FILE *fp;
@@ -76,6 +78,7 @@ int cfg_store_write_atomic(const char *p_path, const uint8_t *p_buf, size_t len)
(void)remove(s_path_tmp);
return -1;
}
(void)remove(p_path); /* 目标可能不存在(首写):remove 失败忽略 */
if (rename(s_path_tmp, p_path) != 0) {
(void)remove(s_path_tmp);
return -1;