🐛 解决cd到相对路径后,新路径字符串拼接错误的问题

This commit is contained in:
fslongjin 2022-07-06 00:39:18 +08:00
parent c4f90f4883
commit 52b5c2731d
2 changed files with 7 additions and 6 deletions

View File

@ -181,7 +181,7 @@ int shell_cmd_cd(int argc, char **argv)
goto fail; goto fail;
; // 出错则直接忽略 ; // 出错则直接忽略
} }
else else // ======进入相对路径=====
{ {
int dest_offset = 0; int dest_offset = 0;
if (dest_len > 2) if (dest_len > 2)
@ -191,7 +191,7 @@ int shell_cmd_cd(int argc, char **argv)
} }
int new_len = current_dir_len + dest_len - dest_offset; int new_len = current_dir_len + dest_len - dest_offset;
// ======进入相对路径=====
if (new_len >= SHELL_CWD_MAX_SIZE - 1) if (new_len >= SHELL_CWD_MAX_SIZE - 1)
{ {
printf("ERROR: Path too long!\n"); printf("ERROR: Path too long!\n");
@ -210,7 +210,8 @@ int shell_cmd_cd(int argc, char **argv)
if (chdir(new_path) == 0) // 成功切换目录 if (chdir(new_path) == 0) // 成功切换目录
{ {
free(shell_current_path); free(shell_current_path);
new_path[new_len] = '\0'; // printf("new_path=%s, newlen= %d\n", new_path, new_len);
new_path[new_len+1] = '\0';
shell_current_path = new_path; shell_current_path = new_path;
goto done; goto done;
} }

View File

@ -73,9 +73,9 @@ int main()
int kb_fd = open(kb_file_path, 0); int kb_fd = open(kb_file_path, 0);
// printf("keyboard fd = %d\n", kb_fd); // printf("keyboard fd = %d\n", kb_fd);
print_ascii_logo(); print_ascii_logo();
printf("before mkdir\n"); // printf("before mkdir\n");
mkdir("/aaac", 0); // mkdir("/aaac", 0);
printf("after mkdir\n"); // printf("after mkdir\n");
main_loop(kb_fd); main_loop(kb_fd);
while (1) while (1)
; ;