Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions core/shared/platform/zephyr/zephyr_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ zephyr_fs_alloc_obj(bool is_dir, const char *path, int *index)
ptr = &desc_array[i];
ptr->used = true;
ptr->is_dir = is_dir;
ptr->path = bh_strdup(path);
ptr->dir_index = 0;
size_t path_len = strlen(path) + 1;
ptr->path = BH_MALLOC(path_len);
if (ptr->path == NULL) {
ptr->used = false;
k_mutex_unlock(&desc_array_mutex);
return NULL;
}
strcpy(ptr->path, path);
*index = i + 3;
break;
}
Expand Down Expand Up @@ -850,11 +852,17 @@ os_renameat(os_file_handle old_handle, const char *old_path,
for (int i = 0; i < CONFIG_WASI_MAX_OPEN_FILES; i++) {
struct zephyr_fs_desc *ptr = &desc_array[i];
if (ptr->used && ptr->path && strcmp(ptr->path, abs_old_path) == 0) {
char *new_path_copy = bh_strdup(new_path);
size_t new_path_len = strlen(abs_new_path) + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there is another modification to store the absolute path instead of the relative path, which might be better to split into a new PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR was intended to fix two warning, redefinition of CLOCK_MONOTONIC and implicit declaration of function 'bh_strdup'. With first one parallelly being committed by @TianlongLiang in #4668 , this PR can't be further split anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if you mean that I replaced bh_strdup in two places and it would be better to split them in two separate PRs, or I missed something, please let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_path -> abs_new_path.

The modified version stores absolute paths instead of relative paths in desc_array, which looks good. It would be better to build absolute paths in os_open_preopendir() to ensure all paths are absolute.

If this is intentional, it should be mentioned in the PR description. It's your decision whether to split this into another PR or keep it in the current one. I am okay with both options.

char *new_path_copy = BH_MALLOC(new_path_len);
if (new_path_copy != NULL) {
strcpy(new_path_copy, abs_new_path);
BH_FREE(ptr->path);
ptr->path = new_path_copy;
}
else {
k_mutex_unlock(&desc_array_mutex);
return __WASI_ENOMEM;
}
break; // Only one descriptor should match
}
}
Expand Down Expand Up @@ -1195,4 +1203,4 @@ bool
os_is_stderr_handle(os_file_handle handle)
{
return (handle == (os_file_handle)stderr);
}
}
Loading