diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-03-23 13:50:02 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-03-23 13:50:02 +0100 |
| commit | c2bd0b680667c7ec4956552f75d9ff7d040ac941 (patch) | |
| tree | 8d117fedfebe03f6f97071ebc522d4ac03f08c47 | |
| parent | 14ed4ec8a416a60a214bf40f9185aa227ac44598 (diff) | |
| download | busybox-w32-c2bd0b680667c7ec4956552f75d9ff7d040ac941.tar.gz busybox-w32-c2bd0b680667c7ec4956552f75d9ff7d040ac941.tar.bz2 busybox-w32-c2bd0b680667c7ec4956552f75d9ff7d040ac941.zip | |
timeout,top,watch,ping: parse NN.N fractional duration in locales with other separators
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | coreutils/printf.c | 1 | ||||
| -rw-r--r-- | coreutils/sleep.c | 4 | ||||
| -rw-r--r-- | coreutils/sort.c | 1 | ||||
| -rw-r--r-- | libbb/duration.c | 14 | ||||
| -rw-r--r-- | miscutils/dc.c | 1 | ||||
| -rw-r--r-- | networking/brctl.c | 1 |
6 files changed, 16 insertions, 6 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c index a20fc3301..dd94c8ade 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
| @@ -122,6 +122,7 @@ static void FAST_FUNC conv_strtod(const char *arg, void *result) | |||
| 122 | char *end; | 122 | char *end; |
| 123 | /* Well, this one allows leading whitespace... so what? */ | 123 | /* Well, this one allows leading whitespace... so what? */ |
| 124 | /* What I like much less is that "-" accepted too! :( */ | 124 | /* What I like much less is that "-" accepted too! :( */ |
| 125 | //TODO: needs setlocale(LC_NUMERIC, "C")? | ||
| 125 | *(double*)result = strtod(arg, &end); | 126 | *(double*)result = strtod(arg, &end); |
| 126 | if (end[0]) { | 127 | if (end[0]) { |
| 127 | errno = ERANGE; | 128 | errno = ERANGE; |
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) | |||
| 74 | sleep(INT_MAX); | 74 | sleep(INT_MAX); |
| 75 | 75 | ||
| 76 | #if ENABLE_FEATURE_FANCY_SLEEP | 76 | #if ENABLE_FEATURE_FANCY_SLEEP |
| 77 | # if ENABLE_FLOAT_DURATION | ||
| 78 | /* undo busybox.c setlocale */ | ||
| 79 | setlocale(LC_NUMERIC, "C"); | ||
| 80 | # endif | ||
| 81 | duration = 0; | 77 | duration = 0; |
| 82 | do { | 78 | do { |
| 83 | duration += parse_duration_str(*argv); | 79 | duration += parse_duration_str(*argv); |
diff --git a/coreutils/sort.c b/coreutils/sort.c index b194847d1..6c4e3038c 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
| @@ -295,6 +295,7 @@ static int compare_keys(const void *xarg, const void *yarg) | |||
| 295 | #if ENABLE_FEATURE_SORT_BIG | 295 | #if ENABLE_FEATURE_SORT_BIG |
| 296 | case FLAG_g: { | 296 | case FLAG_g: { |
| 297 | char *xx, *yy; | 297 | char *xx, *yy; |
| 298 | //TODO: needs setlocale(LC_NUMERIC, "C")? | ||
| 298 | double dx = strtod(x, &xx); | 299 | double dx = strtod(x, &xx); |
| 299 | double dy = strtod(y, &yy); | 300 | double dy = strtod(y, &yy); |
| 300 | /* not numbers < NaN < -infinity < numbers < +infinity) */ | 301 | /* not numbers < NaN < -infinity < numbers < +infinity) */ |
diff --git a/libbb/duration.c b/libbb/duration.c index 086da15fb..a6a29ddae 100644 --- a/libbb/duration.c +++ b/libbb/duration.c | |||
| @@ -37,8 +37,18 @@ duration_t FAST_FUNC parse_duration_str(char *str) | |||
| 37 | if (strchr(str, '.')) { | 37 | if (strchr(str, '.')) { |
| 38 | double d; | 38 | double d; |
| 39 | char *pp; | 39 | char *pp; |
| 40 | int len = strspn(str, "0123456789."); | 40 | int len; |
| 41 | char sv = str[len]; | 41 | char sv; |
| 42 | |||
| 43 | # if ENABLE_LOCALE_SUPPORT | ||
| 44 | /* Undo busybox.c: on input, we want to use dot | ||
| 45 | * as fractional separator in strtod(), | ||
| 46 | * regardless of current locale | ||
| 47 | */ | ||
| 48 | setlocale(LC_NUMERIC, "C"); | ||
| 49 | # endif | ||
| 50 | len = strspn(str, "0123456789."); | ||
| 51 | sv = str[len]; | ||
| 42 | str[len] = '\0'; | 52 | str[len] = '\0'; |
| 43 | errno = 0; | 53 | errno = 0; |
| 44 | d = strtod(str, &pp); | 54 | d = strtod(str, &pp); |
diff --git a/miscutils/dc.c b/miscutils/dc.c index e94dc39e0..42baa67ad 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c | |||
| @@ -229,6 +229,7 @@ static void stack_machine(const char *argument) | |||
| 229 | const struct op *o; | 229 | const struct op *o; |
| 230 | 230 | ||
| 231 | next: | 231 | next: |
| 232 | //TODO: needs setlocale(LC_NUMERIC, "C")? | ||
| 232 | number = strtod(argument, &end); | 233 | number = strtod(argument, &end); |
| 233 | if (end != argument) { | 234 | if (end != argument) { |
| 234 | argument = end; | 235 | argument = end; |
diff --git a/networking/brctl.c b/networking/brctl.c index e1f3e6445..c83aac6e0 100644 --- a/networking/brctl.c +++ b/networking/brctl.c | |||
| @@ -89,6 +89,7 @@ static unsigned str_to_jiffies(const char *time_str) | |||
| 89 | { | 89 | { |
| 90 | double dd; | 90 | double dd; |
| 91 | char *endptr; | 91 | char *endptr; |
| 92 | //TODO: needs setlocale(LC_NUMERIC, "C")? | ||
| 92 | dd = /*bb_*/strtod(time_str, &endptr); | 93 | dd = /*bb_*/strtod(time_str, &endptr); |
| 93 | if (endptr == time_str || dd < 0) | 94 | if (endptr == time_str || dd < 0) |
| 94 | bb_error_msg_and_die(bb_msg_invalid_arg_to, time_str, "timespec"); | 95 | bb_error_msg_and_die(bb_msg_invalid_arg_to, time_str, "timespec"); |
