aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2021-02-20Fix df on macOS.Elliott Hughes
On Linux, struct statvfs' f_bsize and f_frsize seem to be interchangeable. On macOS, they're wildly different. f_bsize is the "preferred length of I/O requests for files on this file system" (corresponding to statfs::f_iosize), and f_frsize is the "size in bytes of the minimum unit of allocation on this file system" (corresponding to statfs::f_bsize. POSIX appears to say nothing about the interpretation of these fields, but man7.org's statvfs(2) page is quite clear that statvfs::f_blocks, for example, is in units of f_frsize, not f_bsize. This is the only place in the tree where we use statvfs::f_bsize (other than the stat(1) output that's supposed to be f_bsize and that has a corresponding f_frsize dual anyway. I've removed the Apple-specific #define f_frsize in portability.h because that seems to have been from my previous attempt to understand what was going on here. The output of the relevant stat(1) fields on macOS are the same before/after this patch. This makes toybox df's output match the system's df on a MacBook Pro running macOS 11.2.1. Tested on a Raspberry Pi 400 running Linux too, where I see no change in the output before/after this patch.
2021-02-08Have xclose() perform the fd != -1 test.Rob Landley
2021-02-08Yi-Yo Chiang pointed out install -D was broken when the target file exists.Rob Landley
Add a test, with comment that "make install_test" doesn't currently exist...
2021-02-07Add lots of "static" annotations, make a couple things use FLAG() macros, etc.Rob Landley
2021-01-26Fix bug pointed out by asm89 and add test.Rob Landley
2021-01-15Cleanup base32 slightly.Rob Landley
2021-01-13Fix "date -I" segfault and teach lib/args.c that "I(opt):;" short opt withRob Landley
no argument returns NULL same as --opt without =
2021-01-07new toy: base32Moritz Röhrich
Add new toy `base32`. Add tests for `base32`. base32 is added by adapting the base64 encode/decode function to also do base32 encoding/decoding. Then their respective main functions set up the global parameter `n` to be the number of bits used in the encoding (5 for base32 and 6 for base64) and `align` to align the result to a certain length via padding. These are deliberately kept as parameters to enable future expansion for other bases easily.
2021-01-06main.c: construct a combination locale to add UTF-8.Elliott Hughes
We need <xlocale.h> for newlocale(3) on macOS, despite it being in POSIX 2008's <locale.h>. musl apparently doesn't have <xlocale.h>, so that's another trick to teach to portability.h...
2021-01-01Fix comma regression reported by Denys Nykula.Rob Landley
2020-12-18Andy Hu wants mount -tnomsdos,smbfs to work.Rob Landley
2020-12-14Follow RFC1952 when consuming gzip headerPuck Meerburg
The FEXTRA field, indicated by bit 2 of the flag byte, contains arbitrary extra data, prefixed by a 16-bit length value. The previous code skipped over the length, but not the actual contents, breaking decompression of certain files.
2020-12-11The "fall back to C.UTF-8" check was backwards, and make TOYFLAG_LINEBUFRob Landley
configurable.
2020-12-06unicode: new toy.Elliott Hughes
Based loosely on the Plan9/Inferno utility, and a convenient way to go back and forth between code points and utf8 sequences. This patch also fixes a couple of bugs in wctoutf8 (and the tests for this toy effectively serve as unit tests for wctoutf8/utf8towc).
2020-12-06Remove CONFIG_TOYBOX_I18N and just always support utf8.Rob Landley
2020-12-05Small cleanup.Rob Landley
2020-12-04chmod: support complex modes.Elliott Hughes
Change 5109da9b3e6a898c8e0ad647303a1b375e3d97d3 caused test.test to call chmod with mode `u+s+s` which passes on the host (where you have a toybox test but a GNU chmod) but fails on Android where chmod is toybox too. Add the missing loop to string_to_mode(), which means this will also affect other toys, but that seems like a feature (and, for example, GNU mkdir also accepts a mode like `a=r+w+x`).
2020-11-18Fix microcom to set serial device's terminal correctly.Rob Landley
Can't use the same set_terminal() logic as ptys because it not displaying data, it should just accurately copy it.
2020-11-17That last sh.c change had a lib/ change I forgot to check in.Rob Landley
2020-11-14Allow 0 prefix to optstr to include argv[0] in optargs[0].Rob Landley
2020-11-07xregcomp: add the specific regex we couldn't parse to the error message.Elliott Hughes
This makes it more likely that you can actually debug something like "sed: bad regex: empty (sub)expression" or "sed: bad regex: parentheses not balanced" from a build failure log, where you don't necessarily know where the failure came from. This also seems like it might be useful generally, although GNU grep doesn't include this detail in its error messages, and busybox doesn't even seem to notice that regcomp() failed? (Realistically if the Android build team wants to move forward with "one true regex implementation", we're going to have to add some GNU-isms to the Android regex implementation. But we'd need to find them first! Note that the two examples given above are real examples from failed buildbot builds, but they occur early in the respective builds so there are likely many more to look at after these. Interestingly, the first of the two appears to be the more general case of something disallowed by POSIX that xregcomp() already has a workaround for.)
2020-11-06portability.h: ensure _FILE_OFFSET_BITS=64 takes effect.Elliott Hughes
I added a #include above this, which caused subtle breakages on 32-bit systems. Move it to the top of the file to fix it and avoid making a similar mistake in future.
2020-10-29Make it easier to switch regex implementations.Elliott Hughes
One reason to use toybox on the host is to get the same behavior across Android/Linux/macOS. Unfortunately (as we've seen from a few bugs) one area where that doesn't quite work is that toybox uses the libc regular expression implementation. That's fine, and mostly what users want, but those folks trying to get the exact same behavior everywhere might want to switch in a known regex implementation (bionic's NetBSD regex implementation, say) for increased consistency. That actually works pretty well, but portability.h has an #ifndef test for REG_STARTEND before including <regex.h> that gets in the way. To make up for that, this patch removes the unnecessary #include <regex.h> from grep.c itself.
2020-10-28Tweak help text again.Rob Landley
2020-10-22Fix thinko.Rob Landley
2020-10-22Add nommu-able xvdaemon() and use it to remove some TOYBOX_FORK dependenciesRob Landley
2020-10-15Three trivial code cleanups and a comment tweak.Rob Landley
2020-10-15Nitpicky cleanup.Rob Landley
We need to *name = 0 explicitly for the !name && !statless case, so don't need the +1 in memset that was only zeroing in the !name && statless case.
2020-10-15dirtree_path: always honor size request.Elliott Hughes
tar asks dirtree_path() to reserve space for a trailing '/', but recent changes broke that for the case that was resolving to just a strdup(). Caught by `export ASAN=1` and `make test_tar`.
2020-10-12Fix bug introduced last commit: the if (name) else case needs to zero it.Rob Landley
2020-10-11toysh: more variable/wildcard plumbing and tests.Rob Landley
2020-10-06The non-recursive dirtree_path wasn't stripping a trailing / from initial path.Rob Landley
2020-10-03Return empty string for dirtree_path() of "" (instead of NULL).Rob Landley
2020-10-03Non-recursive dirtree_path() needs to return start of allocationRob Landley
when passed in extra allocation length or else free() gets very unhappy.
2020-09-26Teach dirtree that top level "" node is "." but not show in dirtree_path().Rob Landley
2020-09-23Have read_password() read from tty device, handle ctrl-c and ctrl-d.Rob Landley
2020-09-23Chris Sarra pointed out that nerfing xprintf() so it doesn't actually flushRob Landley
broke the password: prompt.
2020-09-12Replace HR_COMMAS with HR_NODOTRob Landley
The comma thing turned into an internationalization can of worms, don't go there. Keep the "show megabytes on systems with >10G" logic which includes not showing 0.0 for single digit values.
2020-09-09Attempt internationalization of HR_COMMAS, 9 digit memory sizes for top,Rob Landley
and use the comma format when selected even if <3 digits (no 0.0M)
2020-09-04Add commas to top display, and adjust memory units to megabytes if >10G RAM.Rob Landley
2020-08-27xparsedate: support default date(1) output format.Elliott Hughes
This round trip occurs in practice with $KBUILD_BUILD_TIMESTAMP in kernel builds.
2020-08-21xputsl: fix the *other* line in this function :-)Elliott Hughes
Some of the grep tests were still failing because we weren't flushing stdout --- xflush takes a bool that says whether to actually flush, so we need to pass 1, not 0.
2020-08-20xputsl: write to stdout, not stdin!Elliott Hughes
This is why the tests have been failing since 42303209f44a335025b9cd1dbe5dd2f3069f2e99.
2020-08-19xputsl: remove unused variable.Elliott Hughes
2020-08-15If we fflush(stdout) first we can just write to filehandle.Rob Landley
2020-08-13list_signals: fit to window size.Elliott Hughes
Helps for terminals narrower than 80 columns (such as ConnectBot on a current Android device).
2020-08-04Inline convert_tz()Rob Landley
2020-08-04xparsedate: support UTC offsets.Elliott Hughes
Requested in https://github.com/landley/toybox/issues/130, quoting an old version of the toybox help. This is also supported by coreutils. Set $LANG to C in the date tests so that they pass with TEST_HOST=1 (they were already failing for me, presumably related to a newer glibc).
2020-08-04Toysh signal handling adds a few EINTR recovery corner cases to lib.Rob Landley
2020-08-04echo: fix trailing \0.Elliott Hughes
This is a follow-on from 310eefe, addressing the case where sscanf fails and returns -1.