From d723be72ffb18c716ba69afbe60c4018392387df Mon Sep 17 00:00:00 2001 From: night0721 Date: Wed, 20 Mar 2024 22:18:07 +0000 Subject: [PATCH] fix show hidden logic and fix cannot navigate to root --- ccc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ccc.c b/ccc.c index 8981b9e..bae07c1 100644 --- a/ccc.c +++ b/ccc.c @@ -127,6 +127,10 @@ int main(int argc, char** argv) strcpy(p_cwd, cwd); char *last_slash = strrchr(cwd, '/'); if (last_slash != NULL) { + if (last_slash == cwd) { + strcpy(cwd, "/"); + change_dir(cwd, 0); + } *last_slash = '\0'; change_dir(cwd, 0); } @@ -449,7 +453,7 @@ void populate_files(const char *path, int ftype) strcat(filename, ep->d_name); /* use strncmp to filter out dotfiles */ - if ((show_hidden && strncmp(filename, ".", 1) && strncmp(filename, "..", 2)) || (!show_hidden && strcmp(filename, ".") && strcmp(filename, ".."))) { + if ((!show_hidden && strncmp(filename, ".", 1) && strncmp(filename, "..", 2)) || (show_hidden && strcmp(filename, ".") && strcmp(filename, ".."))) { /* construct full file path */ filename[0] = '\0'; strcat(filename, cwd);