From 0b2209c886969d52685e3b92c36d7c99bfccad7c Mon Sep 17 00:00:00 2001 From: damage Date: Fri, 6 Dec 2024 21:51:08 +0100 Subject: [PATCH] parameter is optional, defaults to '.' --- shperm.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/shperm.c b/shperm.c index 31e15f7..79be739 100644 --- a/shperm.c +++ b/shperm.c @@ -121,15 +121,22 @@ void dumpLines() { } int main(int argc, char* argv[]) { - if (argc != 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); + if (argc > 2) { + fprintf(stderr, "Usage: %s [file or directory]\n", argv[0]); exit(1); } char* path; + char* startpath; path = malloc(PATH_MAX); + + if (argc == 1) { + startpath = "."; + } else { + startpath = argv[1]; + } - if (realpath(argv[1], path)) { + if (realpath(startpath, path)) { char* base; do { struct stat sb; @@ -151,4 +158,4 @@ int main(int argc, char* argv[]) { } free(path); -} \ No newline at end of file +}