2010-10-17 21:50:55 +02:00
|
|
|
|
|
|
|
int cmd_cd(char dir[])
|
|
|
|
{
|
2021-06-12 23:34:41 +02:00
|
|
|
char temp[256];
|
|
|
|
unsigned result;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
2021-06-12 23:34:41 +02:00
|
|
|
if (NULL == dir) {
|
|
|
|
printf(CMD_CD_USAGE);
|
|
|
|
return TRUE;
|
2010-10-17 21:50:55 +02:00
|
|
|
}
|
|
|
|
|
2021-06-12 23:34:41 +02:00
|
|
|
if ( 0 == strcmp(dir, ".") || 0 == strcmp(dir, "./") )
|
|
|
|
return TRUE;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
2021-06-12 23:34:41 +02:00
|
|
|
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;
|
2010-10-17 21:50:55 +02:00
|
|
|
}
|
|
|
|
|
2021-06-12 23:34:41 +02:00
|
|
|
if ( '/' == dir[0]) {
|
|
|
|
if ( dir_check(dir) )
|
|
|
|
{
|
|
|
|
strcpy(cur_dir, dir);
|
|
|
|
set_cwd(cur_dir);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2010-10-17 21:50:55 +02:00
|
|
|
}
|
2021-06-12 23:34:41 +02:00
|
|
|
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;
|
2010-10-17 21:50:55 +02:00
|
|
|
}
|
|
|
|
|
2021-06-12 23:34:41 +02:00
|
|
|
return FALSE;
|
2010-10-17 21:50:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-02-24 11:33:37 +01:00
|
|
|
|