Thanks for doing all that.
This is a net positive I think, though for the record there are some 
disadvantages.

I see both current locale and C locale formats are accepted.
Allowing both C and local locales does introduce some ambiguity.
For example users in the german locale may expect 1.234
to wait 1234 seconds:

  $ LC_NUMERIC=de_DE printf "%'d\n" 1234
  1.234
  $ time LC_NUMERIC=de_DE sleep 1.234
  real  0m1.237s

Now I agree that allowing both is better/required for backwards compat.
BTW I see that sleep in ksh only supports the current locale, which is
surprising at it breaks scripts that specified say 1.2 when run under some 
locales.
I also see that printf in bash (4.3) also only supports the locale decimal 
format,
thus having the same compat issue.

Also it's worth noting that allowing locale specific input limits the 
portability of scripts,
to specific locales, and to new enough implementations of sleep(1) etc.

BTW I checked that multi-byte decimal points are supported with:

  LC_NUMERIC=ps_AF.utf8 src/sleep 1٫234

I pushed a small syntax-check fix,
and have attached a proposed test.

cheers,
Pádraig
diff --git a/tests/misc/sleep.sh b/tests/misc/sleep.sh
index c20ce01..141067f 100755
--- a/tests/misc/sleep.sh
+++ b/tests/misc/sleep.sh
@@ -39,4 +39,13 @@ returns_ 124 timeout 0.1 sleep 1d 2h 3m 4s || fail=1
 returns_ 124 timeout 0.1 sleep inf || fail=1
 returns_ 124 timeout 0.1 sleep $LDBL_MAX || fail=1
 
+# Test locale decimal handling for printf, sleep, timeout
+f=$LOCALE_FR_UTF8
+: ${LOCALE_FR_UTF8=none}
+if test "$LOCALE_FR_UTF8" != "none"; then
+  locale_decimal=$(LC_ALL=$f env printf '%0.3f' 0.001) || fail=1
+  locale_decimal=$(LC_ALL=$f env printf '%0.3f' "$locale_decimal") || fail=1
+  LC_ALL=$f timeout 1$locale_decimal sleep "$locale_decimal" || fail=1
+fi
+
 Exit $fail

Reply via email to