Importing inttypes methods from FreeBSD

Aditya Upadhyay aadit0402@gmail.com
Wed Jul 19 13:23:00 GMT 2017


Thanks Corinna for helping me to understand these stuff. I am making
the changes with this snippet.

Regards,
Aditya

On Wed, Jul 19, 2017 at 5:58 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
> Hi Aditya,
>
> On Jul 19 03:09, Aditya Upadhyay wrote:
>> diff --git a/newlib/libc/stdlib/strtoimax.c b/newlib/libc/stdlib/strtoimax.c
>> new file mode 100644
>> index 000000000..0cb6e2acc
>> --- /dev/null
>> +++ b/newlib/libc/stdlib/strtoimax.c
>> @@ -0,0 +1,146 @@
>> [...]
>> +intmax_t
>> +strtoimax_l(struct _reent *rptr, const char * __restrict nptr, char ** __restrict endptr, int base,
>> +             locale_t loc)
>> +{
>
> This is not quite what you want.  strtoimax_l in BSD does not require a
> reent as first parameter.  By changing the function this way, you
> disallow to export the function in a BSD-compatible way.  Also keep in
> mind that it's always possible that the function name might become
> standarized (POSIX) at one point, just like the original GNU
> locale-specific functions got standarized.
>
> What you really want is to define a static function which takes the
> reent pointer and strtoimax_l/strtoimax only calling that, like this:
>
> --- snip ---
> static intmax_t
> _strtoimax_r(struct _reent *rptr, const char * __restrict nptr,
>              char ** __restrict endptr, int base, locale_t loc)
> {
>   [Add here all functionality you put into strtoimax_l]
> }
>
> intmax_t
> strtoimax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
>              locale_t loc)
> {
>   return _strtoimax_r (_REENT, nptr, endptr, base, loc);
> }
>
> intmax_t
> strtoimax(const char * __restrict nptr, char ** __restrict endptr, int base)
> {
>   return _strtoimax_r (_REENT, nptr, endptr, base, __get_current_locale ());
> }
> --- snap ---
>
> Also, please keep the line length < 80 chars if possible.
>
>
> Thanks,
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat



More information about the Newlib mailing list