#define __WRAPPED_L_(x) x ## _l
#define __WRAPPED_L__(x) __WRAPPED_L_(x)
#define __WRAPPED_L __WRAPPED_L__(__WRAPPED)
#if defined(_KERNEL) || defined(_STANDALONE) || \
defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
__TYPE
_FUNCNAME(const char * __restrict nptr, char ** __restrict endptr, int base,
__TYPE lo, __TYPE hi, int * rstatus)
#else
#include <locale.h>
#include "setlocale_local.h"
#define INT_FUNCNAME_(pre, name, post) pre ## name ## post
#define INT_FUNCNAME(pre, name, post) INT_FUNCNAME_(pre, name, post)
static __TYPE
INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char * __restrict nptr,
char ** __restrict endptr, int base,
__TYPE lo, __TYPE hi, int * rstatus, locale_t loc)
#endif
{
#if !defined(_KERNEL) && !defined(_STANDALONE)
int serrno;
#endif
__TYPE im;
char *ep;
int rep;
_DIAGASSERT(hi >= lo);
_DIAGASSERT(nptr != NULL);
if (endptr == NULL)
endptr = &ep;
if (rstatus == NULL)
rstatus = &rep;
*rstatus = 0;
if (base != 0 && (base < 2 || base > 36)) {
#if !defined(_KERNEL) && !defined(_STANDALONE)
*rstatus = EINVAL;
if (endptr != NULL)
*endptr = __UNCONST(nptr);
return 0;
#else
panic("%s: invalid base %d", __func__, base);
#endif
}
#if !defined(_KERNEL) && !defined(_STANDALONE)
serrno = errno;
errno = 0;
#endif
#if defined(_KERNEL) || defined(_STANDALONE) || \
defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
im = __WRAPPED(nptr, endptr, base);
#else
im = __WRAPPED_L(nptr, endptr, base, loc);
#endif
#if !defined(_KERNEL) && !defined(_STANDALONE)
if (errno != EINVAL)
*rstatus = errno;
errno = serrno;
#endif
if (*rstatus == 0 && nptr == *endptr)
*rstatus = ECANCELED;
if (im < lo) {
if (*rstatus == 0)
*rstatus = ERANGE;
return lo;
}
if (im > hi) {
if (*rstatus == 0)
*rstatus = ERANGE;
return hi;
}
if (*rstatus == 0 && **endptr != '\0')
*rstatus = ENOTSUP;
return im;
}
#if !defined(_KERNEL) && !defined(_STANDALONE) && \
!defined(HAVE_NBTOOL_CONFIG_H) && !defined(BCS_ONLY)
__TYPE
_FUNCNAME(const char * __restrict nptr, char ** __restrict endptr, int base,
__TYPE lo, __TYPE hi, int * rstatus)
{
return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, lo, hi,
rstatus, _current_locale());
}
__TYPE
INT_FUNCNAME(, _FUNCNAME, _l)(const char * __restrict nptr,
char ** __restrict endptr, int base,
__TYPE lo, __TYPE hi, int * rstatus, locale_t loc)
{
return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, lo, hi,
rstatus, loc);
}
#endif