Importing inttypes methods from FreeBSD

Corinna Vinschen vinschen@redhat.com
Wed Jul 19 12:28:00 GMT 2017


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20170719/7c63b495/attachment.sig>


More information about the Newlib mailing list