aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
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.
2020-06-19Bugfix: the code to trim \n off xgetline() was using allocated not read length.Rob Landley
2020-06-01Use copy_file_range() when available.Rob Landley
2020-05-28portability.c: fix macOS build.Elliott Hughes
I suspect the rest of the non-POSIX signals might end up like this, but this is the subset that needs to be #ifdef'ed to fix the macOS build.
2020-05-26Instead of ifdef linux or macos, just ifdef the signals.Rob Landley
2020-05-21Check the signal rather than special case a library and a target.Rob Landley
2020-05-21glibc on mips is missing SIGSTKFLTKhem Raj
Do not therefore assume it being available linuxwide Fixes | lib/portability.c:433:3: error: use of undeclared identifier 'SIGSTKFLT' | SIGNIFY(STKFLT), SIGNIFY(POLL), SIGNIFY(PWR), | ^ Signed-off-by: Khem Raj <raj.khem@gmail.com>
2020-05-21David Legault reported that unescape2() doesn't handle \0 rightRob Landley
because scanf("0%o") needs a 0 _and_ one or more digits. So add it to the end of the \n translation list (where it returns the null terminator).
2020-05-19xsignal_all_killers() should install the handler given to it, and do someRob Landley
refactoring while I was looking at the codepath.
2020-05-05Fix 32 bit option parsing for long long optflag values.Rob Landley
2020-05-03Next round of shell work.Rob Landley
2020-04-13Add unescape2(), migrate some unescape() users over.Rob Landley
2020-04-02Move #include <linux/*.h> into individual commands, initialize structRob Landley
with memset() instead of = {}, and move TT.alarm to local variable.
2020-04-02More shell plumbing. Redo of variable storage, add export.Rob Landley
2020-04-01Add rtcwake.Elliott Hughes
Some of the bringup folks are debugging RTC issues and asked for this. Rather than duplicate the weird xtzset dance with mktime, I've factored that out into a new xmktime that takes a boolean for whether to use UTC or local time. Otherwise, the slight cleanup of hwclock.c is entirely optional. The only functional change there is that util-linux 2.34's hwclock uses ISO time format, which is the usual toybox preference anyway, so I've switched it over to that rather than ctime(3). Bug: http://b/152042947
2020-03-18Fix WARN_ONLY (and the one caller feeding it in the field it was checking).Rob Landley
2020-03-12Fix get_block_device_size() for linuxGreg Kaiser
We were incorrectly passing a pointer to a pointer of an unsigned long long, when we just wanted to pass a pointer to the unsigned long long. This is especially bad on 32-bit systems, where we're then writing a 64-bits into a 32-bit value within ioctl. We fix this to pass a pointer to the unsigned long long. Test: On 32-bit device, no longer see native crash from toybox Bug: http://b/151311535 Signed-off-by: Elliott Hughes <enh@google.com>
2020-03-11fdlength: device size is reported in bytes, not blocks.Elliott Hughes
The shift was a remnant from when BLKGETSIZE (which measures in blocks) was being used on Linux. The Mac has two separate ioctls for block count and block size, which we're already multiplying together. And on Linux we're using BLKGETSIZE64, which returns a result in bytes, not blocks. So lose the shift.
2020-03-11Fix Mac build.Elliott Hughes
The recent re-enablement of the BLKGETSIZE64 code broke the Mac build. Use the equivalent <sys/disk.h> ioctl() pair instead.
2020-03-10modinfo: various fixes.Elliott Hughes
I came here because the new -Wno-unreachable-code-loop-increment warning didn't like the for loop on line 86. That loop is indeed not necessary. Use strend() to do a string suffix match. Use memmem() to search. It's available on macOS and Android by default, but it's behind _GNU_SOURCE for glibc, so add that to portability.h. Output the tags in the same order as the Debian modinfo. I've left "parmtype" in even though the Debian modinfo doesn't output it at all. Also fix the tests so that they work on a device that has modules for multiple kernels installed (like my laptop) --- make sure that the two modules we pick come from the same kernel.