use argv[1] as argument for cwd

This commit is contained in:
Night Kaly 2024-03-28 09:12:25 +00:00
parent b2cd0bf431
commit 4342300e56
No known key found for this signature in database
GPG key ID: 8E829D3381CFEBBE

13
ccc.c
View file

@ -54,6 +54,13 @@ int main(int argc, char** argv)
{ {
if (argc > 1 && strcmp(argv[1], "-h") == 0) if (argc > 1 && strcmp(argv[1], "-h") == 0)
die("Usage: ccc filename"); die("Usage: ccc filename");
if (argc == 2) {
struct stat st;
if (lstat(argv[1], &st) != 0) {
perror("ccc");
die("Error from lstat");
}
}
/* check if it is interactive shell */ /* check if it is interactive shell */
if (!isatty(STDIN_FILENO)) if (!isatty(STDIN_FILENO))
@ -92,8 +99,12 @@ int main(int argc, char** argv)
marked = arraylist_init(100); marked = arraylist_init(100);
cwd = memalloc(PATH_MAX * sizeof(char)); cwd = memalloc(PATH_MAX * sizeof(char));
p_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));
populate_files(cwd, 0); populate_files(cwd, 0);
start_ccc(); start_ccc();