aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/ls.c
AgeCommit message (Collapse)Author
2020-04-13Humor asan.Rob Landley
(ls would read from an uninitalized variable and never use the result because the test is afterwards, but asan freaks about impurity and unclean quantum state that's never observed or some such. You read uninitialized but definitely allocated stack memory into a REGISTER, and then performed an ADDITION on it to produce a result you never use! For SHAME!)
2020-04-08ls: fix -h with block counts.Elliott Hughes
The filter() function modifies st_blocks so it's always 1KiB rather than 512B blocks, but the human-readable output was still assuming 512B. This meant that `ls -sh` was showing figures half the size of `ls -s`, and that the "total" line with -h was also off by a factor of 2. No new test, because I don't know how to write one that would work on all file systems. Bug: http://b/153383721
2020-02-02Canonicalize the usage: lines for the POSIX toys.Elliott Hughes
This only touches 24 of the 68 toys/posix/ files --- the others were already canonical. Potentially contentious, so worth stating explicitly, is that there were 8 matches for "COMMAND..." amongst all existing help output, with 7 matches for various inconsistent variants involving something with "ARG", so I resolved that in favor of using "COMMAND..." (which is also shorter overall, and avoids nested []s).
2020-01-09ls.c: just use getxattr()/lgetxattr().Elliott Hughes
bionic works around the fact that you can't use an O_PATH fd with fgetxattr(2), but glibc doesn't. Fixes https://github.com/landley/toybox/issues/158.
2019-11-12Replace a test I took out last commit because it seemed impossible to trigger,Rob Landley
but the problem is some vertical sort arrangements are impossible, and that's what it was testing for. For example, showing 29 entries in 9 columns with horizontal sort requires 4 rows: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 29 x x x x x x x But with vertical sort that would be: 1 5 9 13 17 21 25 29 x 2 6 10 14 18 22 26 x x 3 7 11 15 19 23 27 x x 4 8 12 16 20 24 28 x x It still doesn't fit in 3 rows (3x9=27) but with 4 rows the 7 leftover spaces eats a whole column, so you _can't_ have 9 columns with vertical sort.
2019-11-08ls cleanup: use FLAG() macros, simplify next_column(), fix off by one errorsRob Landley
in whitespace accounting, eliminate lastcol, same sort[next] in dt, don't count trailing whitespace on last entry in row.
2019-11-05Switch -w tests to check boundary conditions, fix code to pass tests,Rob Landley
variable declarations go at the start of blocks, and remove specific people's names from todo items (anybody can do any todo).
2019-10-31ls: Remove trailing whitespace so that tests passAndrew Ilijic
When in modes `-C` and `-x` we need to remove the trailing whitespace on each line. This is the behavior of other `ls` commands. Other `ls` commands will print the last filename and then print a newline. Prior to this patch we would print the last filename, followed by two spaces, and then print a newline. Previously, we would get to the end of the loop and print the padding. I couldn't figure out a way to determine when the program had reached the end of a line. So I piggybacked off of the newline code.
2019-10-28ls: Add `-w` which sets the column widthAndrew Ilijic
2019-10-17ls: Ensure file names are separated by 2 spacesAndrew Ilijic
We need two spaces between filenames because that is the convention followed by other implementations. More importantly, if we do not have two spaces, certain Unicode file names cause filenames to run together. In Unicode, combining characters come before the character they modify. If a filename ends in a combining character, the combining character attaches to the space that follows it, causing the space not to be visible. Having a two-space gap stops the above issue from happening. For context and a bit more information, see mailing list link below. https://www.mail-archive.com/toybox@lists.landley.net/msg05986.html
2019-10-09ls: fix seqfault on broken localeJarno Mäkipää
When user builds toybox CFG_TOYBOX_I18N disabled and tries to list folder contents with multibyte characters other than UTF-8 ls might seqfault since wcrtomb returns -1 while locale set to fi_FI-UTF-8 disable CFG_TOYBOX_I18N touch őőőőaaőő ls
2019-09-09ls: fix spacing of -lZ and --full-time.Elliott Hughes
Two more spacing bugs here, one before the security context for -Z, and one after the size with --full-time. Before: $ ./toybox ls -lZ --full-time Config. -rw-r----- 1 enh primarygroup? 56162019-09-07 21:09:32.892215100 -0700 Config.in After: $ ./toybox ls -lZ --full-time Config. -rw-r----- 1 enh primarygroup ? 5616 2019-09-07 21:09:32.892215100 -0700 Config.in
2019-09-04ls: fix -Z, add a test.Elliott Hughes
This broke a netd test (but sadly in postsubmit rather than presubmit). Also add a trivial test that would at least have caught this bug. Bug: http://b/140453237
2019-09-04DIRTREE_STATLESS doesn't have to test 3 stat fields, it sets a flagRob Landley
2019-08-30ls: fix recent regression.Elliott Hughes
Commit c26870dab3462c6176936384b090df6b9ba46dee broke ls' error reporting for files that don't exist. `ls $F` is used by some as an equivalent of `test -e $F`. This patch also adds a regression test.
2019-08-26Try to make ls failure more graceful. Print ? ? ? entries instead of error msg.Rob Landley
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()
2019-05-13Use FLAG() macros in lsRob Landley
2019-03-02Improve help consistency.Elliott Hughes
More consistent tense, capitalization, and punctuation. A few commands were missing an introductory line, so I copied those from the first comment line.
2019-01-08ls: Fix -t to also sort by st_mtim.tv_nsec.Peter Collingbourne
2018-08-26Convert more commands to the new option/GLOBALS code style.Rob Landley
2018-08-26Remove ls sub-option: always support --color.Rob Landley
(Well, when you say --color or "alias ls='ls --color=auto'" in your shell.)
2017-12-11An incomplete list of deviations from posix (it's a start).Rob Landley
2017-04-19Add ls -ll (with --full-time as a compatibility synonym) to show nanoseconds.Rob Landley
(And, for some reason, timezone. Individual files have timezones?)
2017-04-12Default to -b rather than -q when output is to a tty.Rob Landley
2017-04-11Silence a broken warning by hitting it with a rock.Rob Landley
2017-04-08Fix the ls -m test (which is just a whitespace issue, but eh).Rob Landley
While we're at it, ls -m wordwrap was one column early.
2017-01-28Add missing `static`s and remove an unused function.Elliott Hughes
2017-01-28Whitespace.Rob Landley
2016-10-09Izabera pointed out that ls defaults to -q when output is a tty.Rob Landley
2016-09-14Fix ls -lh.Elliott Hughes
The recent refactoring broke ls -lh by multiplying all sizes by 0 rather than 1.
2016-08-27Make "LC_ALL=C ls -Cs --color" produce the same output on toybox and ubuntu.Rob Landley
(Two spaces padding between columns, and -k is hardwired on.)
2016-08-27Remove some redundancy and unnecessary xprintf().Rob Landley
(We should use xprintf and similar to flush and check if stdout went away once per line. No point flushing partway through a line, so in ls only use it on things outputting a newline char.)
2016-08-27Fix ls -sh.Elliott Hughes
-h should apply to -s too. (Previously it only applied to the "total" line in -s output.)
2016-08-13Move getusername/getgroupname to lib. (Return name or string representationRob Landley
of number, but never NULL. Both returned in static buffer good through next call.)
2016-05-20Add bufgetgrgid()Rob Landley
2016-04-21Have dirtree_recurse() take the new dirfd as an argument.Rob Landley
2016-03-15Add ls -b and make ls -q work with utf8.Rob Landley
2016-03-07Cleanup pass on the dirtree infrastructure, in preparation for making rm -rRob Landley
handle infinite depth. Fix docs, tweak dirtree_handle_callback() semantics, remove dirtree_start() and don't export dirtree_handle_callback(), instead offer dirtree_flagread(). (dirtree_read() is a wrapper around dirtree_flagread passing 0 for flags.)
2016-03-02For years the man pages have said to #include <sys/types.h> to getRob Landley
major/minor/makedev, but glibc has vowed to break existing programs (https://sourceware.org/ml/libc-alpha/2015-11/msg00253.html) and replace it with _another_ non-standard header (not in posix or lsb), so let's just add functions to lib/ that do the transform ourselves.
2016-01-15Command line files without paths were attempting to use stdin as their dirfd,Rob Landley
(because ls uses nonstandard directory recursion which collates all the command line arguments under a fake top node, which needs more thorough initialization).
2016-01-08The sense of -L was flipped.Elliott Hughes
2016-01-05Add error_msg_raw() and friends, replace error_msg("%s", s) uses, enable formatRob Landley
checking, and fix up format checking complaints. Added out(type, value) function to stat to avoid a zillion printf typecasts.
2015-12-30make "ls -m | cat" assume 80 columns.Rob Landley
2015-12-12Add a useless memset (under CFG_TOYBOX_DEBUG) to shut up valgrind.Rob Landley
Valgrind complains that we add uninitalized memory to totals[] fields we never read from. (If we didn't set it in entrylen() we don't use it during display, they're testing the same flags), but valgrind doesn't understand that.
2015-12-06Rename dirtree->data to dirfd, and don't store symlink length in it.Rob Landley
2015-10-27Use the /proc/self/fd/%d workaround for O_PATH not letting you read xattrs,Rob Landley
inspired by: https://android-review.googlesource.com/#/c/152663/4/libc/bionic/fgetxattr.cpp
2015-10-27Fix ls error message for chmod -r directories.Rob Landley
Also, if you mkdir "$(echo -e "one\ntwo"); chmod -r one*; ls -q one* it honors -q.
2015-09-05ls -h support.Elliott Hughes
It turns out that people are anticipating the switch to toybox ls from toolbox ls on the assumption that this will finally bring -h support. Let's not disappoint. I've merged two existing buffers in listfiles whose uses didn't overlap into one. It may be possible to cram this into toybuf with the other stuff, but it didn't seem worth the extra complexity for 64B of stack, especially since we were already living with that for time formatting anyway.
2015-08-31ls -l user/group/security context should be left-aligned.Elliott Hughes
Right-aligned looks pretty good to me, but it's not what anyone else does.
2015-08-08Fix ls -l user/group field ordering.Elliott Hughes
It's user then group, not the other way round.