before:
Tiny RPN calculator. Operations:
+, -, *, /, %, ~, ^, |,
p - print top of the stack without popping
f - print entire stack
k - pop the value and set the precision
i - pop the value and set input radix
o - pop the value and set output radix
After:
Tiny RPN calculator. Operations:
Arithmetic: + - * / % ^
~ - divide with remainder
| - modular exponentiation
v - square root
p - print top of the stack without popping
f - print entire stack
k - pop the value and set precision
i - pop the value and set input radix
o - pop the value and set output radix
function old new delta
packed_usage 33519 33565 +46
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
musl libc's mallocng free() may modify errno if kernel does not support
MADV_FREE which causes echo to echo with error when it shouldn't.
Future versions of POSIX[1] will require that free() leaves errno
unmodified but til then, do not rely free() implementation.
Should fix downstream issues:
https://github.com/alpinelinux/docker-alpine/issues/134https://gitlab.alpinelinux.org/alpine/aports/-/issues/12311
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Zero-length path prefixes can be specified in PATH as a leading or
trailing colon or two adjacent colons. POSIX says that the use of
zero-length prefixes to refer to the current directory is a legacy
feature. Nonetheless the shells in BusyBox respect this feature,
as does 'which'.
Tab-completion of executables using PATH should support this too.
function old new delta
complete_cmd_dir_file 934 931 -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3) Total: -3 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Most BusyBox applets respond to the '--help' option by printing
a usage message. This is normally handled by busybox_main() so
applet main routines don't have support for '--help'.
In standalone shell mode with FEATURE_SH_NOFORK enabled nofork
applets are invoked directly, bypassing busybox_main(). This
results in inconsistent handling of '--help':
- applets which call getopt() report "unrecognized option '--help'"
and print help anyway;
- realpath says "--help: No such file or directory" and doesn't
print help;
- usleep says "invalid number '--help'" and doesn't print help.
Avoid inconsistency by checking for '--help' in run_nofork_applet().
Bug found by Ron Yorston.
function old new delta
show_usage_if_dash_dash_help - 70 +70
run_nofork_applet 347 362 +15
run_applet_no_and_exit 432 365 -67
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 85/-67) Total: 18 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
"In function 'sprint_status48':
error: format not a string literal and no format arguments"
function old new delta
sprint_status48 160 158 -2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
054493350 ("Do not add -lresolv on non-Linux systems") adds a condition
to link with libresolv only on linux systems.
The check requires that CONFIG_UNAME_OSNAME equals Linux. This works only
if the uname applet is enabled. Otherwise, CONFIG_UNAME_OSNAME is empty,
regardless of the platform.
By default, CONFIG_UNAME_OSNAME is the output of uname -o. For most
linux systems, uname -o returns "GNU/Linux" and the check fails. In this
case, linking a static busybox fails because of missing symbols from
libresolv.
networking/lib.a(nslookup.o): In function `add_query':
nslookup.c:789: undefined reference to `__res_mkquery'
networking/lib.a(nslookup.o): In function `parse_reply':
nslookup.c:355: undefined reference to `ns_initparse'
nslookup.c:361: undefined reference to `ns_parserr'
nslookup.c:404: undefined reference to `ns_name_uncompress'
nslookup.c:418: undefined reference to `ns_get16'
nslookup.c:419: undefined reference to `ns_name_uncompress'
..
nslookup.c:456: undefined reference to `ns_get16'
...
nslookup.c:469: undefined reference to `ns_name_uncompress'
...
nslookup.c:489: undefined reference to `ns_get32'
...
collect2: error: ld returned 1 exit status
This patch uses the output of $CC -dumpmachine to detect the target platform
for which we compile. Both gcc and clang support -dumpmachine. Like the
original patch, we link against libresolv only if our target platform is
linux-based.
Fixes: 054493350 ("Do not add -lresolv on non-Linux systems")
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Use a NULL value of maxsz_p to indicate to xmalloc_fgets_internal()
that the caller doesn't care about the maximum size of the buffer.
This allows the default maximum size to be set once in
xmalloc_fgets_internal() instead of separately in each caller.
function old new delta
xmalloc_fgets_internal 273 287 +14
xmalloc_fgets_str 30 9 -21
xmalloc_fgetline_str 33 12 -21
xmalloc_fgets_str_len 38 10 -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 14/-70) Total: -56 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The command 'nl -b n' should output no line numbers, just some
spaces as a placeholder followed by the actual file content.
Add tests for line numbering by cat and nl. The correct results
were obtained from coreutils.
function old new delta
print_numbered_lines 152 157 +5
.rodata 182456 182453 -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-3) Total: 2 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
'[-p N]' should be '[-P N]' in the trivial usage message.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Selection of ranges for change/delete/yank by forward character
motion commands (SPACE or 'l') was incorrect. The range was
always one character whereas vi allows the size of the range to
be specified.
Fix this by executing the motion command the required number of times.
There is a complication when the range is at the end of a line. We need
to distinguish between a range which excludes the last character and
one which includes it. This requires comparing the actual range with
that expected from the command count. (With the additional quirk that
a command count of zero is equivalent to a command count of one.)
function old new delta
find_range 587 619 +32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 32/0) Total: 32 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Rewrite index_in_strings() to replace calls to strcmp()/strlen().
With this change searching for valid names in the applet_names
array (for example) is 40% faster.
The code has to assume the strings aren't sorted, so will always scan
the entire array when presented with an invalid name.
function old new delta
index_in_strings 63 56 -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-7) Total: -7 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
find_applet_by_name() determines the appropriate range of applet
indices to check for the given name and performs a linear search in
applet_names[].
Revise the code so the index of the upper bound of the range, 'max',
isn't calculated. Instead check the value of the first non-matching
character to see if we've reached the end of the range.
This new code speeds up the time to find a valid applet name by 6%
and halves the time to detect that a given name is invalid. The
average time to detect an invalid name is now the same as for a valid
one.
function old new delta
find_applet_by_name 155 133 -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-22) Total: -22 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Treat the output of printf as binary rather than a null-terminated
string so that NUL characters can be output.
This is considered to be a GNU extension, though it's also available
in mawk and FreeBSD's awk.
function old new delta
evaluate 3487 3504 +17
awk_printf 504 519 +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 32/0) Total: 32 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
FreeBSD is not using <utmp.h> and does not define _PATH_UTMPX.
Tested with busybox applets depending on FEATURE_UTMP (e.g. who, users, etc)
Signed-off-by: Alex Samorukov <samm@os2.kiev.ua>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This patch addressing 2 issues:
1. Replacing source/dest with uh_sport/uh_dport. It seems that uh_* members are
defined on both Linux and BSD, so no #ifdef here
2. Use SOL_IPV6 instead of SOL_RAW on the FreeBSD to fix IPV6_CHECKSUM setsockopt
Signed-off-by: Alex Samorukov <samm@os2.kiev.ua>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
FreeBSD using different constant names, defining them inline
Signed-off-by: Alex Samorukov <samm@os2.kiev.ua>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
<sys/sysmacros.h> is linux-only
FreeBSD defines makedev in sys/types.h already included in the libbb.h.
Signed-off-by: Alex Samorukov <samm@os2.kiev.ua>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
FreeBSD does not use crypt.h, but unistd.h which is already included
Signed-off-by: Alex Samorukov <samm@os2.kiev.ua>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
FreeBSD is not exporting s6_addr32 by default, but has it.
Signed-off-by: Alex Samorukov <samm@os2.kiev.ua>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
FreeBSD uses setpgrp(pid_t, pid_t)
This patch makes crond.c and probably others compilable
Signed-off-by: Alex Samorukov <samm@os2.kiev.ua>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
On FreeBSD getaddrinfo and friends are part of libc.
Other OS-es will also have own dependencies
Signed-off-by: Alex Samorukov <samm@os2.kiev.ua>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Otherwise if $HISTFILE is unset or reassigned, bad things can happen.
function old new delta
ash_main 1210 1218 +8
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>