Add function to rename file

This commit is contained in:
2026-01-02 19:02:17 +00:00
parent f5c2ed89a4
commit ae8cb2e473
7 changed files with 36 additions and 2 deletions

View File

@@ -134,6 +134,24 @@ i32 wapp_file_close(WFile *file) {
return fclose(file);
}
i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath) {
wapp_debug_assert(old_filepath != NULL && new_filepath != NULL,
"`old_filepath` and `new_filepath` should not be NULL");
wapp_persist c8 old_tmp[WAPP_PATH_MAX] = {0};
wapp_debug_assert(old_filepath->size < WAPP_PATH_MAX, "`old_filepath` exceeds max path limit.");
wapp_persist c8 new_tmp[WAPP_PATH_MAX] = {0};
wapp_debug_assert(new_filepath->size < WAPP_PATH_MAX, "`new_filepath` exceeds max path limit.");
memset(old_tmp, 0, WAPP_PATH_MAX);
memcpy(old_tmp, old_filepath->buf, old_filepath->size);
memset(new_tmp, 0, WAPP_PATH_MAX);
memcpy(new_tmp, new_filepath->buf, new_filepath->size);
return rename((const char *)old_tmp, (const char *)new_tmp);
}
i32 wapp_file_remove(Str8RO *filepath) {
wapp_debug_assert(filepath != NULL, "`filepath` should not be NULL");

View File

@@ -50,6 +50,7 @@ u64 wapp_file_read_array(GenericArray dst_buf, WFile *file, u64 item_count);
u64 wapp_file_write_array(const GenericArray src_buf, WFile *file, u64 item_count);
i32 wapp_file_flush(WFile *file);
i32 wapp_file_close(WFile *file);
i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath);
i32 wapp_file_remove(Str8RO *filepath);
#ifdef WAPP_PLATFORM_CPP