Skip to content

Instantly share code, notes, and snippets.

@ashokgelal
Created September 19, 2011 06:29
Show Gist options
  • Save ashokgelal/1226055 to your computer and use it in GitHub Desktop.
Save ashokgelal/1226055 to your computer and use it in GitHub Desktop.
chdir implementation
void changeDir(char *path){
if(path == '\0'){
// get home path
uid_t id = getuid();
struct passwd *pwd = getpwuid(id);
path = (pwd == NULL ? ) "." : pwd->pw_dir;
}
int status = chdir(path);
if(status == 0){
// first get the current directory
char cur_path[4096];
getcwd(cur_path, 4096);
printf("%c]0;%s%s%c", '\033', "Olet tässä: ", curr_path, '\007');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment