This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Importing inttypes methods from FreeBSD


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

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]