Browse Source

Use fstatat() wherever possible

master
sin 10 years ago
parent
commit
05957936f5
1 changed files with 9 additions and 23 deletions
  1. +9
    -23
      noice.c

+ 9
- 23
noice.c View File

@@ -525,7 +525,6 @@ begin:
for (;;) { for (;;) {
int nlines; int nlines;
int odd; int odd;
char *pathnew;
char *name; char *name;
char *bin; char *bin;
char *dir; char *dir;
@@ -605,27 +604,19 @@ nochange:


name = dents[cur].name; name = dents[cur].name;


/* Handle root case */
if (strcmp(path, "/") == 0)
asprintf(&pathnew, "/%s", name);
else
asprintf(&pathnew, "%s/%s", path, name);

DPRINTF_S(name); DPRINTF_S(name);
DPRINTF_S(pathnew);


/* Get path info */ /* Get path info */
r = stat(pathnew, &sb); r = fstatat(dirfd(dirp), name, &sb, 0);
if (r == -1) { if (r == -1) {
printwarn(); printwarn();
free(pathnew);
goto nochange; goto nochange;
} }
DPRINTF_U(sb.st_mode); DPRINTF_U(sb.st_mode);
/* Directory */ switch (sb.st_mode & S_IFMT) {
if (S_ISDIR(sb.st_mode)) { case S_IFDIR:
free(path); free(path);
path = pathnew; path = xrealpath(name);
free(filter); free(filter);
filter = xstrdup(ifilter); /* Reset filter */ filter = xstrdup(ifilter); /* Reset filter */
/* Save history */ /* Save history */
@@ -634,26 +625,21 @@ nochange:
SLIST_INSERT_HEAD(&histhead, hist, entry); SLIST_INSERT_HEAD(&histhead, hist, entry);
cur = 0; cur = 0;
goto out; goto out;
} case S_IFREG:
/* Regular file */
if (S_ISREG(sb.st_mode)) {
/* Open with */ /* Open with */
bin = openwith(name); bin = openwith(name);
if (bin == NULL) { if (bin == NULL) {
printmsg("No association"); printmsg("No association");
free(pathnew);
goto nochange; goto nochange;
} }
exitcurses(); exitcurses();
spawn(bin, pathnew); spawn(bin, name);
initcurses(); initcurses();
free(pathnew);
goto redraw; goto redraw;
default:
printmsg("Unsupported file");
goto nochange;
} }
/* All the rest */
printmsg("Unsupported file");
free(pathnew);
goto nochange;
case SEL_FLTR: case SEL_FLTR:
/* Read filter */ /* Read filter */
printprompt("filter: "); printprompt("filter: ");


||||||
x
 
000:0
Loading…
Cancel
Save