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 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)vfprintf.c 8.1 (Berkeley) 6/4/93
37 * $FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.22.2.5 2002/10/12 10:46:37 schweikh Exp $
38 * $DragonFly: src/lib/libcr/stdio/Attic/vfprintf.c,v 1.4 2004/07/05 17:31:00 eirikn Exp $
42 * Actual printf innards.
44 * This code is large and complicated...
47 #include <sys/types.h>
56 #include "libc_private.h"
60 /* Define FLOATING_POINT to get floating point. */
61 #define FLOATING_POINT
63 static int __sprint (FILE *, struct __suio *);
64 static int __sbprintf (FILE *, const char *, va_list);
65 static char * __ultoa (u_long, char *, int, int, char *);
66 static char * __uqtoa (u_quad_t, char *, int, int, char *);
67 static void __find_arguments (const char *, va_list, void ***);
68 static void __grow_type_table (int, unsigned char **, int *);
71 * Flush out all the vectors defined by the given uio,
72 * then reset it so that it can be reused.
75 __sprint(FILE *fp, struct __suio *uio)
79 if (uio->uio_resid == 0) {
83 err = __sfvwrite(fp, uio);
90 * Helper function for `fprintf to unbuffered unix file': creates a
91 * temporary buffer. We only work on write-only files; this avoids
92 * worries about ungetc buffers and so forth.
95 __sbprintf(FILE *fp, const char *fmt, va_list ap)
99 unsigned char buf[BUFSIZ];
101 /* copy the important variables */
102 fake._flags = fp->_flags & ~__SNBF;
103 fake._file = fp->_file;
104 fake._cookie = fp->_cookie;
105 fake._write = fp->_write;
107 /* set up the buffer */
108 fake._bf._base = fake._p = buf;
109 fake._bf._size = fake._w = sizeof(buf);
110 fake._lbfsize = 0; /* not actually used, but Just In Case */
112 /* do the work, then copy any error status */
113 ret = vfprintf(&fake, fmt, ap);
114 if (ret >= 0 && fflush(&fake))
116 if (fake._flags & __SERR)
117 fp->_flags |= __SERR;
122 * Macros for converting digits to letters and vice versa
124 #define to_digit(c) ((c) - '0')
125 #define is_digit(c) ((unsigned)to_digit(c) <= 9)
126 #define to_char(n) ((n) + '0')
129 * Convert an unsigned long to ASCII for printf purposes, returning
130 * a pointer to the first character of the string representation.
131 * Octal numbers can be forced to have a leading zero; hex numbers
132 * use the given digits.
135 __ultoa(u_long val, char *endp, int base, int octzero, char *xdigs)
141 * Handle the three cases separately, in the hope of getting
142 * better/faster code.
146 if (val < 10) { /* many numbers are 1 digit */
147 *--cp = to_char(val);
151 * On many machines, unsigned arithmetic is harder than
152 * signed arithmetic, so we do at most one unsigned mod and
153 * divide; this is sufficient to reduce the range of
154 * the incoming value to where signed arithmetic works.
156 if (val > LONG_MAX) {
157 *--cp = to_char(val % 10);
162 *--cp = to_char(sval % 10);
169 *--cp = to_char(val & 7);
172 if (octzero && *cp != '0')
178 *--cp = xdigs[val & 15];
189 /* Identical to __ultoa, but for quads. */
191 __uqtoa(u_quad_t val, char *endp, int base, int octzero, char *xdigs)
196 /* quick test for small values; __ultoa is typically much faster */
197 /* (perhaps instead we should run until small, then call __ultoa?) */
198 if (val <= ULONG_MAX)
199 return (__ultoa((u_long)val, endp, base, octzero, xdigs));
203 *--cp = to_char(val % 10);
206 if (val > QUAD_MAX) {
207 *--cp = to_char(val % 10);
212 *--cp = to_char(sval % 10);
219 *--cp = to_char(val & 7);
222 if (octzero && *cp != '0')
228 *--cp = xdigs[val & 15];
239 #ifdef FLOATING_POINT
244 #define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */
247 static char *cvt (double, int, int, char *, int *, int, int *, char **);
248 static int exponent (char *, int, int);
250 #else /* no FLOATING_POINT */
254 #endif /* FLOATING_POINT */
256 #define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */
259 * Flags used during conversion.
261 #define ALT 0x001 /* alternate form */
262 #define HEXPREFIX 0x002 /* add 0x or 0X prefix */
263 #define LADJUST 0x004 /* left adjustment */
264 #define LONGDBL 0x008 /* long double */
265 #define LONGINT 0x010 /* long integer */
266 #define QUADINT 0x020 /* quad integer */
267 #define SHORTINT 0x040 /* short integer */
268 #define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
269 #define FPT 0x100 /* Floating point number */
271 vfprintf(FILE *fp, const char *fmt0, va_list ap)
273 char *fmt; /* format string */
274 int ch; /* character from fmt */
275 int n, n2; /* handy integer (short term usage) */
276 char *cp; /* handy char pointer (short term usage) */
277 struct __siov *iovp; /* for PRINT macro */
278 int flags; /* flags as above */
279 int ret; /* return value accumulator */
280 int width; /* width from format (%8d), or 0 */
281 int prec; /* precision from format (%.3d), or -1 */
282 char sign; /* sign prefix (' ', '+', '-', or \0) */
283 #ifdef FLOATING_POINT
284 char *decimal_point = localeconv()->decimal_point;
285 char softsign; /* temporary negative sign for floats */
286 double _double; /* double precision arguments %[eEfgG] */
287 int expt; /* integer value of exponent */
288 int expsize; /* character count for expstr */
289 int ndig; /* actual number of digits returned by cvt */
290 char expstr[7]; /* buffer for exponent string */
291 char *dtoaresult; /* buffer allocated by dtoa */
293 u_long ulval; /* integer arguments %[diouxX] */
294 u_quad_t uqval; /* %q integers */
295 int base; /* base for [diouxX] conversion */
296 int dprec; /* a copy of prec if [diouxX], 0 otherwise */
297 int realsz; /* field size expanded by dprec, sign, etc */
298 int size; /* size of converted field or string */
299 int prsize; /* max size of printed field */
300 char *xdigs; /* digits for [xX] conversion */
302 struct __suio uio; /* output information: summary */
303 struct __siov iov[NIOV];/* ... and individual io vectors */
304 char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
305 char ox[2]; /* space for 0x hex-prefix */
306 void **argtable; /* args, built due to positional arg */
307 void *statargtable [STATIC_ARG_TBL_SIZE];
308 int nextarg; /* 1-based argument index */
309 va_list orgap; /* original argument pointer */
312 * Choose PADSIZE to trade efficiency vs. size. If larger printf
313 * fields occur frequently, increase PADSIZE and make the initialisers
316 #define PADSIZE 16 /* pad chunk size */
317 static char blanks[PADSIZE] =
318 {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
319 static char zeroes[PADSIZE] =
320 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
323 * BEWARE, these `goto error' on error, and PAD uses `n'.
325 #define PRINT(ptr, len) { \
326 iovp->iov_base = (ptr); \
327 iovp->iov_len = (len); \
328 uio.uio_resid += (len); \
330 if (++uio.uio_iovcnt >= NIOV) { \
331 if (__sprint(fp, &uio)) \
336 #define PAD(howmany, with) { \
337 if ((n = (howmany)) > 0) { \
338 while (n > PADSIZE) { \
339 PRINT(with, PADSIZE); \
346 if (uio.uio_resid && __sprint(fp, &uio)) \
348 uio.uio_iovcnt = 0; \
353 * Get the argument indexed by nextarg. If the argument table is
354 * built, use it to get the argument. If its not, get the next
355 * argument (and arguments must be gotten sequentially).
357 #define GETARG(type) \
358 ((argtable != NULL) ? *((type*)(argtable[nextarg++])) : \
359 (nextarg++, va_arg(ap, type)))
362 * To extend shorts properly, we need both signed and unsigned
363 * argument extraction methods.
366 (flags&LONGINT ? GETARG(long) : \
367 flags&SHORTINT ? (long)(short)GETARG(int) : \
370 (flags&LONGINT ? GETARG(u_long) : \
371 flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
372 (u_long)GETARG(u_int))
375 * Get * arguments, including the form *nn$. Preserve the nextarg
376 * that the argument can be gotten once the type is determined.
378 #define GETASTER(val) \
381 while (is_digit(*cp)) { \
382 n2 = 10 * n2 + to_digit(*cp); \
386 int hold = nextarg; \
387 if (argtable == NULL) { \
388 argtable = statargtable; \
389 __find_arguments (fmt0, orgap, &argtable); \
392 val = GETARG (int); \
396 val = GETARG (int); \
400 #ifdef FLOATING_POINT
404 /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
410 /* optimise fprintf(stderr) (and other unbuffered Unix files) */
411 if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
414 return (__sbprintf(fp, fmt0, ap));
421 uio.uio_iov = iovp = iov;
427 * Scan the format for conversions (`%' character).
430 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
432 if ((n = fmt - cp) != 0) {
433 if ((unsigned)ret + n > INT_MAX) {
442 fmt++; /* skip over '%' */
451 reswitch: switch (ch) {
454 * ``If the space and + flags both appear, the space
455 * flag will be ignored.''
466 * ``A negative field width argument is taken as a
467 * - flag followed by a positive field width.''
469 * They don't exclude field widths read from args.
483 if ((ch = *fmt++) == '*') {
485 prec = n < 0 ? -1 : n;
489 while (is_digit(ch)) {
490 n = 10 * n + to_digit(ch);
493 prec = n < 0 ? -1 : n;
497 * ``Note that 0 is taken as a flag, not as the
498 * beginning of a field width.''
503 case '1': case '2': case '3': case '4':
504 case '5': case '6': case '7': case '8': case '9':
507 n = 10 * n + to_digit(ch);
509 } while (is_digit(ch));
512 if (argtable == NULL) {
513 argtable = statargtable;
514 __find_arguments (fmt0, orgap,
521 #ifdef FLOATING_POINT
539 *(cp = buf) = GETARG(int);
548 if (flags & QUADINT) {
549 uqval = GETARG(quad_t);
550 if ((quad_t)uqval < 0) {
556 if ((long)ulval < 0) {
563 #ifdef FLOATING_POINT
572 fp_begin: if (prec == -1)
575 /* XXX this loses precision. */
576 _double = (double)GETARG(long double);
578 _double = GETARG(double);
579 /* do this before tricky precision changes */
580 if (isinf(_double)) {
587 if (isnan(_double)) {
593 if (dtoaresult != NULL) {
597 cp = cvt(_double, prec, flags, &softsign,
598 &expt, ch, &ndig, &dtoaresult);
599 if (ch == 'g' || ch == 'G') {
600 if (expt <= -4 || expt > prec)
601 ch = (ch == 'g') ? 'e' : 'E';
605 if (ch <= 'e') { /* 'e' or 'E' fmt */
607 expsize = exponent(expstr, expt, ch);
608 size = expsize + ndig;
609 if (ndig > 1 || flags & ALT)
611 } else if (ch == 'f') { /* f fmt */
614 if (prec || flags & ALT)
618 } else if (expt >= ndig) { /* fixed g fmt */
623 size = ndig + (expt > 0 ?
629 #endif /* FLOATING_POINT */
632 *GETARG(quad_t *) = ret;
633 else if (flags & LONGINT)
634 *GETARG(long *) = ret;
635 else if (flags & SHORTINT)
636 *GETARG(short *) = ret;
638 *GETARG(int *) = ret;
639 continue; /* no output */
645 uqval = GETARG(u_quad_t);
652 * ``The argument shall be a pointer to void. The
653 * value of the pointer is converted to a sequence
654 * of printable characters, in an implementation-
658 ulval = (u_long)GETARG(void *);
660 xdigs = "0123456789abcdef";
661 flags = (flags & ~QUADINT) | HEXPREFIX;
665 if ((cp = GETARG(char *)) == NULL)
669 * can't use strlen; can only look for the
670 * NUL in the first `prec' characters, and
671 * strlen() will go further.
673 char *p = memchr(cp, 0, (size_t)prec);
690 uqval = GETARG(u_quad_t);
696 xdigs = "0123456789ABCDEF";
699 xdigs = "0123456789abcdef";
700 hex: if (flags & QUADINT)
701 uqval = GETARG(u_quad_t);
705 /* leading 0x/X only if non-zero */
707 (flags & QUADINT ? uqval != 0 : ulval != 0))
710 /* unsigned conversions */
713 * ``... diouXx conversions ... if a precision is
714 * specified, the 0 flag will be ignored.''
717 number: if ((dprec = prec) >= 0)
721 * ``The result of converting a zero value with an
722 * explicit precision of zero is no characters.''
726 if (flags & QUADINT) {
727 if (uqval != 0 || prec != 0)
728 cp = __uqtoa(uqval, cp, base,
731 if (ulval != 0 || prec != 0)
732 cp = __ultoa(ulval, cp, base,
735 size = buf + BUF - cp;
737 default: /* "%?" prints ?, unless ? is NUL */
740 /* pretend it was %c with argument ch */
749 * All reasonable formats wind up here. At this point, `cp'
750 * points to a string which (if not flags&LADJUST) should be
751 * padded out to `width' places. If flags&ZEROPAD, it should
752 * first be prefixed by any sign or other prefix; otherwise,
753 * it should be blank padded before the prefix is emitted.
754 * After any left-hand padding and prefixing, emit zeroes
755 * required by a decimal [diouxX] precision, then print the
756 * string proper, then emit zeroes required by any leftover
757 * floating precision; finally, if LADJUST, pad with blanks.
759 * Compute actual size, so we know how much to pad.
760 * size excludes decimal prec; realsz includes it.
762 realsz = dprec > size ? dprec : size;
765 else if (flags & HEXPREFIX)
768 prsize = width > realsz ? width : realsz;
769 if ((unsigned)ret + prsize > INT_MAX) {
774 /* right-adjusting blank padding */
775 if ((flags & (LADJUST|ZEROPAD)) == 0)
776 PAD(width - realsz, blanks);
781 } else if (flags & HEXPREFIX) {
787 /* right-adjusting zero padding */
788 if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
789 PAD(width - realsz, zeroes);
791 /* leading zeroes from decimal precision */
792 PAD(dprec - size, zeroes);
794 /* the string or number proper */
795 #ifdef FLOATING_POINT
796 if ((flags & FPT) == 0) {
798 } else { /* glue together f_p fragments */
799 if (ch >= 'f') { /* 'f' or 'g' */
801 /* kludge for __dtoa irregularity */
803 if (expt < ndig || (flags & ALT) != 0) {
804 PRINT(decimal_point, 1);
805 PAD(ndig - 1, zeroes);
807 } else if (expt <= 0) {
809 PRINT(decimal_point, 1);
812 } else if (expt >= ndig) {
814 PAD(expt - ndig, zeroes);
816 PRINT(decimal_point, 1);
820 PRINT(decimal_point, 1);
821 PRINT(cp, ndig-expt);
823 } else { /* 'e' or 'E' */
824 if (ndig > 1 || flags & ALT) {
826 ox[1] = *decimal_point;
831 /* __dtoa irregularity */
832 PAD(ndig - 1, zeroes);
835 PRINT(expstr, expsize);
841 /* left-adjusting padding (always blank) */
843 PAD(width - realsz, blanks);
845 /* finally, adjust ret */
848 FLUSH(); /* copy out the I/O vectors */
853 #ifdef FLOATING_POINT
854 if (dtoaresult != NULL)
860 if ((argtable != NULL) && (argtable != statargtable))
867 * Type ids for argument type table.
883 #define T_LONG_DOUBLE 14
888 * Find all arguments when a positional parameter is encountered. Returns a
889 * table, indexed by argument number, of pointers to each arguments. The
890 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
891 * It will be replaces with a malloc-ed one if it overflows.
894 __find_arguments (const char *fmt0, va_list ap, void ***argtable)
896 char *fmt; /* format string */
897 int ch; /* character from fmt */
898 int n, n2; /* handy integer (short term usage) */
899 char *cp; /* handy char pointer (short term usage) */
900 int flags; /* flags as above */
901 int width; /* width from format (%8d), or 0 */
902 unsigned char *typetable; /* table of types */
903 unsigned char stattypetable [STATIC_ARG_TBL_SIZE];
904 int tablesize; /* current size of type table */
905 int tablemax; /* largest used index in table */
906 int nextarg; /* 1-based argument index */
909 * Add an argument type to the table, expanding if necessary.
911 #define ADDTYPE(type) \
912 ((nextarg >= tablesize) ? \
913 __grow_type_table(nextarg, &typetable, &tablesize) : 0, \
914 (nextarg > tablemax) ? tablemax = nextarg : 0, \
915 typetable[nextarg++] = type)
918 ((flags&LONGINT) ? ADDTYPE(T_LONG) : \
919 ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT)))
922 ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \
923 ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT)))
926 * Add * arguments to the type array.
931 while (is_digit(*cp)) { \
932 n2 = 10 * n2 + to_digit(*cp); \
936 int hold = nextarg; \
945 typetable = stattypetable;
946 tablesize = STATIC_ARG_TBL_SIZE;
949 memset (typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
952 * Scan the format for conversions (`%' character).
955 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
959 fmt++; /* skip over '%' */
965 reswitch: switch (ch) {
976 if ((ch = *fmt++) == '*') {
980 while (is_digit(ch)) {
986 case '1': case '2': case '3': case '4':
987 case '5': case '6': case '7': case '8': case '9':
990 n = 10 * n + to_digit(ch);
992 } while (is_digit(ch));
999 #ifdef FLOATING_POINT
1008 if (flags & LONGINT)
1024 if (flags & QUADINT) {
1030 #ifdef FLOATING_POINT
1036 if (flags & LONGDBL)
1037 ADDTYPE(T_LONG_DOUBLE);
1041 #endif /* FLOATING_POINT */
1043 if (flags & QUADINT)
1045 else if (flags & LONGINT)
1047 else if (flags & SHORTINT)
1051 continue; /* no output */
1056 if (flags & QUADINT)
1071 if (flags & QUADINT)
1078 if (flags & QUADINT)
1083 default: /* "%?" prints ?, unless ? is NUL */
1091 * Build the argument table.
1093 if (tablemax >= STATIC_ARG_TBL_SIZE) {
1094 *argtable = (void **)
1095 malloc (sizeof (void *) * (tablemax + 1));
1098 (*argtable) [0] = NULL;
1099 for (n = 1; n <= tablemax; n++) {
1100 switch (typetable [n]) {
1102 (*argtable) [n] = (void *) &va_arg (ap, int);
1105 (*argtable) [n] = (void *) &va_arg (ap, int);
1108 (*argtable) [n] = (void *) &va_arg (ap, int);
1111 (*argtable) [n] = (void *) &va_arg (ap, short *);
1114 (*argtable) [n] = (void *) &va_arg (ap, int);
1117 (*argtable) [n] = (void *) &va_arg (ap, unsigned int);
1120 (*argtable) [n] = (void *) &va_arg (ap, int *);
1123 (*argtable) [n] = (void *) &va_arg (ap, long);
1126 (*argtable) [n] = (void *) &va_arg (ap, unsigned long);
1129 (*argtable) [n] = (void *) &va_arg (ap, long *);
1132 (*argtable) [n] = (void *) &va_arg (ap, quad_t);
1135 (*argtable) [n] = (void *) &va_arg (ap, u_quad_t);
1138 (*argtable) [n] = (void *) &va_arg (ap, quad_t *);
1141 (*argtable) [n] = (void *) &va_arg (ap, double);
1144 (*argtable) [n] = (void *) &va_arg (ap, long double);
1147 (*argtable) [n] = (void *) &va_arg (ap, char *);
1150 (*argtable) [n] = (void *) &va_arg (ap, void *);
1155 if ((typetable != NULL) && (typetable != stattypetable))
1160 * Increase the size of the type table.
1163 __grow_type_table (int nextarg, unsigned char **typetable, int *tablesize)
1165 unsigned char *const oldtable = *typetable;
1166 const int oldsize = *tablesize;
1167 unsigned char *newtable;
1168 int newsize = oldsize * 2;
1170 if (newsize < nextarg + 1)
1171 newsize = nextarg + 1;
1172 if (oldsize == STATIC_ARG_TBL_SIZE) {
1173 if ((newtable = malloc(newsize)) == NULL)
1174 abort(); /* XXX handle better */
1175 bcopy(oldtable, newtable, oldsize);
1177 if ((newtable = reallocf(oldtable, newsize)) == NULL)
1178 abort(); /* XXX handle better */
1180 memset(&newtable[oldsize], T_UNUSED, newsize - oldsize);
1182 *typetable = newtable;
1183 *tablesize = newsize;
1187 #ifdef FLOATING_POINT
1189 extern char *__dtoa (double, int, int, int *, int *, char **, char **);
1192 cvt(double value, int ndigits, int flags, char *sign, int *decpt,
1193 int ch, int *length, char **dtoaresultp)
1196 char *digits, *bp, *rve;
1199 mode = 3; /* ndigits after the decimal point */
1202 * To obtain ndigits after the decimal point for the 'e'
1203 * and 'E' formats, round to ndigits + 1 significant
1206 if (ch == 'e' || ch == 'E')
1208 mode = 2; /* ndigits significant digits */
1210 digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve, dtoaresultp);
1212 if ((ch != 'g' && ch != 'G') || flags & ALT) {
1213 /* print trailing zeros */
1214 bp = digits + ndigits;
1216 if (*digits == '0' && value)
1217 *decpt = -ndigits + 1;
1220 if (value == 0) /* kludge for __dtoa irregularity */
1225 *length = rve - digits;
1230 exponent(char *p0, int exp, int fmtch)
1233 char expbuf[MAXEXP];
1243 t = expbuf + MAXEXP;
1246 *--t = to_char(exp % 10);
1247 } while ((exp /= 10) > 9);
1248 *--t = to_char(exp);
1249 for (; t < expbuf + MAXEXP; *p++ = *t++);
1253 *p++ = to_char(exp);
1257 #endif /* FLOATING_POINT */