Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. int __cd(Tokens tokens) {
  2.     // cd at background is neglected
  3.     if (tokens.background) return 1;
  4.  
  5.     // get the home directory path using the user_id
  6.     uid_t uid = getuid();
  7.     struct passwd *pw = getpwuid(uid);
  8.  
  9.     char **args = tokens.args;
  10.  
  11.     if (args[1] == NULL || strcmp(args[1], "~") == 0) {
  12.         chdir(pw->pw_dir);
  13.     } else {
  14.         if (chdir(args[1]) != 0) {
  15.             perror("hs-shell");
  16.         }
  17.     }
  18.     return 1;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement