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.3 2003/11/12 20:21:28 eirikn Exp $
42 * Actual printf innards.
44 * This code is large and complicated...
47 #include <sys/types.h>
60 #include "libc_private.h"
64 /* Define FLOATING_POINT to get floating point. */
65 #define FLOATING_POINT
67 static int __sprint (FILE *, struct __suio *);
68 static int __sbprintf (FILE *, const char *, va_list);
69 static char * __ultoa (u_long, char *, int, int, char *);
70 static char * __uqtoa (u_quad_t, char *, int, int, char *);
71 static void __find_arguments (const char *, va_list, void ***);
72 static void __grow_type_table (int, unsigned char **, int *);
75 * Flush out all the vectors defined by the given uio,
76 * then reset it so that it can be reused.
79 __sprint(FILE *fp, struct __suio *uio)
83 if (uio->uio_resid == 0) {
87 err = __sfvwrite(fp, uio);
94 * Helper function for `fprintf to unbuffered unix file': creates a
95 * temporary buffer. We only work on write-only files; this avoids
96 * worries about ungetc buffers and so forth.
99 __sbprintf(FILE *fp, const char *fmt, va_list ap)
103 unsigned char buf[BUFSIZ];
105 /* copy the important variables */
106 fake._flags = fp->_flags & ~__SNBF;
107 fake._file = fp->_file;
108 fake._cookie = fp->_cookie;
109 fake._write = fp->_write;
111 /* set up the buffer */
112 fake._bf._base = fake._p = buf;
113 fake._bf._size = fake._w = sizeof(buf);
114 fake._lbfsize = 0; /* not actually used, but Just In Case */
116 /* do the work, then copy any error status */
117 ret = vfprintf(&fake, fmt, ap);
118 if (ret >= 0 && fflush(&fake))
120 if (fake._flags & __SERR)
121 fp->_flags |= __SERR;
126 * Macros for converting digits to letters and vice versa
128 #define to_digit(c) ((c) - '0')
129 #define is_digit(c) ((unsigned)to_digit(c) <= 9)
130 #define to_char(n) ((n) + '0')
133 * Convert an unsigned long to ASCII for printf purposes, returning
134 * a pointer to the first character of the string representation.
135 * Octal numbers can be forced to have a leading zero; hex numbers
136 * use the given digits.
139 __ultoa(u_long val, char *endp, int base, int octzero, char *xdigs)
141 register char *cp = endp;
145 * Handle the three cases separately, in the hope of getting
146 * better/faster code.
150 if (val < 10) { /* many numbers are 1 digit */
151 *--cp = to_char(val);
155 * On many machines, unsigned arithmetic is harder than
156 * signed arithmetic, so we do at most one unsigned mod and
157 * divide; this is sufficient to reduce the range of
158 * the incoming value to where signed arithmetic works.
160 if (val > LONG_MAX) {
161 *--cp = to_char(val % 10);
166 *--cp = to_char(sval % 10);
173 *--cp = to_char(val & 7);
176 if (octzero && *cp != '0')
182 *--cp = xdigs[val & 15];
193 /* Identical to __ultoa, but for quads. */
195 __uqtoa(u_quad_t val, char *endp, int base, int octzero, char *xdigs)
200 /* quick test for small values; __ultoa is typically much faster */
201 /* (perhaps instead we should run until small, then call __ultoa?) */
202 if (val <= ULONG_MAX)
203 return (__ultoa((u_long)val, endp, base, octzero, xdigs));
207 *--cp = to_char(val % 10);
210 if (val > QUAD_MAX) {
211 *--cp = to_char(val % 10);
216 *--cp = to_char(sval % 10);
223 *--cp = to_char(val & 7);
226 if (octzero && *cp != '0')
232 *--cp = xdigs[val & 15];
243 #ifdef FLOATING_POINT
248 #define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */
251 static char *cvt (double, int, int, char *, int *, int, int *, char **);
252 static int exponent (char *, int, int);
254 #else /* no FLOATING_POINT */
258 #endif /* FLOATING_POINT */
260 #define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */
263 * Flags used during conversion.
265 #define ALT 0x001 /* alternate form */
266 #define HEXPREFIX 0x002 /* add 0x or 0X prefix */
267 #define LADJUST 0x004 /* left adjustment */
268 #define LONGDBL 0x008 /* long double */
269 #define LONGINT 0x010 /* long integer */
270 #define QUADINT 0x020 /* quad integer */
271 #define SHORTINT 0x040 /* short integer */
272 #define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
273 #define FPT 0x100 /* Floating point number */
275 vfprintf(FILE *fp, const char *fmt0, va_list ap)
277 char *fmt; /* format string */
278 int ch; /* character from fmt */
279 int n, n2; /* handy integer (short term usage) */
280 char *cp; /* handy char pointer (short term usage) */
281 struct __siov *iovp; /* for PRINT macro */
282 int flags; /* flags as above */
283 int ret; /* return value accumulator */
284 int width; /* width from format (%8d), or 0 */
285 int prec; /* precision from format (%.3d), or -1 */
286 char sign; /* sign prefix (' ', '+', '-', or \0) */
287 #ifdef FLOATING_POINT
288 char *decimal_point = localeconv()->decimal_point;
289 char softsign; /* temporary negative sign for floats */
290 double _double; /* double precision arguments %[eEfgG] */
291 int expt; /* integer value of exponent */
292 int expsize; /* character count for expstr */
293 int ndig; /* actual number of digits returned by cvt */
294 char expstr[7]; /* buffer for exponent string */
295 char *dtoaresult; /* buffer allocated by dtoa */
297 u_long ulval; /* integer arguments %[diouxX] */
298 u_quad_t uqval; /* %q integers */
299 int base; /* base for [diouxX] conversion */
300 int dprec; /* a copy of prec if [diouxX], 0 otherwise */
301 int realsz; /* field size expanded by dprec, sign, etc */
302 int size; /* size of converted field or string */
303 int prsize; /* max size of printed field */
304 char *xdigs; /* digits for [xX] conversion */
306 struct __suio uio; /* output information: summary */
307 struct __siov iov[NIOV];/* ... and individual io vectors */
308 char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
309 char ox[2]; /* space for 0x hex-prefix */
310 void **argtable; /* args, built due to positional arg */
311 void *statargtable [STATIC_ARG_TBL_SIZE];
312 int nextarg; /* 1-based argument index */
313 va_list orgap; /* original argument pointer */
316 * Choose PADSIZE to trade efficiency vs. size. If larger printf
317 * fields occur frequently, increase PADSIZE and make the initialisers
320 #define PADSIZE 16 /* pad chunk size */
321 static char blanks[PADSIZE] =
322 {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
323 static char zeroes[PADSIZE] =
324 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
327 * BEWARE, these `goto error' on error, and PAD uses `n'.
329 #define PRINT(ptr, len) { \
330 iovp->iov_base = (ptr); \
331 iovp->iov_len = (len); \
332 uio.uio_resid += (len); \
334 if (++uio.uio_iovcnt >= NIOV) { \
335 if (__sprint(fp, &uio)) \
340 #define PAD(howmany, with) { \
341 if ((n = (howmany)) > 0) { \
342 while (n > PADSIZE) { \
343 PRINT(with, PADSIZE); \
350 if (uio.uio_resid && __sprint(fp, &uio)) \
352 uio.uio_iovcnt = 0; \
357 * Get the argument indexed by nextarg. If the argument table is
358 * built, use it to get the argument. If its not, get the next
359 * argument (and arguments must be gotten sequentially).
361 #define GETARG(type) \
362 ((argtable != NULL) ? *((type*)(argtable[nextarg++])) : \
363 (nextarg++, va_arg(ap, type)))
366 * To extend shorts properly, we need both signed and unsigned
367 * argument extraction methods.
370 (flags&LONGINT ? GETARG(long) : \
371 flags&SHORTINT ? (long)(short)GETARG(int) : \
374 (flags&LONGINT ? GETARG(u_long) : \
375 flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
376 (u_long)GETARG(u_int))
379 * Get * arguments, including the form *nn$. Preserve the nextarg
380 * that the argument can be gotten once the type is determined.
382 #define GETASTER(val) \
385 while (is_digit(*cp)) { \
386 n2 = 10 * n2 + to_digit(*cp); \
390 int hold = nextarg; \
391 if (argtable == NULL) { \
392 argtable = statargtable; \
393 __find_arguments (fmt0, orgap, &argtable); \
396 val = GETARG (int); \
400 val = GETARG (int); \
404 #ifdef FLOATING_POINT
408 /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
414 /* optimise fprintf(stderr) (and other unbuffered Unix files) */
415 if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
418 return (__sbprintf(fp, fmt0, ap));
425 uio.uio_iov = iovp = iov;
431 * Scan the format for conversions (`%' character).
434 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
436 if ((n = fmt - cp) != 0) {
437 if ((unsigned)ret + n > INT_MAX) {
446 fmt++; /* skip over '%' */
455 reswitch: switch (ch) {
458 * ``If the space and + flags both appear, the space
459 * flag will be ignored.''
470 * ``A negative field width argument is taken as a
471 * - flag followed by a positive field width.''
473 * They don't exclude field widths read from args.
487 if ((ch = *fmt++) == '*') {
489 prec = n < 0 ? -1 : n;
493 while (is_digit(ch)) {
494 n = 10 * n + to_digit(ch);
497 prec = n < 0 ? -1 : n;
501 * ``Note that 0 is taken as a flag, not as the
502 * beginning of a field width.''
507 case '1': case '2': case '3': case '4':
508 case '5': case '6': case '7': case '8': case '9':
511 n = 10 * n + to_digit(ch);
513 } while (is_digit(ch));
516 if (argtable == NULL) {
517 argtable = statargtable;
518 __find_arguments (fmt0, orgap,
525 #ifdef FLOATING_POINT
543 *(cp = buf) = GETARG(int);
552 if (flags & QUADINT) {
553 uqval = GETARG(quad_t);
554 if ((quad_t)uqval < 0) {
560 if ((long)ulval < 0) {
567 #ifdef FLOATING_POINT
576 fp_begin: if (prec == -1)
579 /* XXX this loses precision. */
580 _double = (double)GETARG(long double);
582 _double = GETARG(double);
583 /* do this before tricky precision changes */
584 if (isinf(_double)) {
591 if (isnan(_double)) {
597 if (dtoaresult != NULL) {
601 cp = cvt(_double, prec, flags, &softsign,
602 &expt, ch, &ndig, &dtoaresult);
603 if (ch == 'g' || ch == 'G') {
604 if (expt <= -4 || expt > prec)
605 ch = (ch == 'g') ? 'e' : 'E';
609 if (ch <= 'e') { /* 'e' or 'E' fmt */
611 expsize = exponent(expstr, expt, ch);
612 size = expsize + ndig;
613 if (ndig > 1 || flags & ALT)
615 } else if (ch == 'f') { /* f fmt */
618 if (prec || flags & ALT)
622 } else if (expt >= ndig) { /* fixed g fmt */
627 size = ndig + (expt > 0 ?
633 #endif /* FLOATING_POINT */
636 *GETARG(quad_t *) = ret;
637 else if (flags & LONGINT)
638 *GETARG(long *) = ret;
639 else if (flags & SHORTINT)
640 *GETARG(short *) = ret;
642 *GETARG(int *) = ret;
643 continue; /* no output */
649 uqval = GETARG(u_quad_t);
656 * ``The argument shall be a pointer to void. The
657 * value of the pointer is converted to a sequence
658 * of printable characters, in an implementation-
662 ulval = (u_long)GETARG(void *);
664 xdigs = "0123456789abcdef";
665 flags = (flags & ~QUADINT) | HEXPREFIX;
669 if ((cp = GETARG(char *)) == NULL)
673 * can't use strlen; can only look for the
674 * NUL in the first `prec' characters, and
675 * strlen() will go further.
677 char *p = memchr(cp, 0, (size_t)prec);
694 uqval = GETARG(u_quad_t);
700 xdigs = "0123456789ABCDEF";
703 xdigs = "0123456789abcdef";
704 hex: if (flags & QUADINT)
705 uqval = GETARG(u_quad_t);
709 /* leading 0x/X only if non-zero */
711 (flags & QUADINT ? uqval != 0 : ulval != 0))
714 /* unsigned conversions */
717 * ``... diouXx conversions ... if a precision is
718 * specified, the 0 flag will be ignored.''
721 number: if ((dprec = prec) >= 0)
725 * ``The result of converting a zero value with an
726 * explicit precision of zero is no characters.''
730 if (flags & QUADINT) {
731 if (uqval != 0 || prec != 0)
732 cp = __uqtoa(uqval, cp, base,
735 if (ulval != 0 || prec != 0)
736 cp = __ultoa(ulval, cp, base,
739 size = buf + BUF - cp;
741 default: /* "%?" prints ?, unless ? is NUL */
744 /* pretend it was %c with argument ch */
753 * All reasonable formats wind up here. At this point, `cp'
754 * points to a string which (if not flags&LADJUST) should be
755 * padded out to `width' places. If flags&ZEROPAD, it should
756 * first be prefixed by any sign or other prefix; otherwise,
757 * it should be blank padded before the prefix is emitted.
758 * After any left-hand padding and prefixing, emit zeroes
759 * required by a decimal [diouxX] precision, then print the
760 * string proper, then emit zeroes required by any leftover
761 * floating precision; finally, if LADJUST, pad with blanks.
763 * Compute actual size, so we know how much to pad.
764 * size excludes decimal prec; realsz includes it.
766 realsz = dprec > size ? dprec : size;
769 else if (flags & HEXPREFIX)
772 prsize = width > realsz ? width : realsz;
773 if ((unsigned)ret + prsize > INT_MAX) {
778 /* right-adjusting blank padding */
779 if ((flags & (LADJUST|ZEROPAD)) == 0)
780 PAD(width - realsz, blanks);
785 } else if (flags & HEXPREFIX) {
791 /* right-adjusting zero padding */
792 if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
793 PAD(width - realsz, zeroes);
795 /* leading zeroes from decimal precision */
796 PAD(dprec - size, zeroes);
798 /* the string or number proper */
799 #ifdef FLOATING_POINT
800 if ((flags & FPT) == 0) {
802 } else { /* glue together f_p fragments */
803 if (ch >= 'f') { /* 'f' or 'g' */
805 /* kludge for __dtoa irregularity */
807 if (expt < ndig || (flags & ALT) != 0) {
808 PRINT(decimal_point, 1);
809 PAD(ndig - 1, zeroes);
811 } else if (expt <= 0) {
813 PRINT(decimal_point, 1);
816 } else if (expt >= ndig) {
818 PAD(expt - ndig, zeroes);
820 PRINT(decimal_point, 1);
824 PRINT(decimal_point, 1);
825 PRINT(cp, ndig-expt);
827 } else { /* 'e' or 'E' */
828 if (ndig > 1 || flags & ALT) {
830 ox[1] = *decimal_point;
835 /* __dtoa irregularity */
836 PAD(ndig - 1, zeroes);
839 PRINT(expstr, expsize);
845 /* left-adjusting padding (always blank) */
847 PAD(width - realsz, blanks);
849 /* finally, adjust ret */
852 FLUSH(); /* copy out the I/O vectors */
857 #ifdef FLOATING_POINT
858 if (dtoaresult != NULL)
864 if ((argtable != NULL) && (argtable != statargtable))
871 * Type ids for argument type table.
887 #define T_LONG_DOUBLE 14
892 * Find all arguments when a positional parameter is encountered. Returns a
893 * table, indexed by argument number, of pointers to each arguments. The
894 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
895 * It will be replaces with a malloc-ed one if it overflows.
898 __find_arguments (const char *fmt0, va_list ap, void ***argtable)
900 char *fmt; /* format string */
901 int ch; /* character from fmt */
902 int n, n2; /* handy integer (short term usage) */
903 char *cp; /* handy char pointer (short term usage) */
904 int flags; /* flags as above */
905 int width; /* width from format (%8d), or 0 */
906 unsigned char *typetable; /* table of types */
907 unsigned char stattypetable [STATIC_ARG_TBL_SIZE];
908 int tablesize; /* current size of type table */
909 int tablemax; /* largest used index in table */
910 int nextarg; /* 1-based argument index */
913 * Add an argument type to the table, expanding if necessary.
915 #define ADDTYPE(type) \
916 ((nextarg >= tablesize) ? \
917 __grow_type_table(nextarg, &typetable, &tablesize) : 0, \
918 (nextarg > tablemax) ? tablemax = nextarg : 0, \
919 typetable[nextarg++] = type)
922 ((flags&LONGINT) ? ADDTYPE(T_LONG) : \
923 ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT)))
926 ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \
927 ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT)))
930 * Add * arguments to the type array.
935 while (is_digit(*cp)) { \
936 n2 = 10 * n2 + to_digit(*cp); \
940 int hold = nextarg; \
949 typetable = stattypetable;
950 tablesize = STATIC_ARG_TBL_SIZE;
953 memset (typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
956 * Scan the format for conversions (`%' character).
959 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
963 fmt++; /* skip over '%' */
969 reswitch: switch (ch) {
980 if ((ch = *fmt++) == '*') {
984 while (is_digit(ch)) {
990 case '1': case '2': case '3': case '4':
991 case '5': case '6': case '7': case '8': case '9':
994 n = 10 * n + to_digit(ch);
996 } while (is_digit(ch));
1003 #ifdef FLOATING_POINT
1012 if (flags & LONGINT)
1028 if (flags & QUADINT) {
1034 #ifdef FLOATING_POINT
1040 if (flags & LONGDBL)
1041 ADDTYPE(T_LONG_DOUBLE);
1045 #endif /* FLOATING_POINT */
1047 if (flags & QUADINT)
1049 else if (flags & LONGINT)
1051 else if (flags & SHORTINT)
1055 continue; /* no output */
1060 if (flags & QUADINT)
1075 if (flags & QUADINT)
1082 if (flags & QUADINT)
1087 default: /* "%?" prints ?, unless ? is NUL */
1095 * Build the argument table.
1097 if (tablemax >= STATIC_ARG_TBL_SIZE) {
1098 *argtable = (void **)
1099 malloc (sizeof (void *) * (tablemax + 1));
1102 (*argtable) [0] = NULL;
1103 for (n = 1; n <= tablemax; n++) {
1104 switch (typetable [n]) {
1106 (*argtable) [n] = (void *) &va_arg (ap, int);
1109 (*argtable) [n] = (void *) &va_arg (ap, int);
1112 (*argtable) [n] = (void *) &va_arg (ap, int);
1115 (*argtable) [n] = (void *) &va_arg (ap, short *);
1118 (*argtable) [n] = (void *) &va_arg (ap, int);
1121 (*argtable) [n] = (void *) &va_arg (ap, unsigned int);
1124 (*argtable) [n] = (void *) &va_arg (ap, int *);
1127 (*argtable) [n] = (void *) &va_arg (ap, long);
1130 (*argtable) [n] = (void *) &va_arg (ap, unsigned long);
1133 (*argtable) [n] = (void *) &va_arg (ap, long *);
1136 (*argtable) [n] = (void *) &va_arg (ap, quad_t);
1139 (*argtable) [n] = (void *) &va_arg (ap, u_quad_t);
1142 (*argtable) [n] = (void *) &va_arg (ap, quad_t *);
1145 (*argtable) [n] = (void *) &va_arg (ap, double);
1148 (*argtable) [n] = (void *) &va_arg (ap, long double);
1151 (*argtable) [n] = (void *) &va_arg (ap, char *);
1154 (*argtable) [n] = (void *) &va_arg (ap, void *);
1159 if ((typetable != NULL) && (typetable != stattypetable))
1164 * Increase the size of the type table.
1167 __grow_type_table (int nextarg, unsigned char **typetable, int *tablesize)
1169 unsigned char *const oldtable = *typetable;
1170 const int oldsize = *tablesize;
1171 unsigned char *newtable;
1172 int newsize = oldsize * 2;
1174 if (newsize < nextarg + 1)
1175 newsize = nextarg + 1;
1176 if (oldsize == STATIC_ARG_TBL_SIZE) {
1177 if ((newtable = malloc(newsize)) == NULL)
1178 abort(); /* XXX handle better */
1179 bcopy(oldtable, newtable, oldsize);
1181 if ((newtable = reallocf(oldtable, newsize)) == NULL)
1182 abort(); /* XXX handle better */
1184 memset(&newtable[oldsize], T_UNUSED, newsize - oldsize);
1186 *typetable = newtable;
1187 *tablesize = newsize;
1191 #ifdef FLOATING_POINT
1193 extern char *__dtoa (double, int, int, int *, int *, char **, char **);
1196 cvt(double value, int ndigits, int flags, char *sign, int *decpt,
1197 int ch, int *length, char **dtoaresultp)
1200 char *digits, *bp, *rve;
1203 mode = 3; /* ndigits after the decimal point */
1206 * To obtain ndigits after the decimal point for the 'e'
1207 * and 'E' formats, round to ndigits + 1 significant
1210 if (ch == 'e' || ch == 'E')
1212 mode = 2; /* ndigits significant digits */
1214 digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve, dtoaresultp);
1216 if ((ch != 'g' && ch != 'G') || flags & ALT) {
1217 /* print trailing zeros */
1218 bp = digits + ndigits;
1220 if (*digits == '0' && value)
1221 *decpt = -ndigits + 1;
1224 if (value == 0) /* kludge for __dtoa irregularity */
1229 *length = rve - digits;
1234 exponent(char *p0, int exp, int fmtch)
1237 char expbuf[MAXEXP];
1247 t = expbuf + MAXEXP;
1250 *--t = to_char(exp % 10);
1251 } while ((exp /= 10) > 9);
1252 *--t = to_char(exp);
1253 for (; t < expbuf + MAXEXP; *p++ = *t++);
1257 *p++ = to_char(exp);
1261 #endif /* FLOATING_POINT */