{
const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
const wchar_t *arg_end;
+ size_t bytes;
+# if ENABLE_UNISTDIO && DCHAR_IS_TCHAR
size_t characters;
+# endif
# if !DCHAR_IS_TCHAR
/* This code assumes that TCHAR_T is 'char'. */
static_assert (sizeof (TCHAR_T) == 1);
mbszero (&state);
# endif
arg_end = arg;
+ bytes = 0;
+# if ENABLE_UNISTDIO && DCHAR_IS_TCHAR
characters = 0;
+# endif
while (precision > 0)
{
char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
if (precision < (unsigned int) count)
break;
arg_end++;
- characters += count;
+ bytes += count;
+# if ENABLE_UNISTDIO && DCHAR_IS_TCHAR
+ characters += mbsnlen (cbuf, count);
+# endif
precision -= count;
}
}
mbszero (&state);
# endif
arg_end = arg;
+ bytes = 0;
+# if ENABLE_UNISTDIO && DCHAR_IS_TCHAR
characters = 0;
+# endif
for (;;)
{
char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
/* Cannot convert. */
goto fail_with_EILSEQ;
arg_end++;
- characters += count;
+ bytes += count;
+# if ENABLE_UNISTDIO && DCHAR_IS_TCHAR
+ characters += mbsnlen (cbuf, count);
+# endif
}
}
# if DCHAR_IS_TCHAR
{
/* Use the entire string. */
arg_end = arg + local_wcslen (arg);
- /* The number of bytes doesn't matter. */
+ /* The number of bytes and characters doesn't matter,
+ because !has_width and therefore width==0. */
+ bytes = 0;
+# if ENABLE_UNISTDIO
characters = 0;
+# endif
}
# endif
TCHAR_T *tmpsrc;
/* Convert the string into a piece of temporary memory. */
- tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T));
+ tmpsrc = (TCHAR_T *) malloc (bytes * sizeof (TCHAR_T));
if (tmpsrc == NULL)
goto out_of_memory;
{
mbstate_t state;
mbszero (&state);
# endif
- for (remaining = characters; remaining > 0; )
+ for (remaining = bytes; remaining > 0; )
{
char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
int count;
tmpdst =
DCHAR_CONV_FROM_ENCODING (locale_charset (),
iconveh_question_mark,
- tmpsrc, characters,
+ tmpsrc, bytes,
NULL,
NULL, &tmpdst_len);
if (tmpdst == NULL)
/* Outside POSIX, it's preferable to compare the width
against the number of _characters_ of the converted
value. */
- w = DCHAR_MBSNLEN (result + length, characters);
+# if DCHAR_IS_TCHAR
+ w = characters;
+# else
+ w = DCHAR_MBSNLEN (tmpdst, tmpdst_len);
+# endif
# else
/* The width is compared against the number of _bytes_
of the converted value, says POSIX. */
- w = characters;
+ w = bytes;
# endif
}
else
mbstate_t state;
mbszero (&state);
# endif
- ENSURE_ALLOCATION (xsum (length, characters));
- for (remaining = characters; remaining > 0; )
+ ENSURE_ALLOCATION (xsum (length, bytes));
+ for (remaining = bytes; remaining > 0; )
{
char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
int count;
/* %lc in vasnprintf. See the specification of fprintf. */
{
wchar_t arg = (wchar_t) a.arg[dp->arg_index].a.a_wide_char;
+ size_t bytes;
+# if ENABLE_UNISTDIO && DCHAR_IS_TCHAR
size_t characters;
+# endif
# if !DCHAR_IS_TCHAR
/* This code assumes that TCHAR_T is 'char'. */
static_assert (sizeof (TCHAR_T) == 1);
# endif
{
/* Count the number of bytes. */
- characters = 0;
char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
int count;
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
if (count < 0)
/* Cannot convert. */
goto fail_with_EILSEQ;
- characters = count;
+ bytes = count;
+# if ENABLE_UNISTDIO && DCHAR_IS_TCHAR
+ characters = mbsnlen (cbuf, count);
+# endif
}
# if DCHAR_IS_TCHAR
else
{
- /* The number of bytes doesn't matter. */
+ /* The number of bytes and characters doesn't matter,
+ because !has_width and therefore width==0. */
+ bytes = 0;
+# if ENABLE_UNISTDIO
characters = 0;
+# endif
}
# endif
TCHAR_T tmpsrc[64]; /* Assume MB_CUR_MAX <= 64. */
/* Convert the string into a piece of temporary memory. */
- if (characters > 0)
+ if (bytes > 0)
{
char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
int count;
tmpdst =
DCHAR_CONV_FROM_ENCODING (locale_charset (),
iconveh_question_mark,
- tmpsrc, characters,
+ tmpsrc, bytes,
NULL,
NULL, &tmpdst_len);
if (tmpdst == NULL)
/* Outside POSIX, it's preferable to compare the width
against the number of _characters_ of the converted
value. */
- w = DCHAR_MBSNLEN (result + length, characters);
+# if DCHAR_IS_TCHAR
+ w = characters;
+# else
+ w = DCHAR_MBSNLEN (tmpdst, tmpdst_len);
+# endif
# else
/* The width is compared against the number of _bytes_
of the converted value, says POSIX. */
- w = characters;
+ w = bytes;
# endif
}
else
if (has_width)
{
/* We know the number of bytes in advance. */
- ENSURE_ALLOCATION (xsum (length, characters));
- if (characters > 0)
+ ENSURE_ALLOCATION (xsum (length, bytes));
+ if (bytes > 0)
{
int count;
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t