fix change directory from argument

This commit is contained in:
Night Kaly 2024-03-31 00:01:29 +00:00
parent 1e0ce67a7f
commit 93c1e5f8c2
No known key found for this signature in database
GPG key ID: 8E829D3381CFEBBE

13
ccc.c
View file

@ -64,10 +64,15 @@ int main(int argc, char** argv)
die("Usage: ccc filename");
if (argc == 2) {
struct stat st;
if (lstat(argv[1], &st) != 0) {
if (lstat(argv[1], &st)) {
perror("ccc");
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 */
@ -109,11 +114,7 @@ int main(int argc, char** argv)
hashtable_init();
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));
start_ccc();
populate_files(cwd, 0);