cmostuor
2020-12-07 21:44:13 +08:00
自己看代码
static void update_cwd(void)
{
cwd = xrealloc_getcwd_or_warn(cwd);
if (!cwd)
cwd = xstrdup(bb_msg_unknown);
}
/* built-in 'cd <path>' handler */
static int builtin_cd(struct child_prog *child)
{
char *newdir;
if (child->argv[1] == NULL)
newdir = getenv("HOME");
else
newdir = child->argv[1];
if (chdir(newdir)) {
bb_perror_msg("cd: %s", newdir);
return EXIT_FAILURE;
}
update_cwd();
return EXIT_SUCCESS;
}
int chdir(const char *path)
{
return syscall(SYS_chdir, path);
}
#ifdef __NR_chdir
# define SYS_chdir __NR_chdir
#endif