aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.h
AgeCommit message (Collapse)Author
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-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-08-26xargs: add --max-args synonym, -o option, and fix -p.Elliott Hughes
The Linux kernel uses the --max-args synonym for -n. Barbarians who use vi need xargs' -o to be able to do something like: find -name xargs.c | xargs vi # Sad vi. find -name xargs.c | xargs -o vi # Happy vi. The -p option needs fixing to read from /dev/tty because stdin is otherwise occupied in xargs. I think xargs is the only place that needs this, so it didn't seem sensible to make all callers to yesno() be specific about which they wanted, hence the new function. Also remove the documentation for the build-time XARGS_PEDANTIC option which isn't actually implemented. Also add a TODO for -P (which is used by at least one script in the Linux kernel).
2019-08-21Add xgetline (which the last sh checkin used, oops).Rob Landley
2019-07-12pidof: fix default behavior, add -x.Elliott Hughes
Before this patch, we're effectively doing `pidof -x` all the time. This patch changes names_to_pid() to allow us to say whether or not we want to include scripts, and adjusts the callers appropriately. Also add tests for `pidof` versus `pidof -x` which pass after this patch, without regressing the existing killall tests.
2019-07-11bind/connect cleanup.Elliott Hughes
Rename the existing xbind/xconnect to xbindany/xconnectany, to make room for new xbind/xconnect that are more like 'x' versions of the regular bind and connect. Move explicit bind/connect callers over to xbind/xconnect. Of the affected commands, only netcat is actually used by Android. It was the most recent patch to netcat that made the lack of a more traditional xbind/xconnect apparent.
2019-07-10dd: iflags, oflags, fix ^C, fix the fundamental loop.Elliott Hughes
Investigating why the toybox tar tests fail on Android with toybox dd, I realized I was rewriting a part of dd I'd rewritten before! This is a re-send of my 2019-02-22 patch, rebased against the current ToT... This patch was originally motivated because after suggesting to the author of https://stackoverflow.com/questions/17157820/access-vdsolinux/54797221#54797221 that he could tell dd to work in bytes rather than blocks, I realized that our dd doesn't actually support that. But the rewrite of the main loop is necessary to fix the incorrect output from the dd calls in the tar test. Without this patch, `yes | dd bs=65536 count=1 > fweep` basically gives random output, based on how many bytes the pipe feels like giving you in your first read. (As far as I know, dd *without* bs= was fine, but I can't guarantee that that's true, just that I haven't seen it fail.) Also switch to TAGGED_ARRAY and comma_* for conv rather than add two more copies of an undesired idiom. It turned out -- contrary to the belief of cp(1) -- that comma_scan isn't suitable for this because of its magic handling of "no" prefixes. (It's actually harmless in cp because none of the --preserve options begin with "no", but some dd options do.) To this end, comma_remove is a less-magic comma_scan. I've also changed an `if` to a `while` because other implementations allow things like `--preserve=mode,mode` or `conv=sync,sync`. (If we decide this is a bug rather than a feature, we should at least fix the error message to be clear that we're rejecting the *duplication*, not the option itself.) I've also fixed the ^C behavior by simply adding a direct SIGINT handler rather than trying to be clever inside the read loop (which is why we weren't handling the SIGINT until the read returned). I've also removed `strstarteq` and just added the '=' to each literal when calling regular `strstart`. Plus basic tests.
2019-07-10Add dlist_lpop() to remove last entry (use dlist as stack).Rob Landley
2019-06-11Add DIRTREE_STATLESS to return entries we couldn't stat().Rob Landley
Sets ->again |= 2 when that happens and ->st is zeroed. While we're there, don't memset(st) and then memcpy(st) over it, and use O_PATH in the open().
2019-06-11Move sig_to_num and num_to_sig into portability.c.Elliott Hughes
macOS doesn't have real-time signals, and it has a slightly different set of non-portable signals from Linux. With this, the toybox `kill -l` output matches the default macOS kill(1).
2019-06-10Improve signal name<->number conversions.Elliott Hughes
Include all the signals, not just the POSIX ones. In particular, improve support for real-time signals. My attempt to switch AOSP builds over to toybox timeout got reverted when I broke the ART build bots which use SIGRTMIN+2. Also fix `kill -l 3` to show "QUIT" and `kill -l QUIT` to show "3". Also make the `kill -l` output include numbers and names, and format it to look better on a 80x24 tty, because it's always August 1978 somewhere.
2019-06-01Teach file to recognize xz archives and old style tarballs.Rob Landley
2019-05-16Add human_readable_long() for more than 3 digits of output.Rob Landley
2019-05-11Teach tar to extract type 'S' sparse file headers.Rob Landley
2019-04-20Add xunsetenv() for the error checking.Rob Landley
2019-04-20New xsetenv() plumbing (repeatedly set same environment variables withoutRob Landley
leaking memory), and mod env command to test it.
2019-04-16Add argument to xflush() so it can test for stdout err without flushing.Rob Landley
2019-04-11scan_key: support more terminals.Elliott Hughes
Although we can get away with ignoring termcap/terminfo on the output side by restricting ourselves to generally-supported escape sequences, the input side is trickier because we need to support the sequences sent by common terminals. Luckily, this isn't is as bad as it sounds because only Home/End commonly differ. But it does mean we need a slightly different implementation to deal with the many-to-one mapping. Since we can't use TAGGED_ARRAY for this (without inflicting pain on all the callers) I've also switched to OR-ing in the modifier keys, so we have (say) KEY_UP|KEY_SHIFT rather than a separate KEY_SUP. This also generalizes better should we ever need to support multiple modifiers at once. To reduce the number of #defines, I've also switched from KEY_F1, KEY_F2, and so on to KEY_FN+1, KEY_FN+2, and so on. This isn't obviously necessary, and easily undone if we'd rather have move #defines in return for slightly more natural naming. To enable all this, I've inverted scan_key and scan_key_getsize so that scan_key_getsize is now the underlying function, and we don't waste all the top bits encoding width and height between scan_key and scan_key_getsize. Tested by pressing Home and End in hexedit in all of the terminals available to me.
2019-03-27Change fileunderdir() to return abspath to file.Rob Landley
2019-03-26Make touch use xparsedate() (result: -t and -d the same, autodetects format),Rob Landley
and fix tests to pass on host too.
2019-03-24Factor out xparsedate() and xvali_date() into lib.Rob Landley
2019-03-10Make multiple sendfile variants, and teach xpopen_both() to use existingRob Landley
stdin/stdout filehandles.
2019-03-09Half-finished su change checked in, sorry.Rob Landley
2019-03-07Add reset_env() and make su and login use it. Do long-delayed login cleanup.Rob Landley
2019-02-23Bumper typo cleanup.Elliott Hughes
Inspired by some of the small patches that have gone by recently. Limited to only things found in `generated/help.h`, plus a wider cleanup for the more common "milisecond" typo.
2019-02-13Move nanomove(), nanodiff(), union socksaddr, and xrecvwait() to lib.Rob Landley
2019-01-22Fix sigjmp_buf/jmp_buf mismatches.Elliott Hughes
Broke the bionic build: external/toybox/toys/net/netcat.c:188:37: error: incompatible pointer types assigning to 'sigjmp_buf *' (aka 'long (*)[33]') from 'jmp_buf *' (aka 'long (*)[32]') [-Werror,-Wincompatible-pointer-types] if (toys.optflags&FLAG_L) NOEXIT(child = XVFORK()); ^~~~~~~~~~~~~~~~~~~~~~~~ external/toybox/lib/lib.h:375:19: note: expanded from macro 'NOEXIT' #define NOEXIT(x) WOULD_EXIT(_noexit_res, x) ^~~~~~~~~~~~~~~~~~~~~~~~~~ external/toybox/lib/lib.h:367:16: note: expanded from macro 'WOULD_EXIT' toys.rebound = &_noexit; \ ^ ~~~~~~~~ 1 error generated.
2019-01-16Move xsendto() to lib/net.c.Rob Landley
2019-01-12sed: add -z.Elliott Hughes
Used to construct SELinux policies in the AOSP build. I left loopfiles_lines with its hard-coded '\n' because although cut(1) also has a -z option, I can't find any case where it's used in any of the codebases searchable by me. (And fmt(1), the other user, doesn't even have the option.) YAGNI. Bug: http://b/122744241
2019-01-12Merge xconnect/xbind.Rob Landley
2018-12-27Make poke() alignment-agnostic.Rob Landley
2018-12-23Add grep --colorRob Landley
2018-12-14Add xrename()Rob Landley
2018-12-10nc: add IPv6 support.Josh Gao
2018-11-28macOS: replace local strnstr with strcasestr.Elliott Hughes
bionic, glibc, macOS, and musl all have strcasestr (see http://man7.org/linux/man-pages/man3/strstr.3.html). macOS (via BSD) has a strnstr that does what strnstr sounds like it should do by analogy with strnlen and strncpy. So we at least need to rename strnstr, but it probably makes more sense just to switch to strcasestr instead.
2018-11-28macOS: noreturn.Elliott Hughes
The macOS libc headers use `__attribute__((noreturn))` rather than `__attribute__((__noreturn__))`, so toybox's `noreturn` macro trips them up. Since we already have a variety of uses of `__attribute__` that aren't guarded in this way, let's do the same here.
2018-10-21Add % to lib/args.c (long time in milliseconds), add xmillitime(), redoRob Landley
xparsetime() not to need floating point, adjust callers.
2018-10-21Move start_redraw() to lib/ and have ps.c (top) use it.Rob Landley
2018-10-10Add xsignal_flags() and more consistently use xsignal() instead of signal().Rob Landley
xsignal() wraps sigaction() giving control of SA_RESTART behavior and such.
2018-08-17Make microcom use set_terminal() and move speed setting into set_terminal().Rob Landley
2018-08-07Forgot to check in the deflate header change, and pending shouldn't default y.Rob Landley
2018-07-04diff: add timestamps to the ---/+++ lines and --color.Elliott Hughes
(My apologies for mixing these two unrelated changes up.)
2018-04-08Add cp --parentsRob Landley
2018-04-08Add mkpath() for common case of mkpathat(), and #define magic constants.Rob Landley
2018-04-03Factor out xtempfile()Rob Landley
2018-03-31Remove semicolon from WOULD_EXIT() macro (screws up if statement levels).Rob Landley
2018-03-10Split "comma separated values" parsing from mntent.h plumbing.Rob Landley
2018-03-10Add a way for commands to distinguish "ps -ax" from "ps ax".Rob Landley
2018-01-30Basic ping support.Rob Landley
Requires echo 0 $((1<<30)) > /proc/sys/net/ipv4/ping_group_range (as root)
2018-01-14Switch xgettty() -> tty_fd() (returning -1 instead of erroring out if none).Rob Landley