nnn.c | 34 +++++++++++----------------------- diff --git a/nnn.c b/nnn.c index 589e22c86f2df0822e53d02a9eeb73b9065436a2..6e6c1ca3cfcec8f7f020e97606b99da037844c5d 100644 --- a/nnn.c +++ b/nnn.c @@ -857,18 +857,6 @@ /* Return keys for navigation etc. */ return *ch; } -static int -canopendir(char *path) -{ - static DIR *dirp; - - dirp = opendir(path); - if (dirp == NULL) - return 0; - closedir(dirp); - return 1; -} - /* * Returns "dir/name or "/name" */ @@ -1003,7 +991,7 @@ printw("%s\n", g_buf); } -static char* +static char * coolsize(off_t size) { static const char * const U[] @@ -1636,7 +1624,7 @@ { static regex_t re; /* Can fail when permissions change while browsing */ - if (canopendir(path) == 0) + if (access(path, R_OK) == -1) return -1; /* Search filter */ @@ -1824,7 +1812,7 @@ goto nochange; } dir = xdirname(path); - if (canopendir(dir) == 0) { + if (access(dir, R_OK) == -1) { printwarn(); goto nochange; } @@ -1865,7 +1853,7 @@ DPRINTF_U(sb.st_mode); switch (sb.st_mode & S_IFMT) { case S_IFDIR: - if (canopendir(newpath) == 0) { + if (access(newpath, R_OK) == -1) { printwarn(); goto nochange; } @@ -2050,7 +2038,7 @@ break; } dir = xdirname(dir); - if (canopendir(dir) == 0) { + if (access(dir, R_OK) == -1) { printwarn(); free(input); goto nochange; @@ -2073,7 +2061,7 @@ mkpath(path, tmp, newpath, PATH_MAX); free(input); - if (canopendir(newpath) == 0) { + if (access(newpath, R_OK) == -1) { printwarn(); break; } @@ -2109,7 +2097,7 @@ clearprompt(); goto nochange; } - if (canopendir(tmp) == 0) { + if (access(tmp, R_OK) == -1) { printwarn(); goto nochange; } @@ -2129,7 +2117,7 @@ if (cfg.filtermode) presel = FILTER; goto begin; case SEL_CDBEGIN: - if (canopendir(ipath) == 0) { + if (access(ipath, R_OK) == -1) { printwarn(); goto nochange; } @@ -2152,7 +2140,7 @@ case SEL_CDLAST: if (lastdir[0] == '\0') break; - if (canopendir(lastdir) == 0) { + if (access(lastdir, R_OK) == -1) { printwarn(); goto nochange; } @@ -2198,7 +2186,7 @@ } else mkpath(path, bookmark[r].loc, newpath, PATH_MAX); - if (canopendir(newpath) == 0) { + if (access(newpath, R_OK) == -1) { printwarn(); goto nochange; } @@ -2480,7 +2468,7 @@ signal(SIGINT, SIG_IGN); /* Test initial path */ - if (canopendir(ipath) == 0) { + if (access(ipath, R_OK) == -1) { fprintf(stderr, "%s: %s\n", ipath, strerror(errno)); exit(1); }