fix show hidden logic and fix cannot navigate to root

This commit is contained in:
Night Kaly 2024-03-20 22:18:07 +00:00
parent 920a660f23
commit d723be72ff
No known key found for this signature in database
GPG key ID: 8E829D3381CFEBBE

6
ccc.c
View file

@ -127,6 +127,10 @@ int main(int argc, char** argv)
strcpy(p_cwd, cwd); strcpy(p_cwd, cwd);
char *last_slash = strrchr(cwd, '/'); char *last_slash = strrchr(cwd, '/');
if (last_slash != NULL) { if (last_slash != NULL) {
if (last_slash == cwd) {
strcpy(cwd, "/");
change_dir(cwd, 0);
}
*last_slash = '\0'; *last_slash = '\0';
change_dir(cwd, 0); change_dir(cwd, 0);
} }
@ -449,7 +453,7 @@ void populate_files(const char *path, int ftype)
strcat(filename, ep->d_name); strcat(filename, ep->d_name);
/* use strncmp to filter out dotfiles */ /* 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 */ /* construct full file path */
filename[0] = '\0'; filename[0] = '\0';
strcat(filename, cwd); strcat(filename, cwd);