mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 13:51:31 +00:00
Same functionality using lstat(2) instead of fstatat(2)
This commit is contained in:
parent
ca07068dcb
commit
cc88af72ca
33
noice.c
33
noice.c
|
@ -88,6 +88,7 @@ struct entry {
|
||||||
void printmsg(char *msg);
|
void printmsg(char *msg);
|
||||||
void printwarn(void);
|
void printwarn(void);
|
||||||
void printerr(int ret, char *prefix);
|
void printerr(int ret, char *prefix);
|
||||||
|
char *makepath(char *dir, char *name);
|
||||||
|
|
||||||
void *
|
void *
|
||||||
xmalloc(size_t size)
|
xmalloc(size_t size)
|
||||||
|
@ -398,13 +399,19 @@ printent(struct entry *ent, int active)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
dentfill(DIR *dirp, struct entry **dents,
|
dentfill(char *path, struct entry **dents,
|
||||||
int (*filter)(regex_t *, char *), regex_t *re)
|
int (*filter)(regex_t *, char *), regex_t *re)
|
||||||
{
|
{
|
||||||
|
DIR *dirp;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
char *newpath;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int r;
|
int fd, r;
|
||||||
|
|
||||||
|
dirp = opendir(path);
|
||||||
|
if (dirp == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
while ((dp = readdir(dirp)) != NULL) {
|
while ((dp = readdir(dirp)) != NULL) {
|
||||||
/* Skip self and parent */
|
/* Skip self and parent */
|
||||||
|
@ -416,14 +423,19 @@ dentfill(DIR *dirp, struct entry **dents,
|
||||||
*dents = xrealloc(*dents, (n + 1) * sizeof(**dents));
|
*dents = xrealloc(*dents, (n + 1) * sizeof(**dents));
|
||||||
(*dents)[n].name = xstrdup(dp->d_name);
|
(*dents)[n].name = xstrdup(dp->d_name);
|
||||||
/* Get mode flags */
|
/* Get mode flags */
|
||||||
r = fstatat(dirfd(dirp), dp->d_name, &sb,
|
newpath = makepath(path, dp->d_name);
|
||||||
AT_SYMLINK_NOFOLLOW);
|
r = lstat(newpath, &sb);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
printerr(1, "fstatat");
|
printerr(1, "lstat");
|
||||||
(*dents)[n].mode = sb.st_mode;
|
(*dents)[n].mode = sb.st_mode;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Should never be null */
|
||||||
|
r = closedir(dirp);
|
||||||
|
if (r == -1)
|
||||||
|
printerr(1, "closedir");
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,7 +495,6 @@ dentfind(struct entry *dents, int n, char *cwd, char *path)
|
||||||
void
|
void
|
||||||
browse(const char *ipath, const char *ifilter)
|
browse(const char *ipath, const char *ifilter)
|
||||||
{
|
{
|
||||||
DIR *dirp;
|
|
||||||
struct entry *dents;
|
struct entry *dents;
|
||||||
int i, n, cur;
|
int i, n, cur;
|
||||||
int r, ret, fd;
|
int r, ret, fd;
|
||||||
|
@ -501,8 +512,7 @@ begin:
|
||||||
n = 0;
|
n = 0;
|
||||||
dents = NULL;
|
dents = NULL;
|
||||||
|
|
||||||
dirp = opendir(path);
|
if (canopendir(path) == 0) {
|
||||||
if (dirp == NULL) {
|
|
||||||
printwarn();
|
printwarn();
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
@ -512,7 +522,7 @@ begin:
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
|
||||||
n = dentfill(dirp, &dents, visible, &filter_re);
|
n = dentfill(path, &dents, visible, &filter_re);
|
||||||
|
|
||||||
qsort(dents, n, sizeof(*dents), entrycmp);
|
qsort(dents, n, sizeof(*dents), entrycmp);
|
||||||
|
|
||||||
|
@ -718,11 +728,6 @@ nochange:
|
||||||
out:
|
out:
|
||||||
dentfree(dents, n);
|
dentfree(dents, n);
|
||||||
|
|
||||||
/* Should never be null */
|
|
||||||
r = closedir(dirp);
|
|
||||||
if (r == -1)
|
|
||||||
printerr(1, "closedir");
|
|
||||||
|
|
||||||
goto begin;
|
goto begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue