[OpenWrt-Devel] Is printf considered to be guaranteed?
Sebastian Moeller
moeller0 at gmx.de
Fri Oct 12 18:47:35 EDT 2018
Dear mhei,
> On Oct 12, 2018, at 20:53, Michael Heimpold <mhei at heimpold.de> wrote:
>
> Am Donnerstag, 11. Oktober 2018, 22:44:53 CEST schrieb Sebastian Moeller:
>> Dear Luiz,
>>
>> thank you very much for this information. By now I have realized that printf
>> evaluated locale (specifically LC_NUMERIC) at least on non-openwrt unices,
>> which makes it unfortunately unusable for my purpose.
>
> forcing local, e.g.
> LANG=C printf "%0.3f" 47.11
> does not help?
That might actually work, I tried LC_NUMERIC which did not work on openwrt.
> Maybe you could elaborate on your purpose?
Well I wanted to have a shell variable for configuring a buffer by the time in milliseconds required to empty that buffer (at a given bandwidth), but wanted to actually allow values down to microseconds.
So I tried to use the following to effectively convert a value in (fractional) milliseconds into microseconds for use by the actual consumer like:
TMP=1.015 ; printf %.0f\n "${TMP}e3"
Shell only operates on integers so doing it in shell did not give the desired results, and the printf trick seemed like a acceptable work-around. But due to the locale sensitivity I simply switched the configuration parameter from milliseconds to microseconds side stepping the whole problem. (The reason I wanted milliseconds to begin with is that my hypothesis is that single digit milliseconds are reasonable and sane values, but for exceptional cases it might be nice to go down to microseconds). I hope this clarifies the issue.
Best Regards
Sebastian
>
> Regards,
> mhei
>
>>
>> Best Regards
>> Sebastian
>>
>>> On Oct 11, 2018, at 19:58, Luiz Angelo Daros de Luca <luizluca at gmail.com>
>>> wrote:
>>>
>>> I think so. It is compiled by default:
>>>
>>> $ grep PRINTF -A2 package/utils/busybox/Config-defaults.in
>>> config BUSYBOX_DEFAULT_PRINTF
>>>
>>> bool
>>> default y
>>>
>>> --
>>> config BUSYBOX_DEFAULT_ASH_PRINTF
>>>
>>> bool
>>> default y
>>>
>>> --
>>> config BUSYBOX_DEFAULT_HUSH_PRINTF
>>>
>>> bool
>>> default n
>>>
>>> Regards,
>>
>> _______________________________________________
>> openwrt-devel mailing list
>> openwrt-devel at lists.openwrt.org
>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
>
>
>
>
>
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list