Use fstatat() wherever possible

This commit is contained in:
sin 2014-10-22 16:50:30 +01:00
parent b06a4d4eeb
commit 05957936f5

30
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:
/* All the rest */
printmsg("Unsupported file"); printmsg("Unsupported file");
free(pathnew);
goto nochange; goto nochange;
}
case SEL_FLTR: case SEL_FLTR:
/* Read filter */ /* Read filter */
printprompt("filter: "); printprompt("filter: ");