aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
AgeCommit message (Collapse)Author
2019-03-27Change fileunderdir() to return abspath to file.Rob Landley
2019-03-10Add missing isatty(3) call.Elliott Hughes
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-03-04Consistently use ARRAY_LEN.Elliott Hughes
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-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
2018-12-27Make poke() alignment-agnostic.Rob Landley
2018-12-14Add xrename()Rob Landley
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-10-10Trivial speedup to format_iso_time(), teach parsetime() leading garbage != 0.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-07-08Fix division by zero errors and double summary in ping.Rob Landley
2018-07-04Add xgetrandom() with probe for new system call (else open/read /dev/{,u}random)Rob Landley
2018-07-04diff: add timestamps to the ---/+++ lines and --color.Elliott Hughes
(My apologies for mixing these two unrelated changes up.)
2018-07-02Fix bugs in yesterday's bufgetgrgid() work (reported by Elliott).Rob Landley
2018-06-30Loop retrying larger allocation sizes for bufgetpwuid/bufgetgrgid.Rob Landley
Slightly tweaked version of Elliott's patch. We probably only need to do this for groups (struct group * has a list of users that belong to it, but struct passwd doesn't, getgrouplist() is separate) but keeping the code of the two similar in case there's a way to merge them later.
2018-06-14Change do_lines() semantics to end with a callback(0,0) to indicate EOF,Rob Landley
adjusting existing users.
2018-05-03Add uuidgen.Elliott Hughes
Reuse create_uuid, but make it match the current RFC.
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-22atolx should use tolower instead of toupperMinghui Liu
2018-03-20Fix atolx not integer error when used with suffix *dMinghui Liu
2018-03-20Minghui Liu pointed out that the b and c suffixes were reported as errors.Rob Landley
2018-03-12Fix bug in names_to_pid.Elliott Hughes
Found by the compiler, not me: lib/lib.c:1053:30: warning: 'st2.st_dev' may be used uninitialized in this function [-Wmaybe-uninitialized] if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) continue; ~~~^~~~~~~
2018-02-09Fix the pidof comm and cmdline tests.Elliott Hughes
If we have a 15-byte name, we don't know whether comm actually matches or is a truncated form of a longer name that has a common prefix. For example, with "this-is-a-very-long-name-that-is-too-long", we shouldn't match "this-is-a-very-" (but the old code would). The cmdline code was also broken on Android because it used basename(3) rather than getbasename. This doesn't affect glibc because there's a workaround in portability.h to ensure that we get the non-POSIX basename(3) with glibc but then a non-glibc section that ensures everyone else gets POSIX basename(3). That should probably be removed (and maybe `basename` poisoned) to prevent similar mistakes in future. Bug: http://b/73123244
2018-01-06Move millitime() into lib.c.Rob Landley
2018-01-01Cleanup logger.c, and move the facilitynames/prioritynames SYSLOG_NAMESRob Landley
stuff syslog.h does into lib.c and portability.h
2017-12-22Redo namestopid to handle more cases.Rob Landley
2017-12-19killall should kill scripts too.Elliott Hughes
Found running LTP file system tests on Android. Bug: http://b/70627145
2017-12-03Don't capitalize in the middle of a sentence.Elliott Hughes
Before: toy: Unknown option p (See "toy --help") After: toy: Unknown option p (see "toy --help")
2017-10-10Tweak help_exit() to show "See %s --help" message on the same line.Rob Landley
2017-10-10Complete rewrite of cut. Handle multipe ranges, add -DFO options, startRob Landley
of utf8 support (not finished yet)... Adds new loopfiles_lines() wrapper to lib.c that calls do_lines from loopfiles.
2017-10-01Fix xargs to obey POSIX's ARG_MAX restrictions.Elliott Hughes
This avoids "xargs: exec echo: Argument list too long" errors in practice. find(1) needs to be fixed too, but that's a bit more complicated and a working xargs provides a workaround. Bug: http://b/65818597 Test: find /proc | strace -f -e execve ./toybox xargs echo > /dev/null
2017-09-05Tweak utf8towc() to return -1 earlier sometimes (instead of -2), and add testRob Landley
program to compare against libc output.
2017-09-02utf8towc() has to be in lib.c if strlower() is going to use it, becauseRob Landley
scripts/*.c builds against lib.c but not linestack.c.
2017-07-07Make dd use atolx_range(), and teach atolx_range() about "w" suffix (word, *2).Rob Landley
2017-06-26Most things seem to want the "b" suffix to mean 512 instead of 1.Rob Landley
(According to the git history I added "b" for "od" but the man page says 512 there too.)
2017-06-06Add comment explaining strend()Rob Landley
2017-06-05Have help_exit() give a brief "See %s --help" message instead of theRob Landley
full help text, and put it back in the args constraint failures.
2017-05-21Cleaup chrtRob Landley
2017-05-08Move strend() to lib/lib.cRob Landley
2017-02-204a4b3d65644ce403b0f22887fc0d38b0202ec8c7 upset clang.Elliott Hughes
Recent-ish clang doesn't like self-assignment. Google/Android code always uses the [template-based moral equivalent of] __attribute__((__unused__)) to keep both compilers happy.
2017-02-05Silence a warning.Rob Landley
Once upon a time you could call fchown() and let it fail. Then gcc decided not using its return code was inconcievable, but you could typecast it to (void) to shut it up. Then gcc noticed people doing that and clutched its pearls and took it away, so I added an if() statement that does nothing with the result because we _expect_ this to fail when we're not root. Then clang started complaining about an if (); statement with the semicolon on the same line, but decided it's ok if the ; is on the next line (I.E. significant whitespace in C), so I'm adding an "assignemnt to self" that gets optimized away so it does a more _explicit_ nothing (the same way you suppress gcc's broken "this isn't used uninitialized" warnings). If the compilers weren't going to so much trouble to force the issue I might add code to only call fchown when we're UID 0, but I refuse to be coerced into it. (And if getpid() is still a system call instead of a vdso member then it doesn't actually _save_ us anything, the dentry should be hot and the permission check was just "if (!uid)" before selinux entered into it and we're operating on an fd so the security's the same.)
2016-09-30sed -i run as root wasn't preserving ownership.Rob Landley
2016-09-05Replace loopfiles' failok with WARN_ONLY open flag.Rob Landley
2016-09-03Move genericish function to lib.Rob Landley
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.)