add path_prepend_xxx

This commit is contained in:
lixianjing 2023-09-25 08:51:46 +08:00
parent ea521291e6
commit d77e905ea4
4 changed files with 59 additions and 0 deletions

View File

@ -1,5 +1,9 @@
# 最新动态
2023/09/25
* 增加函数path\_prepend\_temp\_path
* 增加函数path\_prepend\_user\_storage\_path
2023/09/24
* 增加函数tk\_iostream\_tcp\_create\_client
* 增加函数hash\_table\_size

View File

@ -346,6 +346,26 @@ const char* path_prepend_app_root(char full_path[MAX_PATH + 1], const char* path
return full_path;
}
const char* path_prepend_temp_path(char full_path[MAX_PATH + 1], const char* path) {
char temp_path[MAX_PATH + 1] = {0};
return_value_if_fail(path != NULL, NULL);
return_value_if_fail(fs_get_temp_path(os_fs(), temp_path) == RET_OK, NULL);
path_build(full_path, MAX_PATH, temp_path, path, NULL);
return full_path;
}
const char* path_prepend_user_storage_path(char full_path[MAX_PATH + 1], const char* path) {
char user_storage_path[MAX_PATH + 1] = {0};
return_value_if_fail(path != NULL, NULL);
return_value_if_fail(fs_get_user_storage_path(os_fs(), user_storage_path) == RET_OK, NULL);
path_build(full_path, MAX_PATH, user_storage_path, path, NULL);
return full_path;
}
ret_t path_abs_normalize(const char* filename, char* result, int32_t size) {
char path[MAX_PATH + 1];
return_value_if_fail(filename != NULL && result != NULL && size > 0, RET_BAD_PARAMS);

View File

@ -257,6 +257,26 @@ ret_t path_remove_last_slash(char* path);
*/
const char* path_prepend_app_root(char full_path[MAX_PATH + 1], const char* path);
/**
* @method path_prepend_temp_path
*
* @param {char*} full_path
* @param {const char*} path
*
* @return {const char*}
*/
const char* path_prepend_temp_path(char full_path[MAX_PATH + 1], const char* path);
/**
* @method path_prepend_user_storage_path
*
* @param {char*} full_path
* @param {const char*} path
*
* @return {const char*}
*/
const char* path_prepend_user_storage_path(char full_path[MAX_PATH + 1], const char* path);
/**
* @method path_abs_normalize
*

View File

@ -270,6 +270,21 @@ TEST(Path, path_prepend_app_root) {
char result[MAX_PATH + 1] = {0};
ASSERT_EQ(path_prepend_app_root(result, "bin"), result);
ASSERT_EQ(path_exist(result), TRUE);
log_debug("%s\n", result);
}
TEST(Path, path_prepend_temp_path) {
char result[MAX_PATH + 1] = {0};
ASSERT_EQ(path_prepend_temp_path(result, "test.txt"), result);
ASSERT_NE(strstr(result, "test.txt"), (char*)NULL);
log_debug("%s\n", result);
}
TEST(Path, path_prepend_user_storage_path) {
char result[MAX_PATH + 1] = {0};
ASSERT_EQ(path_prepend_user_storage_path(result, "test.txt"), result);
ASSERT_NE(strstr(result, "test.txt"), (char*)NULL);
log_debug("%s\n", result);
}
TEST(Path, abs_normalize) {