2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #if defined(LIBC_SCCS) && !defined(lint)
35 static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
36 #endif /* LIBC_SCCS and not lint */
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
42 * Actual wprintf innards.
44 * Avoid making gratuitous changes to this source file; it should be kept
45 * as close as possible to vfprintf.c for ease of maintenance.
48 #include "namespace.h"
49 #include <sys/types.h>
62 #include "un-namespace.h"
64 #include "libc_private.h"
67 #include "printflocal.h"
69 static int __sbprintf(FILE *, const wchar_t *, va_list);
70 static wint_t __xfputwc(wchar_t, FILE *);
71 static wchar_t *__ujtoa(uintmax_t, wchar_t *, int, int, const char *, int,
73 static wchar_t *__ultoa(u_long, wchar_t *, int, int, const char *, int,
75 static wchar_t *__mbsconv(char *, int);
78 * Helper function for `fprintf to unbuffered unix file': creates a
79 * temporary buffer. We only work on write-only files; this avoids
80 * worries about ungetc buffers and so forth.
83 __sbprintf(FILE *fp, const wchar_t *fmt, va_list ap)
87 unsigned char buf[BUFSIZ];
89 /* copy the important variables */
90 fake._flags = fp->_flags & ~__SNBF;
91 fake._file = fp->_file;
92 fake._cookie = fp->_cookie;
93 fake._write = fp->_write;
94 fake._orientation = fp->_orientation;
95 fake._mbstate = fp->_mbstate;
97 /* set up the buffer */
98 fake._bf._base = fake._p = buf;
99 fake._bf._size = fake._w = sizeof(buf);
100 fake._lbfsize = 0; /* not actually used, but Just In Case */
102 /* do the work, then copy any error status */
103 ret = __vfwprintf(&fake, fmt, ap);
104 if (ret >= 0 && __fflush(&fake))
106 if (fake._flags & __SERR)
107 fp->_flags |= __SERR;
112 * Like __fputwc, but handles fake string (__SSTR) files properly.
113 * File must already be locked.
116 __xfputwc(wchar_t wc, FILE *fp)
118 static const mbstate_t initial;
120 char buf[MB_LEN_MAX];
125 if ((fp->_flags & __SSTR) == 0)
126 return (__fputwc(wc, fp));
129 if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
130 fp->_flags |= __SERR;
138 return (__sfvwrite(fp, &uio) != EOF ? (wint_t)wc : WEOF);
142 * Convert an unsigned long to ASCII for printf purposes, returning
143 * a pointer to the first character of the string representation.
144 * Octal numbers can be forced to have a leading zero; hex numbers
145 * use the given digits.
148 __ultoa(u_long val, wchar_t *endp, int base, int octzero, const char *xdigs,
149 int needgrp, char thousep, const char *grp)
156 * Handle the three cases separately, in the hope of getting
157 * better/faster code.
161 if (val < 10) { /* many numbers are 1 digit */
162 *--cp = to_char(val);
167 * On many machines, unsigned arithmetic is harder than
168 * signed arithmetic, so we do at most one unsigned mod and
169 * divide; this is sufficient to reduce the range of
170 * the incoming value to where signed arithmetic works.
172 if (val > LONG_MAX) {
173 *--cp = to_char(val % 10);
179 *--cp = to_char(sval % 10);
182 * If (*grp == CHAR_MAX) then no more grouping
183 * should be performed.
185 if (needgrp && ndig == *grp && *grp != CHAR_MAX
190 * If (*(grp+1) == '\0') then we have to
191 * use *grp character (last grouping rule)
194 if (*(grp+1) != '\0')
203 *--cp = to_char(val & 7);
206 if (octzero && *cp != '0')
212 *--cp = xdigs[val & 15];
223 /* Identical to __ultoa, but for intmax_t. */
225 __ujtoa(uintmax_t val, wchar_t *endp, int base, int octzero,
226 const char *xdigs, int needgrp, char thousep, const char *grp)
232 /* quick test for small values; __ultoa is typically much faster */
233 /* (perhaps instead we should run until small, then call __ultoa?) */
234 if (val <= ULONG_MAX)
235 return (__ultoa((u_long)val, endp, base, octzero, xdigs,
236 needgrp, thousep, grp));
240 *--cp = to_char(val % 10);
244 if (val > INTMAX_MAX) {
245 *--cp = to_char(val % 10);
251 *--cp = to_char(sval % 10);
254 * If (*grp == CHAR_MAX) then no more grouping
255 * should be performed.
257 if (needgrp && *grp != CHAR_MAX && ndig == *grp
262 * If (*(grp+1) == '\0') then we have to
263 * use *grp character (last grouping rule)
266 if (*(grp+1) != '\0')
275 *--cp = to_char(val & 7);
278 if (octzero && *cp != '0')
284 *--cp = xdigs[val & 15];
296 * Convert a multibyte character string argument for the %s format to a wide
297 * string representation. ``prec'' specifies the maximum number of bytes
298 * to output. If ``prec'' is greater than or equal to zero, we can't assume
299 * that the multibyte char. string ends in a null character.
302 __mbsconv(char *mbsarg, int prec)
304 static const mbstate_t initial;
306 wchar_t *convbuf, *wcp;
308 size_t insize, nchars, nconv;
314 * Supplied argument is a multibyte string; convert it to wide
319 * String is not guaranteed to be NUL-terminated. Find the
320 * number of characters to print.
325 while (nchars != (size_t)prec) {
326 nconv = mbrlen(p, MB_CUR_MAX, &mbs);
327 if (nconv == 0 || nconv == (size_t)-1 ||
334 if (nconv == (size_t)-1 || nconv == (size_t)-2)
337 insize = strlen(mbsarg);
342 * Allocate buffer for the result and perform the conversion,
343 * converting at most `size' bytes of the input multibyte string to
344 * wide characters for printing.
346 convbuf = malloc((insize + 1) * sizeof(*convbuf));
352 while (insize != 0) {
353 nconv = mbrtowc(wcp, p, insize, &mbs);
354 if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)
360 if (nconv == (size_t)-1 || nconv == (size_t)-2) {
373 vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, va_list ap)
379 ret = __vfwprintf(fp, fmt0, ap);
384 #ifndef NO_FLOATING_POINT
387 #define freedtoa __freedtoa
396 static int exponent(wchar_t *, int, wchar_t);
398 #endif /* !NO_FLOATING_POINT */
401 * The size of the buffer we use as scratch space for integer
402 * conversions, among other things. Technically, we would need the
403 * most space for base 10 conversions with thousands' grouping
404 * characters between each pair of digits. 100 bytes is a
405 * conservative overestimate even for a 128-bit uintmax_t.
410 * Non-MT-safe version
413 __vfwprintf(FILE *fp, const wchar_t *fmt0, va_list ap)
415 wchar_t *fmt; /* format string */
416 wchar_t ch; /* character from fmt */
417 int n, n2, n3; /* handy integer (short term usage) */
418 wchar_t *cp; /* handy char pointer (short term usage) */
419 int flags; /* flags as above */
420 int ret; /* return value accumulator */
421 int width; /* width from format (%8d), or 0 */
422 int prec; /* precision from format; <0 for N/A */
423 wchar_t sign; /* sign prefix (' ', '+', '-', or \0) */
424 char thousands_sep; /* locale specific thousands separator */
425 const char *grouping; /* locale specific numeric grouping rules */
426 #ifndef NO_FLOATING_POINT
428 * We can decompose the printed representation of floating
429 * point numbers into several parts, some of which may be empty:
431 * [+|-| ] [0x|0X] MMM . NNN [e|E|p|P] [+|-] ZZ
434 * A: 'sign' holds this value if present; '\0' otherwise
435 * B: ox[1] holds the 'x' or 'X'; '\0' if not hexadecimal
436 * C: cp points to the string MMMNNN. Leading and trailing
437 * zeros are not in the string and must be added.
438 * D: expchar holds this character; '\0' if no exponent, e.g. %f
439 * F: at least two digits for decimal, at least one digit for hex
441 char *decimal_point; /* locale specific decimal point */
442 int signflag; /* true if float is negative */
443 union { /* floating point arguments %[aAeEfFgG] */
447 int expt; /* integer value of exponent */
448 char expchar; /* exponent character: [eEpP\0] */
449 char *dtoaend; /* pointer to end of converted digits */
450 int expsize; /* character count for expstr */
451 int lead; /* sig figs before decimal or group sep */
452 int ndig; /* actual number of digits returned by dtoa */
453 wchar_t expstr[MAXEXPDIG+2]; /* buffer for exponent string: e+ZZZ */
454 char *dtoaresult; /* buffer allocated by dtoa */
455 int nseps; /* number of group separators with ' */
456 int nrepeats; /* number of repeats of the last group */
458 u_long ulval; /* integer arguments %[diouxX] */
459 uintmax_t ujval; /* %j, %ll, %q, %t, %z integers */
460 int base; /* base for [diouxX] conversion */
461 int dprec; /* a copy of prec if [diouxX], 0 otherwise */
462 int realsz; /* field size expanded by dprec, sign, etc */
463 int size; /* size of converted field or string */
464 int prsize; /* max size of printed field */
465 const char *xdigs; /* digits for [xX] conversion */
466 wchar_t buf[BUF]; /* buffer with space for digits of uintmax_t */
467 wchar_t ox[2]; /* space for 0x hex-prefix */
468 union arg *argtable; /* args, built due to positional arg */
469 union arg statargtable [STATIC_ARG_TBL_SIZE];
470 int nextarg; /* 1-based argument index */
471 va_list orgap; /* original argument pointer */
472 wchar_t *convbuf; /* multibyte to wide conversion result */
475 * Choose PADSIZE to trade efficiency vs. size. If larger printf
476 * fields occur frequently, increase PADSIZE and make the initialisers
479 #define PADSIZE 16 /* pad chunk size */
480 static wchar_t blanks[PADSIZE] =
481 {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
482 static wchar_t zeroes[PADSIZE] =
483 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
485 static const char xdigs_lower[16] = "0123456789abcdef";
486 static const char xdigs_upper[16] = "0123456789ABCDEF";
489 * BEWARE, these `goto error' on error, PRINT uses `n2' and
492 #define PRINT(ptr, len) do { \
493 for (n3 = 0; n3 < (len); n3++) \
494 __xfputwc((ptr)[n3], fp); \
496 #define PAD(howmany, with) do { \
497 if ((n = (howmany)) > 0) { \
498 while (n > PADSIZE) { \
499 PRINT(with, PADSIZE); \
505 #define PRINTANDPAD(p, ep, len, with) do { \
511 PAD((len) - (n2 > 0 ? n2 : 0), (with)); \
515 * Get the argument indexed by nextarg. If the argument table is
516 * built, use it to get the argument. If its not, get the next
517 * argument (and arguments must be gotten sequentially).
519 #define GETARG(type) \
520 ((argtable != NULL) ? *((type*)(&argtable[nextarg++])) : \
521 (nextarg++, va_arg(ap, type)))
524 * To extend shorts properly, we need both signed and unsigned
525 * argument extraction methods.
528 (flags&LONGINT ? GETARG(long) : \
529 flags&SHORTINT ? (long)(short)GETARG(int) : \
530 flags&CHARINT ? (long)(signed char)GETARG(int) : \
533 (flags&LONGINT ? GETARG(u_long) : \
534 flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
535 flags&CHARINT ? (u_long)(u_char)GETARG(int) : \
536 (u_long)GETARG(u_int))
537 #define INTMAX_SIZE (INTMAXT|SIZET|PTRDIFFT|LLONGINT)
539 (flags&INTMAXT ? GETARG(intmax_t) : \
540 flags&SIZET ? (intmax_t)GETARG(size_t) : \
541 flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \
542 (intmax_t)GETARG(long long))
544 (flags&INTMAXT ? GETARG(uintmax_t) : \
545 flags&SIZET ? (uintmax_t)GETARG(size_t) : \
546 flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \
547 (uintmax_t)GETARG(unsigned long long))
550 * Get * arguments, including the form *nn$. Preserve the nextarg
551 * that the argument can be gotten once the type is determined.
553 #define GETASTER(val) \
556 while (is_digit(*cp)) { \
557 n2 = 10 * n2 + to_digit(*cp); \
561 int hold = nextarg; \
562 if (argtable == NULL) { \
563 argtable = statargtable; \
564 if (__find_warguments (fmt0, orgap, &argtable)) { \
570 val = GETARG (int); \
574 val = GETARG (int); \
578 thousands_sep = '\0';
580 #ifndef NO_FLOATING_POINT
581 decimal_point = localeconv()->decimal_point;
584 /* sorry, fwprintf(read_only_file, L"") returns WEOF, not 0 */
585 if (prepwrite(fp) != 0)
588 /* optimise fprintf(stderr) (and other unbuffered Unix files) */
589 if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
591 return (__sbprintf(fp, fmt0, ap));
593 fmt = (wchar_t *)fmt0;
600 * Scan the format for conversions (`%' character).
603 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
605 if ((n = fmt - cp) != 0) {
606 if ((unsigned)ret + n > INT_MAX) {
615 fmt++; /* skip over '%' */
625 reswitch: switch (ch) {
628 * ``If the space and + flags both appear, the space
629 * flag will be ignored.''
640 * ``A negative field width argument is taken as a
641 * - flag followed by a positive field width.''
643 * They don't exclude field widths read from args.
658 thousands_sep = *(localeconv()->thousands_sep);
659 grouping = localeconv()->grouping;
662 if ((ch = *fmt++) == '*') {
667 while (is_digit(ch)) {
668 prec = 10 * prec + to_digit(ch);
674 * ``Note that 0 is taken as a flag, not as the
675 * beginning of a field width.''
680 case '1': case '2': case '3': case '4':
681 case '5': case '6': case '7': case '8': case '9':
684 n = 10 * n + to_digit(ch);
686 } while (is_digit(ch));
689 if (argtable == NULL) {
690 argtable = statargtable;
691 if (__find_warguments (fmt0, orgap,
701 #ifndef NO_FLOATING_POINT
707 if (flags & SHORTINT) {
717 if (flags & LONGINT) {
724 flags |= LLONGINT; /* not necessarily */
737 *(cp = buf) = (wchar_t)GETARG(wint_t);
739 *(cp = buf) = (wchar_t)btowc(GETARG(int));
748 if (flags & INTMAX_SIZE) {
750 if ((intmax_t)ujval < 0) {
756 if ((long)ulval < 0) {
763 #ifndef NO_FLOATING_POINT
777 if (flags & LONGDBL) {
778 fparg.ldbl = GETARG(long double);
780 __hldtoa(fparg.ldbl, xdigs, prec,
781 &expt, &signflag, &dtoaend);
783 fparg.dbl = GETARG(double);
785 __hdtoa(fparg.dbl, xdigs, prec,
786 &expt, &signflag, &dtoaend);
789 prec = dtoaend - dtoaresult;
794 ndig = dtoaend - dtoaresult;
795 cp = convbuf = __mbsconv(dtoaresult, -1);
796 freedtoa(dtoaresult);
801 if (prec < 0) /* account for digit before decpt */
812 expchar = ch - ('g' - 'e');
820 if (flags & LONGDBL) {
821 fparg.ldbl = GETARG(long double);
823 __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec,
824 &expt, &signflag, &dtoaend);
826 fparg.dbl = GETARG(double);
828 dtoa(fparg.dbl, expchar ? 2 : 3, prec,
829 &expt, &signflag, &dtoaend);
833 ndig = dtoaend - dtoaresult;
834 cp = convbuf = __mbsconv(dtoaresult, -1);
835 freedtoa(dtoaresult);
839 if (expt == INT_MAX) { /* inf or nan */
841 cp = (ch >= 'a') ? L"nan" : L"NAN";
844 cp = (ch >= 'a') ? L"inf" : L"INF";
850 if (ch == 'g' || ch == 'G') {
851 if (expt > -4 && expt <= prec) {
852 /* Make %[gG] smell like %[fF] */
862 * Make %[gG] smell like %[eE], but
863 * trim trailing zeroes if no # flag.
870 expsize = exponent(expstr, expt - 1, expchar);
871 size = expsize + prec;
872 if (prec > 1 || flags & ALT)
875 /* space for digits before decimal point */
880 /* space for decimal pt and following digits */
881 if (prec || flags & ALT)
883 if (grouping && expt > 0) {
884 /* space for thousands' grouping */
885 nseps = nrepeats = 0;
887 while (*grouping != CHAR_MAX) {
888 if (lead <= *grouping)
897 size += nseps + nrepeats;
902 #endif /* !NO_FLOATING_POINT */
905 * Assignment-like behavior is specified if the
906 * value overflows or is otherwise unrepresentable.
907 * C99 says to use `signed char' for %hhn conversions.
909 if (flags & LLONGINT)
910 *GETARG(long long *) = ret;
911 else if (flags & SIZET)
912 *GETARG(ssize_t *) = (ssize_t)ret;
913 else if (flags & PTRDIFFT)
914 *GETARG(ptrdiff_t *) = ret;
915 else if (flags & INTMAXT)
916 *GETARG(intmax_t *) = ret;
917 else if (flags & LONGINT)
918 *GETARG(long *) = ret;
919 else if (flags & SHORTINT)
920 *GETARG(short *) = ret;
921 else if (flags & CHARINT)
922 *GETARG(signed char *) = ret;
924 *GETARG(int *) = ret;
925 continue; /* no output */
930 if (flags & INTMAX_SIZE)
938 * ``The argument shall be a pointer to void. The
939 * value of the pointer is converted to a sequence
940 * of printable characters, in an implementation-
944 ujval = (uintmax_t)(uintptr_t)GETARG(void *);
947 flags = flags | INTMAXT;
954 if (flags & LONGINT) {
955 if ((cp = GETARG(wchar_t *)) == NULL)
962 if ((mbp = GETARG(char *)) == NULL)
965 convbuf = __mbsconv(mbp, prec);
966 if (convbuf == NULL) {
967 fp->_flags |= __SERR;
976 * can't use wcslen; can only look for the
977 * NUL in the first `prec' characters, and
978 * wcslen() will go further.
980 wchar_t *p = wmemchr(cp, 0, (size_t)prec);
996 if (flags & INTMAX_SIZE)
1003 xdigs = xdigs_upper;
1006 xdigs = xdigs_lower;
1008 if (flags & INTMAX_SIZE)
1013 /* leading 0x/X only if non-zero */
1015 (flags & INTMAX_SIZE ? ujval != 0 : ulval != 0))
1019 /* unsigned conversions */
1020 nosign: sign = '\0';
1022 * ``... diouXx conversions ... if a precision is
1023 * specified, the 0 flag will be ignored.''
1026 number: if ((dprec = prec) >= 0)
1030 * ``The result of converting a zero value with an
1031 * explicit precision of zero is no characters.''
1034 * ``The C Standard is clear enough as is. The call
1035 * printf("%#.0o", 0) should print 0.''
1036 * -- Defect Report #151
1039 if (flags & INTMAX_SIZE) {
1040 if (ujval != 0 || prec != 0 ||
1041 (flags & ALT && base == 8))
1042 cp = __ujtoa(ujval, cp, base,
1044 flags & GROUPING, thousands_sep,
1047 if (ulval != 0 || prec != 0 ||
1048 (flags & ALT && base == 8))
1049 cp = __ultoa(ulval, cp, base,
1051 flags & GROUPING, thousands_sep,
1054 size = buf + BUF - cp;
1055 if (size > BUF) /* should never happen */
1058 default: /* "%?" prints ?, unless ? is NUL */
1061 /* pretend it was %c with argument ch */
1070 * All reasonable formats wind up here. At this point, `cp'
1071 * points to a string which (if not flags&LADJUST) should be
1072 * padded out to `width' places. If flags&ZEROPAD, it should
1073 * first be prefixed by any sign or other prefix; otherwise,
1074 * it should be blank padded before the prefix is emitted.
1075 * After any left-hand padding and prefixing, emit zeroes
1076 * required by a decimal [diouxX] precision, then print the
1077 * string proper, then emit zeroes required by any leftover
1078 * floating precision; finally, if LADJUST, pad with blanks.
1080 * Compute actual size, so we know how much to pad.
1081 * size excludes decimal prec; realsz includes it.
1083 realsz = dprec > size ? dprec : size;
1089 prsize = width > realsz ? width : realsz;
1090 if ((unsigned)ret + prsize > INT_MAX) {
1095 /* right-adjusting blank padding */
1096 if ((flags & (LADJUST|ZEROPAD)) == 0)
1097 PAD(width - realsz, blanks);
1103 if (ox[1]) { /* ox[1] is either x, X, or \0 */
1108 /* right-adjusting zero padding */
1109 if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
1110 PAD(width - realsz, zeroes);
1112 /* leading zeroes from decimal precision */
1113 PAD(dprec - size, zeroes);
1115 /* the string or number proper */
1116 #ifndef NO_FLOATING_POINT
1117 if ((flags & FPT) == 0) {
1119 } else { /* glue together f_p fragments */
1120 if (!expchar) { /* %[fF] or sufficiently short %[gG] */
1123 if (prec || flags & ALT)
1124 PRINT(decimal_point, 1);
1126 /* already handled initial 0's */
1129 PRINTANDPAD(cp, convbuf + ndig, lead, zeroes);
1132 while (nseps>0 || nrepeats>0) {
1139 PRINT(&thousands_sep,
1146 if (cp > convbuf + ndig)
1147 cp = convbuf + ndig;
1149 if (prec || flags & ALT) {
1150 buf[0] = *decimal_point;
1154 PRINTANDPAD(cp, convbuf + ndig, prec, zeroes);
1155 } else { /* %[eE] or sufficiently long %[gG] */
1156 if (prec > 1 || flags & ALT) {
1158 buf[1] = *decimal_point;
1161 PAD(prec - ndig, zeroes);
1164 PRINT(expstr, expsize);
1170 /* left-adjusting padding (always blank) */
1171 if (flags & LADJUST)
1172 PAD(width - realsz, blanks);
1174 /* finally, adjust ret */
1180 if (convbuf != NULL)
1184 if ((argtable != NULL) && (argtable != statargtable))
1191 #ifndef NO_FLOATING_POINT
1194 exponent(wchar_t *p0, int exp, wchar_t fmtch)
1197 wchar_t expbuf[MAXEXPDIG];
1207 t = expbuf + MAXEXPDIG;
1210 *--t = to_char(exp % 10);
1211 } while ((exp /= 10) > 9);
1212 *--t = to_char(exp);
1213 for (; t < expbuf + MAXEXPDIG; *p++ = *t++);
1217 * Exponents for decimal floating point conversions
1218 * (%[eEgG]) must be at least two characters long,
1219 * whereas exponents for hexadecimal conversions can
1220 * be only one character long.
1222 if (fmtch == 'e' || fmtch == 'E')
1224 *p++ = to_char(exp);
1228 #endif /* !NO_FLOATING_POINT */