From 4342300e56b40966d15029455390c56770b7ee68 Mon Sep 17 00:00:00 2001 From: night0721 Date: Thu, 28 Mar 2024 09:12:25 +0000 Subject: [PATCH] use argv[1] as argument for cwd --- ccc.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ccc.c b/ccc.c index cc8bf58..a190008 100644 --- a/ccc.c +++ b/ccc.c @@ -54,6 +54,13 @@ int main(int argc, char** argv) { if (argc > 1 && strcmp(argv[1], "-h") == 0) 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 */ if (!isatty(STDIN_FILENO)) @@ -92,8 +99,12 @@ int main(int argc, char** argv) marked = arraylist_init(100); cwd = memalloc(PATH_MAX * sizeof(char)); + if (argc == 2) { + strcpy(cwd, argv[1]); + } else { + getcwd(cwd, PATH_MAX); + } p_cwd = memalloc(PATH_MAX * sizeof(char)); - getcwd(cwd, PATH_MAX); populate_files(cwd, 0); start_ccc();