aboutsummaryrefslogtreecommitdiffstats
path: root/noice.c
diff options
context:
space:
mode:
authorlostd <lostd@2f30.org>2014-11-13 18:49:57 +0200
committerlostd <lostd@2f30.org>2014-11-13 18:49:57 +0200
commitcc88af72ca6a18925e28748cce854c514fbc7752 (patch)
tree3ce34da673ebdb5c92726b353210a9f0c1e5aed0 /noice.c
parentca07068dcb1d506bd999f61b5942fb09194a0f44 (diff)
downloadnoice-cc88af72ca6a18925e28748cce854c514fbc7752.tar.gz
Same functionality using lstat(2) instead of fstatat(2)
Diffstat (limited to 'noice.c')
-rw-r--r--noice.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/noice.c b/noice.c
index bd905f0..16622dd 100644
--- a/noice.c
+++ b/noice.c
@@ -88,6 +88,7 @@ struct entry {
void printmsg(char *msg);
void printwarn(void);
void printerr(int ret, char *prefix);
+char *makepath(char *dir, char *name);
void *
xmalloc(size_t size)
@@ -398,13 +399,19 @@ printent(struct entry *ent, int active)
}
int
-dentfill(DIR *dirp, struct entry **dents,
+dentfill(char *path, struct entry **dents,
int (*filter)(regex_t *, char *), regex_t *re)
{
+ DIR *dirp;
struct dirent *dp;
struct stat sb;
+ char *newpath;
int n = 0;
- int r;
+ int fd, r;
+
+ dirp = opendir(path);
+ if (dirp == NULL)
+ return 0;
while ((dp = readdir(dirp)) != NULL) {
/* Skip self and parent */
@@ -416,14 +423,19 @@ dentfill(DIR *dirp, struct entry **dents,
*dents = xrealloc(*dents, (n + 1) * sizeof(**dents));
(*dents)[n].name = xstrdup(dp->d_name);
/* Get mode flags */
- r = fstatat(dirfd(dirp), dp->d_name, &sb,
- AT_SYMLINK_NOFOLLOW);
+ newpath = makepath(path, dp->d_name);
+ r = lstat(newpath, &sb);
if (r == -1)
- printerr(1, "fstatat");
+ printerr(1, "lstat");
(*dents)[n].mode = sb.st_mode;
n++;
}
+ /* Should never be null */
+ r = closedir(dirp);
+ if (r == -1)
+ printerr(1, "closedir");
+
return n;
}
@@ -483,7 +495,6 @@ dentfind(struct entry *dents, int n, char *cwd, char *path)
void
browse(const char *ipath, const char *ifilter)
{
- DIR *dirp;
struct entry *dents;
int i, n, cur;
int r, ret, fd;
@@ -501,8 +512,7 @@ begin:
n = 0;
dents = NULL;
- dirp = opendir(path);
- if (dirp == NULL) {
+ if (canopendir(path) == 0) {
printwarn();
goto nochange;
}
@@ -512,7 +522,7 @@ begin:
if (r != 0)
goto nochange;
- n = dentfill(dirp, &dents, visible, &filter_re);
+ n = dentfill(path, &dents, visible, &filter_re);
qsort(dents, n, sizeof(*dents), entrycmp);
@@ -718,11 +728,6 @@ nochange:
out:
dentfree(dents, n);
- /* Should never be null */
- r = closedir(dirp);
- if (r == -1)
- printerr(1, "closedir");
-
goto begin;
}
Un proyecto texto-plano.xyz