Commit Graph

1995 Commits

Author SHA1 Message Date
Ron Yorston
2dade4f18a uniq: really support -z
Commit 894466cc5 (uniq: support -z) added support for NUL delimited
output.  Unfortunately nobody told getopt32().

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-24 23:37:06 +02:00
Denys Vlasenko
6481070eb9 nproc: code shrink
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-24 13:47:49 +02:00
Denys Vlasenko
df96a3cd08 ls: code shrink
function                                             old     new   delta
scan_and_display_dirs_recur                          576     574      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-24 13:37:53 +02:00
Denys Vlasenko
56bbbfae7d cp: implement -n
function                                             old     new   delta
.rodata                                           103681  103722     +41
packed_usage                                       33698   33717     +19
copy_file                                           1678    1696     +18
cp_main                                              500     492      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 78/-8)              Total: 70 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-22 15:28:34 +02:00
Denys Vlasenko
91b9549a8c crc32: code shrink for !CKSUM config
function                                             old     new   delta
cksum_main                                           215     203     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-22 10:24:06 +02:00
Denys Vlasenko
836580a7d6 cksum: fix handling of read errors
function                                             old     new   delta
cksum_main                                           377     399     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-22 09:29:22 +02:00
Denys Vlasenko
ea9b96e5aa crc32: new applet
function                                             old     new   delta
cksum_main                                           258     377    +119
.rodata                                           103672  103681      +9
applet_names                                        2745    2751      +6
applet_main                                         1588    1592      +4
packed_usage                                       33734   33698     -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 138/-36)           Total: 102 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-22 01:07:54 +02:00
Denys Vlasenko
0ec52d438a cp: implement -t DIR
function                                             old     new   delta
packed_usage                                       33713   33734     +21
.rodata                                           103670  103672      +2
cp_main                                              506     500      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 23/-6)              Total: 17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-21 19:38:39 +02:00
Denys Vlasenko
1de709fda2 cp: preparatory indenting of code block, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-21 19:38:02 +02:00
Denys Vlasenko
d82c937a31 df: support -t TYPE
function                                             old     new   delta
packed_usage                                       33656   33716     +60
df_main                                             1029    1065     +36
.rodata                                           103395  103397      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 98/0)               Total: 98 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-20 15:03:21 +02:00
Denys Vlasenko
a2a9113f35 df: POSIXLY_CORRECT sets _default_ scale, -m/-h overrides it
function                                             old     new   delta
df_main                                             1034    1029      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-20 14:46:19 +02:00
Denys Vlasenko
d71c7892ac shred: with -u, unlink file even if it is zero length
function                                             old     new   delta
shred_main                                           391     387      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-20 13:48:21 +02:00
Denys Vlasenko
ec3170ac95 shred: implement -s SIZE
function                                             old     new   delta
shred_main                                           337     391     +54
.rodata                                           103393  103395      +2
packed_usage                                       33666   33656     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 56/-10)             Total: 46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-20 13:08:50 +02:00
Denys Vlasenko
c113796884 env: implement -0
function                                             old     new   delta
packed_usage                                       33590   33618     +28
env_main                                             187     209     +22
.rodata                                           103242  103250      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 58/0)               Total: 58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-17 13:39:46 +02:00
Denys Vlasenko
91bc01c59b mv: implement -t and -T
function                                             old     new   delta
mv_main                                              496     585     +89
.rodata                                           103188  103242     +54
packed_usage                                       33549   33590     +41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 184/0)             Total: 184 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-17 12:59:33 +02:00
Denys Vlasenko
894466cc51 uniq: support -z
function                                             old     new   delta
uniq_main                                            391     427     +36
packed_usage                                       33570   33549     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 36/-21)             Total: 15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-17 00:36:13 +02:00
Denys Vlasenko
e7a8e8e30c du: support -b "apparent size"
function                                             old     new   delta
du                                                   434     470     +36
packed_usage                                       33542   33570     +28
print                                                 57      78     +21
du_main                                              286     302     +16
.rodata                                           103187  103188      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 102/0)             Total: 102 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-16 17:45:28 +02:00
Denys Vlasenko
e47000490c shuf: simplify check that we have at least one FILE
function                                             old     new   delta
.rodata                                           103190  103194      +4
packed_usage                                       33541   33537      -4
shred_main                                           354     337     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 4/-21)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15 10:39:33 +02:00
Denys Vlasenko
1f60d88cf6 *: more --help tweaks
function                                             old     new   delta
packed_usage                                       33552   33541     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15 10:00:18 +02:00
Denys Vlasenko
e2b9215868 *: --help tweaks
function                                             old     new   delta
packed_usage                                       33589   33552     -37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-14 20:47:20 +02:00
Denys Vlasenko
643b308029 base32/64: accept -i "skip bad chars" option (currently in effect unconditionally)
function                                             old     new   delta
.rodata                                           103189  103190      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-13 23:58:17 +02:00
Denys Vlasenko
6f7b10cdab *: more --help tweaking
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-13 03:51:55 +02:00
Denys Vlasenko
1849285a20 *: more --help tweaks, mostly expanding ts --help
function                                             old     new   delta
packed_usage                                       33554   33596     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-13 03:12:09 +02:00
Denys Vlasenko
6b6826f0b8 *: --help tweaks
function                                             old     new   delta
.rodata                                           103190  103189      -1
packed_usage                                       33590   33566     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-13 01:08:48 +02:00
Denys Vlasenko
08ea7be73b ls: trim --help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-05 10:36:17 +02:00
Sören Tempel
3d9c649158 ls: don't output any colors with TERM=dumb
The TERM variable is usually set to "dumb" to indicate that the terminal
does not support any ANSI escape sequences. Presently, ls does not honor
this variable and outputs colors anyhow which results in unreadable
output, unless the user explicitly disables colors using `ls
--color=never`. The rational behind this change is that ls should "just
work" by default, even on dumb terminals.

For this reason, this patch adds a check which additionally consults the
TERM variable before printing any colors. This is analogous to the
existing check for ensuring that standard output is a tty. As such,
colors can still be forced with `--color=force`, even if TERM is set to
dumb.

function                                             old     new   delta
is_TERM_dumb                                           -      40     +40
ls_main                                              579     598     +19
.rodata                                           103246  103251      +5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 64/0)               Total: 64 bytes

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-04 22:39:10 +02:00
Denys Vlasenko
f193aeac1f tail: do not lose the tail of old file if new file (-F) is detected
function                                             old     new   delta
tail_main                                           1619    1645     +26
.rodata                                           103246  103250      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 30/0)               Total: 30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-02 05:17:44 +02:00
Denys Vlasenko
e0ea125ce2 tail: fix typo in variable name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-02 04:11:40 +02:00
Denys Vlasenko
b9258b86a7 head,tail: trim --help text
function                                             old     new   delta
packed_usage                                       33598   33560     -38

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-02 04:01:10 +02:00
Denys Vlasenko
7c813fbabf echo: fix !ENABLE_FEATURE_FANCY_ECHO build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-14 18:55:30 +02:00
Denys Vlasenko
ba9f9c2d2c *: --help text tweaks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-14 15:15:45 +02:00
Denys Vlasenko
93f1255af2 touch: shorten --help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-14 14:52:09 +02:00
Denys Vlasenko
d156bcf71e touch: code shrink
function                                             old     new   delta
touch_main                                           424     421      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-14 14:46:35 +02:00
Denys Vlasenko
fe9507f8c3 touch: fix -am
function                                             old     new   delta
touch_main                                           414     424     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-14 01:01:20 +02:00
Rafał Miłecki
4eb46e1be6 dd: support iflag=count_bytes
It allows passing amount of bytes in the count=

function                                             old     new   delta
packed_usage                                       33599   33617     +18
static.iflag_words                                    29      41     +12
dd_main                                             1601    1607      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0)               Total: 36 bytes

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-13 21:35:57 +02:00
Denys Vlasenko
9c210f0efb touch: fix previous commit
function                                             old     new   delta
touch_main                                           423     414      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-13 15:49:06 +02:00
Denys Vlasenko
6b6ff80299 touch: make FEATURE_TOUCH_NODEREF unconditional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-13 15:45:59 +02:00
Denys Vlasenko
3630054504 touch: code shrink
function                                             old     new   delta
touch_main                                           450     423     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-13 15:41:57 +02:00
Denys Vlasenko
6f63a2ba0e touch: code shrink
function                                             old     new   delta
.rodata                                           103215  103218      +3
touch_main                                           460     450     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 3/-10)              Total: -7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-13 15:11:47 +02:00
Xabier Oneca
e3c6a0973c touch: prevent usage of -r and -t at once
coreutils forbids this combination.

Signed-off-by: Xabier Oneca <xoneca@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-13 14:48:24 +02:00
Denys Vlasenko
79c92dbd70 touch: switch to using utimensat() and futimens()
This patch changes the functions used to update timestamps in touch.

Before, utimes() and lutimes() were used, which had certain
disadvantages.
They are unable to handle nanosecond timestamps, and implementations of
certain features like -a and -m require running stat() in a loop.

Almost all implementations of utimes() and lutimes() are wrappers for
utimensat(), this is the case for glibc, ulibc and musl libc.

function                                             old     new   delta
__futimens_time64                                      -      24     +24
__lutimes_time64                                      80       -     -80
touch_main                                           539     456     -83
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/1 up/down: 24/-163)          Total: -139 bytes

Signed-off-by: urmum-69 <urmum69@snopyta.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-13 11:31:46 +02:00
Denys Vlasenko
1a181264d5 touch: unbreak -h
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-12 20:12:56 +02:00
Xabier Oneca
7ec254467c touch: remove unneeded GETOPT32 defines
Long options handling (getopt32 vs getopt32long) is done in libbb.h, no need to
care here of the same logic. This cleans the code a bit.

Also, --no-create was grouped as a SUSv3 option, where as the short -c was not.
Even if it is part of SUS, leave it out as was the short option.

v2: Fix for disabled ENABLE_LONG_OPTS. getopt32long does not like
  IF_FEATURE_xxx() style conditionals... :/

Signed-off-by: Xabier Oneca <xoneca@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-12 20:05:48 +02:00
Xabier Oneca
de1a49cb41 touch: fix atime set from reference file
When using a file's times as reference, use both atime and mtime for the files
to be modified.

Signed-off-by: Xabier Oneca <xoneca@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-12 20:05:48 +02:00
Xabier Oneca
520bb3eac2 touch: add SUSv3 options -a and -m
Add missing -a and -m options to be fully SUSv3 compliant.

function                                             old     new   delta
touch_main                                           415     510     +95
packed_usage                                       33824   33865     +41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 136/0)             Total: 136 bytes

v2: Ignore -a/-m if not ENABLE_FEATURE_TOUCH_SUSV3.

Signed-off-by: Xabier Oneca <xoneca@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-12 20:05:48 +02:00
Denys Vlasenko
c2bd0b6806 timeout,top,watch,ping: parse NN.N fractional duration in locales with other separators
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-23 13:50:02 +01:00
Natanael Copa
e880c9c100 echo: do not assume that free() leaves errno unmodified
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/134
https://gitlab.alpinelinux.org/alpine/aports/-/issues/12311

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-23 12:59:29 +01:00
Ron Yorston
cad3fc743a libbb: introduce and use fputs_stdout
function                                             old     new   delta
fputs_stdout                                           -      12     +12
zxc_vm_process                                      7237    7230      -7
yes_main                                              85      78      -7
write_block                                          380     373      -7
wrapf                                                305     298      -7
strings_main                                         437     430      -7
show_bridge                                          353     346      -7
rev_main                                             384     377      -7
put_prompt_custom                                     58      51      -7
put_cur_glyph_and_inc_cursor                         168     161      -7
print_numbered_lines                                 152     145      -7
print_named_ascii                                    130     123      -7
print_name                                           135     128      -7
print_login_issue                                    386     379      -7
print_ascii                                          208     201      -7
powertop_main                                       1249    1242      -7
od_main                                             1789    1782      -7
logread_main                                         518     511      -7
head_main                                            804     797      -7
display_process_list                                1319    1312      -7
cut_main                                            1002     995      -7
bb_dump_dump                                        1550    1543      -7
bb_ask_noecho                                        393     386      -7
baseNUM_main                                         702     695      -7
expand_main                                          755     745     -10
dumpleases_main                                      497     487     -10
write1                                                12       -     -12
putcsi                                                37      23     -14
print_login_prompt                                    55      41     -14
paste_main                                           525     511     -14
cat_main                                             440     426     -14
print_it                                             245     230     -15
print_addrinfo                                      1188    1171     -17
print_rule                                           770     750     -20
print_linkinfo                                       842     822     -20
httpd_main                                           791     771     -20
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/34 up/down: 12/-341)         Total: -329 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-03 20:52:40 +01:00
Ron Yorston
c849e72c0b nl: ensure '-b n' option displays file content
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>
2021-02-02 17:37:41 +01:00
Alex Samorukov
28759d0e95 Fix mknod compilation on the FreeBSD
<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>
2021-01-04 13:28:28 +01:00