When using cd it will change directory to home if not specifying directory

This commit is contained in:
hellisabove
2022-04-25 16:51:36 +03:00
parent 7dbd28ff8d
commit 6c35c9f183
3 changed files with 314 additions and 307 deletions
+7
View File
@@ -7,6 +7,7 @@
#include <sys/wait.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <pwd.h>
#define MAXCOM 1000 // max number of letters to be supported
#define MAXLIST 100 // max number of commands to be supported
@@ -126,8 +127,14 @@ int ownCmdHandler(char** parsed)
case 1:
exit(0);
case 2:
if(parsed[1]){
chdir(parsed[1]);
return 1;
} else {
char *home = getenv("HOME");
chdir(home);
return 1;
}
default:
break;
}