Quellcode durchsuchen

Replace open and close dir with access()

master
Arun Prakash Jana vor 7 Jahren
Ursprung
Commit
00f9ae9c85
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden GPG-Schlüssel-ID: A75979F35C080412
1 geänderte Dateien mit 11 neuen und 23 gelöschten Zeilen
  1. +11
    -23
      nnn.c

+ 11
- 23
nnn.c Datei anzeigen

@@ -857,18 +857,6 @@ end:
return *ch; 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" * Returns "dir/name or "/name"
*/ */
@@ -1003,7 +991,7 @@ printent(struct entry *ent, int sel)
printw("%s\n", g_buf); printw("%s\n", g_buf);
} }


static char*
static char *
coolsize(off_t size) coolsize(off_t size)
{ {
static const char * const U[] static const char * const U[]
@@ -1636,7 +1624,7 @@ populate(char *path, char *oldpath, char *fltr)
static regex_t re; static regex_t re;


/* Can fail when permissions change while browsing */ /* Can fail when permissions change while browsing */
if (canopendir(path) == 0)
if (access(path, R_OK) == -1)
return -1; return -1;


/* Search filter */ /* Search filter */
@@ -1824,7 +1812,7 @@ nochange:
} }


dir = xdirname(path); dir = xdirname(path);
if (canopendir(dir) == 0) {
if (access(dir, R_OK) == -1) {
printwarn(); printwarn();
goto nochange; goto nochange;
} }
@@ -1865,7 +1853,7 @@ nochange:


switch (sb.st_mode & S_IFMT) { switch (sb.st_mode & S_IFMT) {
case S_IFDIR: case S_IFDIR:
if (canopendir(newpath) == 0) {
if (access(newpath, R_OK) == -1) {
printwarn(); printwarn();
goto nochange; goto nochange;
} }
@@ -2050,7 +2038,7 @@ nochange:
} }


dir = xdirname(dir); dir = xdirname(dir);
if (canopendir(dir) == 0) {
if (access(dir, R_OK) == -1) {
printwarn(); printwarn();
free(input); free(input);
goto nochange; goto nochange;
@@ -2073,7 +2061,7 @@ nochange:


free(input); free(input);


if (canopendir(newpath) == 0) {
if (access(newpath, R_OK) == -1) {
printwarn(); printwarn();
break; break;
} }
@@ -2109,7 +2097,7 @@ nochange:
goto nochange; goto nochange;
} }


if (canopendir(tmp) == 0) {
if (access(tmp, R_OK) == -1) {
printwarn(); printwarn();
goto nochange; goto nochange;
} }
@@ -2129,7 +2117,7 @@ nochange:
presel = FILTER; presel = FILTER;
goto begin; goto begin;
case SEL_CDBEGIN: case SEL_CDBEGIN:
if (canopendir(ipath) == 0) {
if (access(ipath, R_OK) == -1) {
printwarn(); printwarn();
goto nochange; goto nochange;
} }
@@ -2152,7 +2140,7 @@ nochange:
if (lastdir[0] == '\0') if (lastdir[0] == '\0')
break; break;


if (canopendir(lastdir) == 0) {
if (access(lastdir, R_OK) == -1) {
printwarn(); printwarn();
goto nochange; goto nochange;
} }
@@ -2198,7 +2186,7 @@ nochange:
mkpath(path, bookmark[r].loc, mkpath(path, bookmark[r].loc,
newpath, PATH_MAX); newpath, PATH_MAX);


if (canopendir(newpath) == 0) {
if (access(newpath, R_OK) == -1) {
printwarn(); printwarn();
goto nochange; goto nochange;
} }
@@ -2480,7 +2468,7 @@ main(int argc, char *argv[])
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);


/* Test initial path */ /* Test initial path */
if (canopendir(ipath) == 0) {
if (access(ipath, R_OK) == -1) {
fprintf(stderr, "%s: %s\n", ipath, strerror(errno)); fprintf(stderr, "%s: %s\n", ipath, strerror(errno));
exit(1); exit(1);
} }


Laden…
Abbrechen
Speichern