Add function to rename file
This commit is contained in:
@@ -134,6 +134,24 @@ i32 wapp_file_close(WFile *file) {
|
|||||||
return fclose(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) {
|
i32 wapp_file_remove(Str8RO *filepath) {
|
||||||
wapp_debug_assert(filepath != NULL, "`filepath` should not be NULL");
|
wapp_debug_assert(filepath != NULL, "`filepath` should not be NULL");
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
u64 wapp_file_write_array(const GenericArray src_buf, WFile *file, u64 item_count);
|
||||||
i32 wapp_file_flush(WFile *file);
|
i32 wapp_file_flush(WFile *file);
|
||||||
i32 wapp_file_close(WFile *file);
|
i32 wapp_file_close(WFile *file);
|
||||||
|
i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath);
|
||||||
i32 wapp_file_remove(Str8RO *filepath);
|
i32 wapp_file_remove(Str8RO *filepath);
|
||||||
|
|
||||||
#ifdef WAPP_PLATFORM_CPP
|
#ifdef WAPP_PLATFORM_CPP
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#define DST_CAPACITY 5
|
#define DST_CAPACITY 5
|
||||||
wapp_intern Str8RO test_filename = wapp_str8_lit_ro_initialiser_list("wapptest.bin");
|
wapp_intern Str8RO test_filename = wapp_str8_lit_ro_initialiser_list("wapptest.bin");
|
||||||
|
wapp_intern Str8RO new_filename = wapp_str8_lit_ro_initialiser_list("wapptest2.bin");
|
||||||
wapp_intern WFile *test_fp = NULL;
|
wapp_intern WFile *test_fp = NULL;
|
||||||
wapp_intern I32Array src_array1 = wapp_array(i32, 0, 1, 2, 3, 4);
|
wapp_intern I32Array src_array1 = wapp_array(i32, 0, 1, 2, 3, 4);
|
||||||
wapp_intern I32Array src_array2 = wapp_array(i32, 5, 6, 7, 8, 9);
|
wapp_intern I32Array src_array2 = wapp_array(i32, 5, 6, 7, 8, 9);
|
||||||
@@ -92,7 +93,12 @@ TestFuncResult test_wapp_file_close(void) {
|
|||||||
return wapp_tester_result(close_result == 0);
|
return wapp_tester_result(close_result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TestFuncResult test_wapp_file_rename(void) {
|
||||||
|
i32 rename_result = wapp_file_rename(&test_filename, &new_filename);
|
||||||
|
return wapp_tester_result(rename_result == 0);
|
||||||
|
}
|
||||||
|
|
||||||
TestFuncResult test_wapp_file_remove(void) {
|
TestFuncResult test_wapp_file_remove(void) {
|
||||||
i32 remove_result = wapp_file_remove(&test_filename);
|
i32 remove_result = wapp_file_remove(&new_filename);
|
||||||
return wapp_tester_result(remove_result == 0);
|
return wapp_tester_result(remove_result == 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#define DST_CAPACITY 5
|
#define DST_CAPACITY 5
|
||||||
wapp_intern Str8RO test_filename = wapp_str8_lit_ro_initialiser_list("wapptest.bin");
|
wapp_intern Str8RO test_filename = wapp_str8_lit_ro_initialiser_list("wapptest.bin");
|
||||||
|
wapp_intern Str8RO new_filename = wapp_str8_lit_ro_initialiser_list("wapptest2.bin");
|
||||||
wapp_intern WFile *test_fp = NULL;
|
wapp_intern WFile *test_fp = NULL;
|
||||||
wapp_intern i32 dst_buf[DST_CAPACITY] = {0};
|
wapp_intern i32 dst_buf[DST_CAPACITY] = {0};
|
||||||
wapp_intern I32Array src_array1;
|
wapp_intern I32Array src_array1;
|
||||||
@@ -96,7 +97,12 @@ TestFuncResult test_wapp_file_close(void) {
|
|||||||
return wapp_tester_result(close_result == 0);
|
return wapp_tester_result(close_result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TestFuncResult test_wapp_file_rename(void) {
|
||||||
|
i32 rename_result = wapp_file_rename(&test_filename, &new_filename);
|
||||||
|
return wapp_tester_result(rename_result == 0);
|
||||||
|
}
|
||||||
|
|
||||||
TestFuncResult test_wapp_file_remove(void) {
|
TestFuncResult test_wapp_file_remove(void) {
|
||||||
i32 remove_result = wapp_file_remove(&test_filename);
|
i32 remove_result = wapp_file_remove(&new_filename);
|
||||||
return wapp_tester_result(remove_result == 0);
|
return wapp_tester_result(remove_result == 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ TestFuncResult test_wapp_file_read_array(void);
|
|||||||
TestFuncResult test_wapp_file_write_array(void);
|
TestFuncResult test_wapp_file_write_array(void);
|
||||||
TestFuncResult test_wapp_file_flush(void);
|
TestFuncResult test_wapp_file_flush(void);
|
||||||
TestFuncResult test_wapp_file_close(void);
|
TestFuncResult test_wapp_file_close(void);
|
||||||
|
TestFuncResult test_wapp_file_rename(void);
|
||||||
TestFuncResult test_wapp_file_remove(void);
|
TestFuncResult test_wapp_file_remove(void);
|
||||||
|
|
||||||
#endif // !TEST_FILE_H
|
#endif // !TEST_FILE_H
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ int main(void) {
|
|||||||
test_wapp_file_write_array,
|
test_wapp_file_write_array,
|
||||||
test_wapp_file_flush,
|
test_wapp_file_flush,
|
||||||
test_wapp_file_close,
|
test_wapp_file_close,
|
||||||
|
test_wapp_file_rename,
|
||||||
test_wapp_file_remove,
|
test_wapp_file_remove,
|
||||||
test_commander_cmd_success,
|
test_commander_cmd_success,
|
||||||
test_commander_cmd_failure,
|
test_commander_cmd_failure,
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ int main(void) {
|
|||||||
test_wapp_file_write_array,
|
test_wapp_file_write_array,
|
||||||
test_wapp_file_flush,
|
test_wapp_file_flush,
|
||||||
test_wapp_file_close,
|
test_wapp_file_close,
|
||||||
|
test_wapp_file_rename,
|
||||||
test_wapp_file_remove,
|
test_wapp_file_remove,
|
||||||
test_commander_cmd_success,
|
test_commander_cmd_success,
|
||||||
test_commander_cmd_failure,
|
test_commander_cmd_failure,
|
||||||
|
|||||||
Reference in New Issue
Block a user