aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-08-26 21:25:42 -0500
committerRob Landley <rob@landley.net>2019-08-26 21:25:42 -0500
commitc26870dab3462c6176936384b090df6b9ba46dee (patch)
treed7672c441d36d0b655b4a352dc4300107265b685 /lib
parent0b51fcccf097f70cfd033fee1c983b4dc8d214b7 (diff)
downloadtoybox-c26870dab3462c6176936384b090df6b9ba46dee.tar.gz
Try to make ls failure more graceful. Print ? ? ? entries instead of error msg.
Tweak DIRTREE_STATLESS so it returns zero stat for any error (I'm testing that dev, ino, and blksize are all zero), and fill in file type from readdir()
Diffstat (limited to 'lib')
-rw-r--r--lib/dirtree.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c
index e44df66c..df38b257 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -27,7 +27,7 @@ int dirtree_notdotdot(struct dirtree *catch)
struct dirtree *dirtree_add_node(struct dirtree *parent, char *name, int flags)
{
- struct dirtree *dt = NULL;
+ struct dirtree *dt = 0;
struct stat st;
int len = 0, linklen = 0, statless = 0;
@@ -36,7 +36,7 @@ struct dirtree *dirtree_add_node(struct dirtree *parent, char *name, int flags)
int fd = parent ? parent->dirfd : AT_FDCWD;
if (fstatat(fd, name, &st,AT_SYMLINK_NOFOLLOW*!(flags&DIRTREE_SYMFOLLOW))) {
- if ((flags&DIRTREE_STATLESS) && errno == ENOENT) statless++;
+ if (flags&DIRTREE_STATLESS) statless++;
else goto error;
}
if (S_ISLNK(st.st_mode)) {
@@ -122,7 +122,7 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new,
// If this had children, it was callback's job to free them already.
if (!(flags & DIRTREE_SAVE)) {
free(new);
- new = NULL;
+ new = 0;
}
return (flags & DIRTREE_ABORT)==DIRTREE_ABORT ? DIRTREE_ABORTVAL : new;
@@ -157,6 +157,8 @@ int dirtree_recurse(struct dirtree *node,
while ((entry = readdir(dir))) {
if ((flags&DIRTREE_PROC) && !isdigit(*entry->d_name)) continue;
if (!(new = dirtree_add_node(node, entry->d_name, flags))) continue;
+ if (!new->st.st_blksize && !new->st.st_mode)
+ new->st.st_mode = entry->d_type<<12;
new = dirtree_handle_callback(new, callback);
if (new == DIRTREE_ABORTVAL) break;
if (new) {