#endif
#include <limits.h>
+#include <stdckdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
# undef __mbsrtowcs_l
# define __mbsrtowcs_l(d, s, l, st, loc) __mbsrtowcs (d, s, l, st)
# endif
-# define widen(os, ws, l) \
- { \
- mbstate_t __st; \
- const char *__s = os; \
- memset (&__st, '\0', sizeof (__st)); \
- l = __mbsrtowcs_l (NULL, &__s, 0, &__st, loc); \
- ws = (wchar_t *) alloca ((l + 1) * sizeof (wchar_t)); \
- (void) __mbsrtowcs_l (ws, &__s, l, &__st, loc); \
- }
#endif
width = 0;
do
{
- if (INT_MULTIPLY_WRAPV (width, 10, &width)
- || INT_ADD_WRAPV (width, *f - L_('0'), &width))
+ if (ckd_mul (&width, width, 10)
+ || ckd_add (&width, width, *f - L_('0')))
width = INT_MAX;
++f;
}
#ifdef COMPILE_WIDE
{
/* The zone string is always given in multibyte form. We have
- to transform it first. */
- wchar_t *wczone;
- size_t len;
- widen (zone, wczone, len);
- cpy (len, wczone);
+ to convert it to wide character. */
+ size_t w = pad == L_('-') || width < 0 ? 0 : width;
+ char const *z = zone;
+ mbstate_t st = {0};
+ size_t len = __mbsrtowcs_l (p, &z, maxsize - i, &st, loc);
+ if (len == (size_t) -1)
+ return 0;
+ size_t incr = len < w ? w : len;
+ if (incr >= maxsize - i)
+ {
+ errno = ERANGE;
+ return 0;
+ }
+ if (p)
+ {
+ if (len < w)
+ {
+ size_t delta = w - len;
+ wmemmove (p + delta, p, len);
+ wchar_t wc = pad == L_('0') || pad == L_('+') ? L'0' : L' ';
+ wmemset (p, wc, delta);
+ }
+ p += incr;
+ }
+ i += incr;
}
#else
cpy (strlen (zone), zone);
#include <config.h>
#include "timespec.h"
+#include <stdckdint.h>
#include "intprops.h"
struct timespec
{
rns = ns + TIMESPEC_HZ;
time_t bs1;
- if (!INT_ADD_WRAPV (bs, 1, &bs1))
+ if (!ckd_add (&bs1, bs, 1))
bs = bs1;
else if (- TYPE_SIGNED (time_t) < rs)
rs--;
goto low_overflow;
}
- if (INT_SUBTRACT_WRAPV (rs, bs, &rs))
+ if (ckd_sub (&rs, rs, bs))
{
if (0 < bs)
{