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>
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>
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>
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>
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>
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>
<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>
If we have a square, the speedup can be extremely large
(in best case example below, it's ~40000 times faster):
$ time ./busybox_old factor 18446743988964486098
18446743988964486098: 2 3037000493 3037000493
real 0m4.246s
$ time ./busybox factor 18446743988964486098
18446743988964486098: 2 3037000493 3037000493
real 0m0.000s
function old new delta
isqrt_odd - 57 +57
print_w - 36 +36
factorize 218 236 +18
print_h - 7 +7
factorize_numstr 65 72 +7
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/0 up/down: 125/0) Total: 125 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
PLATFORM_LINUX is a hidden configuration option which is disabled by
default and enabled at over a hundred locations for features that are
deemed to be Linux specific.
The only effect of PLATFORM_LINUX is to control compilation of
libbb/match_fstype.c. This file is only needed by mount and umount.
Remove all references to PLATFORM_LINUX and compile match_fstype.c
if mount or umount is enabled.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Prior to the patch, both -f and --first-only are in all cases either
no-op or ignored.
Without --tabs, --first-only is the default so specifying it is a no-op.
With --tabs, --all is implied, and --first-only is intended to reset this.
function old new delta
expand_main 690 694 +4
Signed-off-by: Mark Edgar <medgar123@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
stime() has been deprecated in glibc 2.31 and replaced with
clock_settime(). Let's replace the stime() function calls with
clock_settime() in preperation.
function old new delta
rdate_main 197 224 +27
clock_settime - 27 +27
date_main 926 941 +15
stime 37 - -37
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/0 up/down: 69/-37) Total: 32 bytes
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
When IF_DESKTOP is not defined, chown and chgrp only takes option -R -h,
However the usage output of chgrp is wrong:
$ ./busybox.nosuid chown
Usage: chown [-Rh]... USER[:[GRP]] FILE...
$ ./busybox.nosuid chgrp
Usage: chgrp [-RhLHP]... GROUP FILE...
$ ./busybox.nosuid chgrp -H group dummy
chgrp: invalid option -- 'H'
Usage: chgrp [-RhLHP]... GROUP FILE...
The chgrp is now a wrapper of chown, so the recognized options shall be the same.
This is introduced by 34425389e0
I would expect the correct behavior shall be the same as chown.
So suggest the below patch, the behavior shall be:
$ ./busybox.nosuid chgrp
Usage: chgrp [-Rh]... GROUP FILE...
Signed-off-by: Shuang Liu <sliu@de.adit-jv.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>