kolibrios-fun/programs/system/shell/cmd/cmd_cd.c
Rustem Gimadutdinov (rgimad) 68cf3e4293 SHELL 0.8.2
- big refactoring, now uses libc.obj
- added kfetch command

git-svn-id: svn://kolibrios.org@8827 a494cfbc-eb01-0410-851d-a64ba20cac60
2021-06-12 21:34:41 +00:00

49 lines
817 B
C

int cmd_cd(char dir[])
{
char temp[256];
unsigned result;
if (NULL == dir) {
printf(CMD_CD_USAGE);
return TRUE;
}
if ( 0 == strcmp(dir, ".") || 0 == strcmp(dir, "./") )
return TRUE;
if ( ( 0 == strcmp(dir, "..") || 0 == strcmp(dir, "../") ) && ( 0 != strcmp(cur_dir, "/")) ) {
cur_dir[strlen(cur_dir)-1]='\0';
dir_truncate(cur_dir);
set_cwd(cur_dir);
return TRUE;
}
if ( '/' == dir[0]) {
if ( dir_check(dir) )
{
strcpy(cur_dir, dir);
set_cwd(cur_dir);
return TRUE;
}
return FALSE;
}
else {
strcpy(temp, cur_dir);
if (cur_dir[strlen(cur_dir)-1] != '/')
strcat(temp, "/");
strcat(temp, dir);
if ( dir_check(temp) ) {
strcpy(cur_dir, temp);
set_cwd(cur_dir);
return TRUE;
}
return FALSE;
}
}