[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH 1/1] libbb: fix parse_duration_str with LOCALE_SUPPORT
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2021-03-26 11:03:21
Message-ID: CAK1hOcM9B-boGY4ft0sMuAuZ4rKV_gpvN2XbMob1aZEpiPR9uw () mail ! gmail ! com
[Download RAW message or body]

Applied, thank you.

On Mon, Mar 22, 2021 at 6:21 AM Maxim Kochetkov <fido_max@inbox.ru> wrote:
>
> Decimal dot may differs from ".", so we need to set LC_NUMERIC to "C" before
> processing duration string by strtod()
>
> Signed-off-by: Maxim Kochetkov <fido_max@inbox.ru>
> ---
>  coreutils/sleep.c | 4 ----
>  libbb/duration.c  | 7 +++++++
>  2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/coreutils/sleep.c b/coreutils/sleep.c
> index 7bfaab920..2658e84df 100644
> --- a/coreutils/sleep.c
> +++ b/coreutils/sleep.c
> @@ -74,10 +74,6 @@ int sleep_main(int argc UNUSED_PARAM, char **argv)
>                         sleep(INT_MAX);
>
>  #if ENABLE_FEATURE_FANCY_SLEEP
> -# if ENABLE_FLOAT_DURATION
> -       /* undo busybox.c setlocale */
> -       setlocale(LC_NUMERIC, "C");
> -# endif
>         duration = 0;
>         do {
>                 duration += parse_duration_str(*argv);
> diff --git a/libbb/duration.c b/libbb/duration.c
> index 086da15fb..cbbb7336d 100644
> --- a/libbb/duration.c
> +++ b/libbb/duration.c
> @@ -33,6 +33,10 @@ static const struct suffix_mult duration_suffixes[] ALIGN_SUFFIX = {
>  duration_t FAST_FUNC parse_duration_str(char *str)
>  {
>         duration_t duration;
> +# if ENABLE_LOCALE_SUPPORT
> +       /* undo busybox.c setlocale */
> +       setlocale(LC_NUMERIC, "C");
> +# endif
>
>         if (strchr(str, '.')) {
>                 double d;
> @@ -54,6 +58,9 @@ duration_t FAST_FUNC parse_duration_str(char *str)
>                 duration = xatoul_sfx(str, duration_suffixes);
>         }
>
> +#if ENABLE_LOCALE_SUPPORT
> +       setlocale(LC_NUMERIC, "");
> +#endif
>         return duration;
>  }
>  void FAST_FUNC sleep_for_duration(duration_t duration)
> --
> 2.30.2
>
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic