Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int __cd(Tokens tokens) {
- // cd at background is neglected
- if (tokens.background) return 1;
- // get the home directory path using the user_id
- uid_t uid = getuid();
- struct passwd *pw = getpwuid(uid);
- char **args = tokens.args;
- if (args[1] == NULL || strcmp(args[1], "~") == 0) {
- chdir(pw->pw_dir);
- } else {
- if (chdir(args[1]) != 0) {
- perror("hs-shell");
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement