[PATCH v2 3/3] touch: add --time=what option

Denys Vlasenko vda.linux at googlemail.com
Tue Apr 13 13:17:57 UTC 2021


>  #if ENABLE_FEATURE_TOUCH_SUSV3
>      char *reference_file = NULL;
>      char *date_str = NULL;
> +    IF_LONG_OPTS(char *time_arg = NULL;)

These are actually long-ish insns
(on x86, "mov immediate" (and "test") has no byte-extending version,
unlike ALU ops). Sometimes it's cheaper to test
if (opt & OPT_l)...   than  if (optstr)...
- the former does not require NULLing.

> +        static const char *time_values ALIGN1 =
> +            /* OPT_a: */ "access\0" "atime\0" "use\0"
> +            /* OPT_m: */ "modify\0" "mtime\0";
> +        int pos = index_in_substrings(time_values, time_arg);
> +
> +        if (pos >= 3) {
> +            opts |= OPT_m;
> +        } else if (pos >= 0) {
> +            opts |= OPT_a;
> +        } else {
> +            //bb_error_msg("Invalid value: %s", time_arg);
> +            bb_show_usage();
> +        }

how about this instead? -
           opts |= (time_arg[0] == 'm') ? OPT_m : OPT_a;


More information about the busybox mailing list