diff options
author | Rob Landley <rob@landley.net> | 2023-03-03 15:21:06 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2023-03-03 15:21:06 -0600 |
commit | b367482e9c102f49001a7e2d1ddb048bdce8b06e (patch) | |
tree | f4c498463564b545fcee9408899925db8dc2d29a /toys/posix/ls.c | |
parent | 078e95bba4fa0ce2aaf3e17502bba05b8551a93d (diff) | |
download | toybox-b367482e9c102f49001a7e2d1ddb048bdce8b06e.tar.gz |
Change FLAG(x) macros to always return 0 or 1. Treewide audit of FLAG()
users to make sure nobody NEEDED FLAG(x) to return the masked bit value,
and to remove now-redundant !!, with a number of in-passing cleanups
while I was there.
I think I fixed an actual bug in patch.c (-R depended on the flag value
but commit 6f6b7614e463 changed it, so "+-"[FLAG(R)] was comparing
against the NUL terminator when measuring fuzz) but we didn't have a
test for "fuzz autodetection". And there was another bug in tar.c
where DIRTREE_BREADTH was assigned to a local variable... and then not
used. But the test passed? (Not sure the flag's needed at the top level,
added a comment to the test suite to remind me to revisit that.)
While I was there, capitalize TODO comments so they're easier to grep for.
Diffstat (limited to 'toys/posix/ls.c')
-rw-r--r-- | toys/posix/ls.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/toys/posix/ls.c b/toys/posix/ls.c index aa722cbb..9d3e99a3 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -203,7 +203,7 @@ static int filter(struct dirtree *new) new->st.st_blocks >>= 1; // Use 1KiB blocks rather than 512B blocks. if (FLAG(a)||FLAG(f)) return DIRTREE_SAVE; - if (!FLAG(A) && new->name[0]=='.') return 0; + if (!FLAG(A) && *new->name=='.') return 0; return dirtree_notdotdot(new) & DIRTREE_SAVE; } @@ -291,7 +291,7 @@ static void listfiles(int dirfd, struct dirtree *indir) // Read directory contents. We dup() the fd because this will close it. // This reads/saves contents to display later, except for in "ls -1f" mode. } else dirtree_recurse(indir, filter, dirfd, - DIRTREE_STATLESS|DIRTREE_SYMFOLLOW*!!FLAG(L)); + DIRTREE_STATLESS|DIRTREE_SYMFOLLOW*FLAG(L)); // Copy linked list to array and sort it. Directories go in array because // we visit them in sorted order too. (The nested loops let us measure and @@ -379,9 +379,7 @@ static void listfiles(int dirfd, struct dirtree *indir) // Handle padding and wrapping for display purposes entrylen(dt, len); if (ul) { - int mm = !!FLAG(m); - - if (mm) xputc(','); + if (FLAG(m)) xputc(','); if (FLAG(C)||FLAG(x)) { if (!curcol) xputc('\n'); else { @@ -392,8 +390,8 @@ static void listfiles(int dirfd, struct dirtree *indir) xputc('\n'); width = 0; } else { - printf(" "+mm, 0); // shut up the stupid compiler - width += 2-mm; + printf(" "+FLAG(m), 0); // shut up the stupid compiler + width += 2-FLAG(m); } } width += *len; |