fix change directory from argument
This commit is contained in:
parent
1e0ce67a7f
commit
93c1e5f8c2
1 changed files with 7 additions and 6 deletions
11
ccc.c
11
ccc.c
|
@ -64,10 +64,15 @@ int main(int argc, char** argv)
|
||||||
die("Usage: ccc filename");
|
die("Usage: ccc filename");
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (lstat(argv[1], &st) != 0) {
|
if (lstat(argv[1], &st)) {
|
||||||
perror("ccc");
|
perror("ccc");
|
||||||
die("Error from lstat");
|
die("Error from lstat");
|
||||||
}
|
}
|
||||||
|
/* chdir to directory from argument */
|
||||||
|
if(S_ISDIR(st.st_mode) && chdir(argv[1])) {
|
||||||
|
perror("ccc");
|
||||||
|
die("Error from chdir");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if it is interactive shell */
|
/* check if it is interactive shell */
|
||||||
|
@ -109,11 +114,7 @@ int main(int argc, char** argv)
|
||||||
hashtable_init();
|
hashtable_init();
|
||||||
|
|
||||||
cwd = memalloc(PATH_MAX * sizeof(char));
|
cwd = memalloc(PATH_MAX * sizeof(char));
|
||||||
if (argc == 2) {
|
|
||||||
strcpy(cwd, argv[1]);
|
|
||||||
} else {
|
|
||||||
getcwd(cwd, PATH_MAX);
|
getcwd(cwd, PATH_MAX);
|
||||||
}
|
|
||||||
p_cwd = memalloc(PATH_MAX * sizeof(char));
|
p_cwd = memalloc(PATH_MAX * sizeof(char));
|
||||||
start_ccc();
|
start_ccc();
|
||||||
populate_files(cwd, 0);
|
populate_files(cwd, 0);
|
||||||
|
|
Loading…
Reference in a new issue