parameter is optional, defaults to '.'

This commit is contained in:
damage 2024-12-06 21:51:08 +01:00
parent f1c57a0ae6
commit 0b2209c886

View File

@ -121,15 +121,22 @@ void dumpLines() {
}
int main(int argc, char* argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <file or directory>\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);
}
}