On 11/04/2021 07.41, urmum-69 wrote:
> 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.
> -
> -             result = (ENABLE_FEATURE_TOUCH_NODEREF && (opts & OPT_h) ? 
> lutimes : utimes)(*argv, newtime);
> -
> +             int result =
> +#if ENABLE_FEATURE_TOUCH_NODEREF
> +             (opts & OPT_h) ? utimensat(AT_FDCWD, *argv, newtime, 
> AT_SYMLINK_NOFOLLOW) :
> +#endif
> +             utimensat(AT_FDCWD, *argv, newtime, 0);

OPT_h is 0 if ENABLE_FEATURE_TOUCH_NODEREF is not set. So all of this
can be simplified by just using

  (opts & OPT_h) ? AT_SYMLINK_NOFOLLOW : 0

as the flags argument. Maybe, for line length and readability, assign
that to a "const unsigned flags" local variable and pass that. But no
need to split a ternary operator across ifdeffery.

Other than that, from a quick read-through, it looks good.

Rasmus
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to