Commit graph

2110 commits

Author SHA1 Message Date
Denys Vlasenko
14f57f5357 cut: code shrink
move "linenum" manipulations to the one place where it is used.

function                                             old     new   delta
cut_main                                            1373    1360     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-21 00:43:45 +01:00
Denys Vlasenko
1ea89fa98a cut: code shrink
This change eliminates one temporary:

-       if (dcount++ < cut_list[cl_pos].startpos)
+       dcount++;
+       if (dcount <= cut_list[cl_pos].startpos)

function                                             old     new   delta
cut_main                                            1402    1373     -29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-21 00:24:30 +01:00
Denys Vlasenko
b03f5162ac cut: fix up -D/-s behavior with -F
function                                             old     new   delta
cut_main                                            1388    1402     +14
packed_usage                                       34934   34933      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-1)              Total: 13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-20 22:12:33 +01:00
Denys Vlasenko
dd40b40ee5 cut: remove unnecessary initialization of regmatch_t
function                                             old     new   delta
cut_main                                            1404    1388     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-20 21:46:32 +01:00
Denys Vlasenko
e2304d47a9 cut: shorten error messages on bad syntax even more
$ cut -s -b3
cut: -s requires -f or -F
$ cut -d@ -b3
cut: -d DELIM requires -f or -F

function                                             old     new   delta
static.requires_f                                      -      19     +19
static._op_on_field                                   32       -     -32
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/0 up/down: 19/-32)            Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-16 01:12:17 +01:00
Denys Vlasenko
ee8b94acbf cut: shorten error messages on bad syntax
We don't need to mimic GNU cut error messages.

$ cut -d@ -b3
cut: -d DELIM makes sense only with -f or -F
$ cut -s -b3
cut: -s makes sense only with -f or -F

function                                             old     new   delta
static._op_on_field                                   31      32      +1
.rodata                                           105659  105598     -61
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 1/-61)             Total: -60 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-16 00:53:51 +01:00
Denys Vlasenko
0bd84c9472 cut: terminate cut_list[] so that we don't need "size of the array" variable
function                                             old     new   delta
cut_main                                            1410    1404      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-16 00:32:57 +01:00
Denys Vlasenko
ba9651b803 cut: we can't get empty cut_list[], remove the check for that
function                                             old     new   delta
.rodata                                           105685  105659     -26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-16 00:19:43 +01:00
Denys Vlasenko
e8622f0d85 cut: disallow -f '' and -f '-'
function                                             old     new   delta
cut_main                                            1391    1410     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-15 12:27:33 +01:00
Denys Vlasenko
b25ea3f156 cut: fix -F n-m to match toybox
function                                             old     new   delta
cut_main                                            1339    1391     +52

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-14 13:58:49 +01:00
Denys Vlasenko
d48400d8fb cut: simplify getopt32 code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 20:35:28 +01:00
Denys Vlasenko
7624077772 cut: "it's legal to pass an empty list" seems to be untrue
function                                             old     new   delta
cut_main                                            1344    1339      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 20:22:05 +01:00
Denys Vlasenko
f4f8dc6864 cut: whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 19:43:53 +01:00
Denys Vlasenko
ed6561685c cut: tweak comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 19:39:34 +01:00
Denys Vlasenko
96a230f17b cut: fix handling of -d ''
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 19:31:41 +01:00
Denys Vlasenko
9adafbc118 cut: prevent infinite loop if -F REGEX matches empty delimiter
function                                             old     new   delta
cut_main                                            1339    1348      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-13 19:13:20 +01:00
Denys Vlasenko
a4894eaf71 cut: tweak --help
function                                             old     new   delta
packed_usage                                       34901   34934     +33
cut_main                                            1353    1339     -14
.rodata                                           105724  105685     -39
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 33/-53)            Total: -20 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-11 01:10:05 +01:00
Denys Vlasenko
9e364b16d1 cut: fix -d$'\n' --output-delimiter=@@ behavior
function                                             old     new   delta
cut_main                                            1261    1353     +92
packed_usage                                       34925   34901     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 92/-24)             Total: 68 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 21:01:52 +01:00
Denys Vlasenko
a208fa03de cut: implement --output-delimiter
function                                             old     new   delta
cut_main                                            1204    1261     +57
static.cut_longopts                                    -      20     +20
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 77/0)               Total: 77 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 18:49:10 +01:00
Denys Vlasenko
b402b13fab cut: with -F disabled in .config, don't show it in --help
function                                             old     new   delta
packed_usage                                       34897   34849     -48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 18:09:07 +01:00
Denys Vlasenko
38a3c0ad32 cut: comment out code which seems to be not needed
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 17:50:29 +01:00
Denys Vlasenko
103139d0e6 cut: fix "echo 1.2 | cut -d. -f1,3" (print "1", not "1.")
function                                             old     new   delta
cut_main                                            1228    1201     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 17:21:30 +01:00
Denys Vlasenko
470f009552 cut: with -F, do not regcomp() pattern for every file
function                                             old     new   delta
cut_main                                            1218    1228     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 02:55:58 +01:00
Denys Vlasenko
55fc6a18da cut: rename "cut_lists" to "cut_list"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 02:29:48 +01:00
Denys Vlasenko
1220b1519d cut: rename some variables to hopefully better names
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 02:15:25 +01:00
Denys Vlasenko
808155ebf3 cut: "orig_line" is redundant, remove it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:55:25 +01:00
Denys Vlasenko
478ac90f2c cut: allocate "printed" only if OPT_CHAR or OPT_BYTE
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:50:58 +01:00
Denys Vlasenko
ad12ab439b cut: localize 'spos' variable, convert !NUMVAR to NUMVAR == 0
This imporves readability

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:44:13 +01:00
Denys Vlasenko
73e9d25d75 cut: simplify OPT_ names, eliminate one variable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:38:31 +01:00
Ron Yorston
f020414413 cut: improve detection of invalid ranges
Commit 0068ce2fa (cut: add toybox-compatible options -O OUTSEP,
-D, -F LIST) added detection of reversed ranges.  Further
improvements are possible.

- The test for reversed ranges compared the start after it had been
  decremented with the end before decrement.  It thus missed ranges
  of the form 2-1.

- Zero isn't a valid start value for a range.  (Nor is it a valid
  end value, but that's caught by the test for a reversed range.)

- The code

        if (!*ltok)
            e = INT_MAX;

  duplicates a check that's already been made.

- Display the actual range in the error message to make it easier
  to find which range was at fault.

function                                             old     new   delta
.rodata                                           100273  100287     +14
cut_main                                            1239    1237      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-2)              Total: 12 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:29:44 +01:00
Colin McAllister
50e2b59370 cut: fix "-s" flag to omit blank lines
Using cut with the delimiter flag ("-d") with the "-s" flag to only
output lines containing the delimiter will print blank lines. This is
deviant behavior from cut provided by GNU Coreutils. Blank lines should
be omitted if "-s" is used with "-d".

This change introduces a somewhat naiive, yet efficient solution, where
line length is checked before looping though bytes. If line length is
zero and the "-s" flag is used, the code will jump to parsing the next
line to avoid printing a newline character.

function                                             old     new   delta
cut_main                                            1196    1185     -11

Signed-off-by: Colin McAllister <colinmca242@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-10 01:27:04 +01:00
Denys Vlasenko
0929a129fc test: -x can return 0/1 early if all X bits are the same
function                                             old     new   delta
nexpr                                                702     725     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 07:33:58 +02:00
Denys Vlasenko
96b0607302 ash: cache more of uid/gid syscalls
Testcase:
setuidgid 1:1 strace ash -c 'test -x TODO; test -x TODO; echo $?'
should show that second "test -x" does not query ids again.

function                                             old     new   delta
ash_main                                            1236    1256     +20
get_cached_euid                                        -      19     +19
get_cached_egid                                        -      19     +19
test_main                                             56      72     +16
test_exec                                            119     135     +16
is_in_supplementary_groups                            52      57      +5
nexpr                                                718     702     -16
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/1 up/down: 95/-16)             Total: 79 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 07:28:44 +02:00
Denys Vlasenko
d26e958725 ash: make "test -x" use cached groupinfo
function                                             old     new   delta
test_main2                                             -     407    +407
testcmd                                               10      23     +13
test_main                                            418      56    -362
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 420/-362)           Total: 58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 07:14:27 +02:00
Denys Vlasenko
4c1d645c86 libbb: simplify parameter passing in is_in_supplementary_groups()
function                                             old     new   delta
is_in_supplementary_groups                            54      52      -2
nexpr                                                721     718      -3
test_exec                                            125     119      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-11)             Total: -11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 06:36:00 +02:00
Denys Vlasenko
748b168154 libbb: move is_in_supplementary_groups() from test to libbb
function                                             old     new   delta
is_in_supplementary_groups                             -      54     +54
nexpr                                                766     721     -45
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 54/-45)              Total: 9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 01:20:43 +02:00
Denys Vlasenko
bb5525613e test: Invert return value of test_eaccess and rename it to test_st_mode
From dash:

    From: herbert <herbert@gondor.apana.org.au>
    Date: Wed, 2 Mar 2005 22:14:54 +1100
    Invert return value of test_eaccess and rename it to test_st_mode.

function                                             old     new   delta
nexpr                                                800     766     -34

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06 19:25:07 +02:00
Denys Vlasenko
222802e833 test: code shrink
function                                             old     new   delta
nexpr                                                813     800     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06 19:08:10 +02:00
Ron Yorston
e4b5ccd13b timeout: allow fractional seconds in timeout values
The 'timeout' applet uses parse_duration_str() to obtain its
timeout values.  The default configuration enables float durations.

However, the applet silently ignores fractional seconds.  This
results in unexpected behaviour:

   $ timeout 5.99 sleep 5.1; echo $?
   Terminated
   143

When float durations are enabled ensure that any fractional seconds
are taken into account.

function                                             old     new   delta
timeout_wait                                          44      92     +48
timeout_main                                         383     365     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-18)             Total: 30 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 21:34:18 +02:00
Ron Yorston
a3c5068306 md5/shaXsum: accept uppercase hex strings
The coreutils versions of md5sum and the like accept uppercase hex
strings from checksum files specified with the '-c' option.

Use a case-insensitive comparison so BusyBox does the same.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-11 18:17:31 +02:00
Denys Vlasenko
2075553a1b libbb: add bit counting function, use where appropriate
Although "naive" counting function is not too slow and is smaller,
using it on e.g. each of 1024 words of CPU mask feels wrong.

function                                             old     new   delta
bb_popcnt_32                                           -      52     +52
get_prefix                                           323     321      -2
nproc_main                                           206     199      -7
d4_run_script                                        739     731      -8
ipcalc_main                                          533     507     -26
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/4 up/down: 52/-43)              Total: 9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-05-31 16:03:23 +02:00
Denys Vlasenko
5a68a246e7 nproc: prepare for arbitrarily large CPU masks
function                                             old     new   delta
get_malloc_cpu_affinity                                -      76     +76
nproc_main                                           216     206     -10
process_pid_str                                      250     206     -44
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 76/-54)             Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-05-31 11:58:48 +02:00
Denys Vlasenko
a97a2f1280 ls: do not truncate username/groupname to 8 chars
function                                             old     new   delta
.rodata                                           105412  105408      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-25 01:06:30 +01:00
Petr Vorel
d17c0a348f sleep: Update doc
4c20d9f2b removed FEATURE_FLOAT_SLEEP option, thus since then there are
only two variants.

Fixes: 4c20d9f2b ("extend fractional duration support to "top -d N.N" and "timeout"")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 16:59:09 +01:00
Nero
6d22c9abc2 install: Fix chown resetting suid/sgid bits from chmod
Since Linux 2.2.13, chown(2) resets the suid/gid bits for all users.
This patch changes the ordering so that chmod gets called after chown.

This behavior follows GNU coreutils.

Signed-off-by: Nero <nero@w1r3.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-02 14:26:27 +02:00
Denys Vlasenko
791b222dd5 sleep: fix "sleep -- ARGS"
function                                             old     new   delta
sleep_main                                           116     119      +3
printf_main                                          860     837     -23
single_argv                                           50      25     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-48)             Total: -45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-02 13:56:32 +02:00
Ron Yorston
2cc9d436e8 tsort: avoid use-after-free
When the input data contained a cycle it was possible for tsort to
attempt to access freed nodes.  This sometimes resulted in the
test case 'echo a b b a | tsort' crashing.

Don't free nodes when they're removed from the graph.

function                                             old     new   delta
tsort_main                                           621     596     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-08-31 09:41:53 +02:00
Denys Vlasenko
c484846c44 introduce and use exitcode_t
function                                             old     new   delta
strings_main                                         422     420      -2
setfattr_main                                        175     173      -2
brctl_main                                          1548    1546      -2
makedevs_main                                        979     975      -4
rev_main                                             337     332      -5
getfattr_main                                        307     302      -5
cut_main                                            1201    1196      -5
cksum_main                                           398     393      -5
umount_main                                          573     565      -8
ln_main                                              516     508      -8
expand_main                                          660     652      -8
df_main                                             1068    1060      -8
renice_main                                          346     332     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/13 up/down: 0/-76)            Total: -76 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-17 17:29:36 +02:00
Denys Vlasenko
5353df91cb Update applet size estimates
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 17:25:21 +02:00
Denys Vlasenko
6d9427420b od: -l,I,L indeed depend on sizeof(long), fix this
function                                             old     new   delta
.rodata                                           105255  105252      -3
od_main                                             1917    1901     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19)             Total: -19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 20:17:04 +02:00