aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
AgeCommit message (Collapse)Author
2020-01-11find.c: don't assume time_t is the same as longRich Felker
This is false on ILP32 targets with 64-bit time_t.
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.
2020-01-08Implement readelf(1).Elliott Hughes
Basic readelf(1) implementation, with output close enough to the binutils version to be usable with scripts that expect the binutils version. This started as an implementation of nm(1) until I realized that I almost always want readelf instead, and that you actually have to do much of the work needed for readelf just to implement nm. Arguably nm (being part of POSIX) belongs in toybox while readelf doesn't. An argument could also be made that neither really belongs in toybox, belonging in a separate set of development tools (such as binutils or the LLVM binutils). Doesn't support most of the architecture-specific stuff, most notably relocations, but is aware of things like ARM exidx sections and the common register state notes in core dumps for the "big four" architectures: arm, arm64, x86, and x86-64. Doesn't support symbol versions (but probably should). Doesn't support section groups or the -t "section details" (which is a long form of -S "section headers" that I've never seen used in practice and which isn't part of -a). Doesn't support dumping unwind info or the hash table bucket histograms. Reuses the table of ELF architectures from file(1). Not fuzzed, but successfully parses all the ELF files in my Ubuntu 18.04 system's lib directories. Attempts to exit with an error when presented with an invalid ELF file rather than struggle on as binutils seems to.
2020-01-06date.c: add a few more important specifiers to --help.Elliott Hughes
Odd (and un-toyboxy) that we advertise the locale-specific output formats but not the ISO ones :-)
2020-01-01Add MAYFORK to more pseudo-builtins.Rob Landley
This doesn't (yet) add shell builtin awareness to time, kill, or pwd, just lets them run in the shell process.
2019-12-28More sheer pedantry.Rob Landley
2019-12-28Rename get_chunk()/dump_chunk() to read_chunk()/write_chunk().Rob Landley
2019-12-28Cleanup, mostly whitespace.Rob Landley
2019-12-28Sheer pedantry.Rob Landley
2019-12-28Change variable type to avoid typecast.Rob Landley
2019-12-28tar: fix memory write errorEmmanuel Nicolet
Clear the last byte of the allocated buffer.
2019-12-22Bugfix: tee with no arguments was writing to stdout twice.Rob Landley
Add basic smoketest while we're at it.
2019-12-21Add patch -F (fuzz factor)Rob Landley
2019-12-21Tighten up unquote_file()Rob Landley
2019-12-20patch: support [FILE [PATCH]] arguments.Elliott Hughes
POSIX only mentions -i/stdin, but GNU patch -- and Larry Wall's patch 1.3, found via https://en.wikipedia.org/wiki/Patch_(Unix) -- also support supplying the name of the file to patch and the name of the patch file as optional arguments. The AOSP build makes use of this syntax to patch snakeyaml to remove references to java.beans.* stuff.
2019-11-23Fix iconv and tests on Mac.Elliott Hughes
The Mac iconv_open(3) doesn't follow Unicode TR#22 rules for charset alias matching that bionic and glibc do (and, strictly, POSIX doesn't say you have to even though it's obviously a good idea), so we have to say exactly "UTF-8" rather than "utf8". Additionally, the 2006-era bash 3.2 on current versions of macOS (because it was the last GPLv2 bash) seems to have bugs that cause it to mangle UTF-8 input, so we can't reliably echo a UTF-8 sequence into a file. Use \x in the tests to work around this.
2019-11-23du: use FLAG().Elliott Hughes
2019-11-14xargs: distinguish the two "argument too long" error cases.Elliott Hughes
One is really "the command is too long for me to ever call it given other constraints", so leave "argument too long" for the case where it's actually an argument causing the issue.
2019-11-13Pedantic constant annotations to shut up older toolchains.Rob Landley
2019-11-12Don't rm prompt for nonexistent, just warn.Denys Nykula
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-05id: fix Android issues.Elliott Hughes
glibc doesn't set errno when getpw* fails, so the perror_exit() looked fine. bionic sets ENOENT and the trailing "No such file or directory" looks silly, so switch to error_exit(). Additionally, the default format tests fail on Android because of SELinux (but for a different reason than usual!). There's no id --no-context flag, so use sed to just throw away any SELinux context.
2019-11-05id.c: fix -nG.Elliott Hughes
The previous patch broke -nG, so move the -G code back to showone() which handles -n. Add the missing tests for the various uses of -n. Also refactor the code to avoid the need to test optflags directly.
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-11-04id: various fixes.Elliott Hughes
Handle unknown groups (fixes #117). Fix -G to show *all* groups, not just all supplementary groups. Fix -Z output to not include "context=".
2019-11-03id: support numeric lookup.Elliott Hughes
Fall back to converting the "name" to an integer and calling getpwuid(). We need to update `username` for the later call to getgrouplist(). Also fix the separator printing logic to avoid a trailing ',' on `id 0`. Switch to FLAG() and move some declarations down to where they can be initialized, both for clarity. Also add simple tests. Sadly, there's no always-present user that is in multiple groups.
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-28Switch the fudge factor from 2048 to 4096 to unblock android build.Rob Landley
2019-10-28cp: treat a directory name with a slash at the end the same as one without a ↵William Haddon
slash
2019-10-28More xargs cleanup, with one possible accounting error but not what fixesRob Landley
the -0 "argument too long" issue.
2019-10-27Tar extract should delete files or symlinks where it's making a directory,Rob Landley
but --restrict checking should run on the path up to the last component before unlinking so tar can't be tricked into deleting random files off the system.
2019-10-26cut: re-enable crunch_str on cut -CJarno Mäkipää
Reason: unicolumns() does not print combining characters correctly Combining characters follow the character which they modify. https://www.cl.cam.ac.uk/~mgk25/unicode.html#comb xterm renders cut test1.txt -C -1 now correctly
2019-10-26Add ln -r and relative_path() to lib, plus test.Rob Landley
And a few small cleanups while I was there.
2019-10-24Fix the xargs argument too long problem by putting the proper accountingRob Landley
back when they haven't specified -s, add tests.
2019-10-22JakeSFR on github pointed out that broken symlink relative detection was beingRob Landley
checked relative to the current directory, not from where the symlink lives.
2019-10-21Use FLAG() macros more.Rob Landley
2019-10-21Remove getdirname(), it's _not_ a drop-in replacement for dirnameRob Landley
(it returns a malloc), and doesn't match the object lifetime of getbasename() (which always returns some or all of its argument string). The dirname() in libc modifies its argument string, but that's what posix says to do: https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/dirname.html so I guess we can live with it.
2019-10-21More xargs cleanup.Rob Landley
2019-10-21xargs: fix type of a local to avoid a cast.Elliott Hughes
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-15In-passing cleanup and add a NOP -P.Rob Landley
2019-10-14Make cmp work with 1 argument (implicit - as second argument).Rob Landley
2019-10-12Don't need the second variable, and put the comment back.Rob Landley
2019-10-12Fix argless find segfault.Denys Nykula
Inline array becomes garbage outside the if.
2019-10-09xargs: various fixes.Elliott Hughes
Don't run the command with no arguments if we run out of input but have already run the command at least once. The implementation of "run the command at least once (unless -r was supplied)" wasn't taking into account whether or not this was our first time round the loop. Fix the exit value, and the -- already documented but not implemented -- behavior if a child exits with status 255. Also extend the tests to cover these cases, plus cases I broke while coming up with the fix. Add more tests to convince myself that we've correctly interpreted how -s is supposed to behave, and fix the corner cases at the bottom end of the range. This fixes some issues we were seeing trying to build the Android SDK for (and more importantly, on) macOS.
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-10-08Add arch command.Rob Landley
2019-10-04ln.c: add -t to synopsis.Elliott Hughes
We're inconsistent about whether the option help below should be just `-t` or `-t DIR`, but the majority of commands _don't_ repeat their argument, so I've left that as-is for now.