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
37 #if defined(LIBC_SCCS) && !defined(lint)
39 static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
41 static const char rcsid[] =
42 "$FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.22.2.5 2002/10/12 10:46:37 schweikh Exp $";
43 #endif /* LIBC_SCCS and not lint */
46 * Actual printf innards.
48 * This code is large and complicated...
51 #include <sys/types.h>
64 #include "libc_private.h"
68 /* Define FLOATING_POINT to get floating point. */
69 #define FLOATING_POINT
71 static int __sprint __P((FILE *, struct __suio *));
72 static int __sbprintf __P((FILE *, const char *, va_list));
73 static char * __ultoa __P((u_long, char *, int, int, char *));
74 static char * __uqtoa __P((u_quad_t, char *, int, int, char *));
75 static void __find_arguments __P((const char *, va_list, void ***));
76 static void __grow_type_table __P((int, unsigned char **, int *));
79 * Flush out all the vectors defined by the given uio,
80 * then reset it so that it can be reused.
83 __sprint(FILE *fp, struct __suio *uio)
87 if (uio->uio_resid == 0) {
91 err = __sfvwrite(fp, uio);
98 * Helper function for `fprintf to unbuffered unix file': creates a
99 * temporary buffer. We only work on write-only files; this avoids
100 * worries about ungetc buffers and so forth.
103 __sbprintf(FILE *fp, const char *fmt, va_list ap)
107 unsigned char buf[BUFSIZ];
109 /* copy the important variables */
110 fake._flags = fp->_flags & ~__SNBF;
111 fake._file = fp->_file;
112 fake._cookie = fp->_cookie;
113 fake._write = fp->_write;
115 /* set up the buffer */
116 fake._bf._base = fake._p = buf;
117 fake._bf._size = fake._w = sizeof(buf);
118 fake._lbfsize = 0; /* not actually used, but Just In Case */
120 /* do the work, then copy any error status */
121 ret = vfprintf(&fake, fmt, ap);
122 if (ret >= 0 && fflush(&fake))
124 if (fake._flags & __SERR)
125 fp->_flags |= __SERR;
130 * Macros for converting digits to letters and vice versa
132 #define to_digit(c) ((c) - '0')
133 #define is_digit(c) ((unsigned)to_digit(c) <= 9)
134 #define to_char(n) ((n) + '0')
137 * Convert an unsigned long to ASCII for printf purposes, returning
138 * a pointer to the first character of the string representation.
139 * Octal numbers can be forced to have a leading zero; hex numbers
140 * use the given digits.
143 __ultoa(u_long val, char *endp, int base, int octzero, char *xdigs)
145 register char *cp = endp;
149 * Handle the three cases separately, in the hope of getting
150 * better/faster code.
154 if (val < 10) { /* many numbers are 1 digit */
155 *--cp = to_char(val);
159 * On many machines, unsigned arithmetic is harder than
160 * signed arithmetic, so we do at most one unsigned mod and
161 * divide; this is sufficient to reduce the range of
162 * the incoming value to where signed arithmetic works.
164 if (val > LONG_MAX) {
165 *--cp = to_char(val % 10);
170 *--cp = to_char(sval % 10);
177 *--cp = to_char(val & 7);
180 if (octzero && *cp != '0')
186 *--cp = xdigs[val & 15];
197 /* Identical to __ultoa, but for quads. */
199 __uqtoa(u_quad_t val, char *endp, int base, int octzero, char *xdigs)
204 /* quick test for small values; __ultoa is typically much faster */
205 /* (perhaps instead we should run until small, then call __ultoa?) */
206 if (val <= ULONG_MAX)
207 return (__ultoa((u_long)val, endp, base, octzero, xdigs));
211 *--cp = to_char(val % 10);
214 if (val > QUAD_MAX) {
215 *--cp = to_char(val % 10);
220 *--cp = to_char(sval % 10);
227 *--cp = to_char(val & 7);
230 if (octzero && *cp != '0')
236 *--cp = xdigs[val & 15];
247 #ifdef FLOATING_POINT
252 #define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */
255 static char *cvt __P((double, int, int, char *, int *, int, int *, char **));
256 static int exponent __P((char *, int, int));
258 #else /* no FLOATING_POINT */
262 #endif /* FLOATING_POINT */
264 #define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */
267 * Flags used during conversion.
269 #define ALT 0x001 /* alternate form */
270 #define HEXPREFIX 0x002 /* add 0x or 0X prefix */
271 #define LADJUST 0x004 /* left adjustment */
272 #define LONGDBL 0x008 /* long double */
273 #define LONGINT 0x010 /* long integer */
274 #define QUADINT 0x020 /* quad integer */
275 #define SHORTINT 0x040 /* short integer */
276 #define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
277 #define FPT 0x100 /* Floating point number */
279 vfprintf(FILE *fp, const char *fmt0, va_list ap)
281 char *fmt; /* format string */
282 int ch; /* character from fmt */
283 int n, n2; /* handy integer (short term usage) */
284 char *cp; /* handy char pointer (short term usage) */
285 struct __siov *iovp; /* for PRINT macro */
286 int flags; /* flags as above */
287 int ret; /* return value accumulator */
288 int width; /* width from format (%8d), or 0 */
289 int prec; /* precision from format (%.3d), or -1 */
290 char sign; /* sign prefix (' ', '+', '-', or \0) */
291 #ifdef FLOATING_POINT
292 char *decimal_point = localeconv()->decimal_point;
293 char softsign; /* temporary negative sign for floats */
294 double _double; /* double precision arguments %[eEfgG] */
295 int expt; /* integer value of exponent */
296 int expsize; /* character count for expstr */
297 int ndig; /* actual number of digits returned by cvt */
298 char expstr[7]; /* buffer for exponent string */
299 char *dtoaresult; /* buffer allocated by dtoa */
301 u_long ulval; /* integer arguments %[diouxX] */
302 u_quad_t uqval; /* %q integers */
303 int base; /* base for [diouxX] conversion */
304 int dprec; /* a copy of prec if [diouxX], 0 otherwise */
305 int realsz; /* field size expanded by dprec, sign, etc */
306 int size; /* size of converted field or string */
307 int prsize; /* max size of printed field */
308 char *xdigs; /* digits for [xX] conversion */
310 struct __suio uio; /* output information: summary */
311 struct __siov iov[NIOV];/* ... and individual io vectors */
312 char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
313 char ox[2]; /* space for 0x hex-prefix */
314 void **argtable; /* args, built due to positional arg */
315 void *statargtable [STATIC_ARG_TBL_SIZE];
316 int nextarg; /* 1-based argument index */
317 va_list orgap; /* original argument pointer */
320 * Choose PADSIZE to trade efficiency vs. size. If larger printf
321 * fields occur frequently, increase PADSIZE and make the initialisers
324 #define PADSIZE 16 /* pad chunk size */
325 static char blanks[PADSIZE] =
326 {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
327 static char zeroes[PADSIZE] =
328 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
331 * BEWARE, these `goto error' on error, and PAD uses `n'.
333 #define PRINT(ptr, len) { \
334 iovp->iov_base = (ptr); \
335 iovp->iov_len = (len); \
336 uio.uio_resid += (len); \
338 if (++uio.uio_iovcnt >= NIOV) { \
339 if (__sprint(fp, &uio)) \
344 #define PAD(howmany, with) { \
345 if ((n = (howmany)) > 0) { \
346 while (n > PADSIZE) { \
347 PRINT(with, PADSIZE); \
354 if (uio.uio_resid && __sprint(fp, &uio)) \
356 uio.uio_iovcnt = 0; \
361 * Get the argument indexed by nextarg. If the argument table is
362 * built, use it to get the argument. If its not, get the next
363 * argument (and arguments must be gotten sequentially).
365 #define GETARG(type) \
366 ((argtable != NULL) ? *((type*)(argtable[nextarg++])) : \
367 (nextarg++, va_arg(ap, type)))
370 * To extend shorts properly, we need both signed and unsigned
371 * argument extraction methods.
374 (flags&LONGINT ? GETARG(long) : \
375 flags&SHORTINT ? (long)(short)GETARG(int) : \
378 (flags&LONGINT ? GETARG(u_long) : \
379 flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
380 (u_long)GETARG(u_int))
383 * Get * arguments, including the form *nn$. Preserve the nextarg
384 * that the argument can be gotten once the type is determined.
386 #define GETASTER(val) \
389 while (is_digit(*cp)) { \
390 n2 = 10 * n2 + to_digit(*cp); \
394 int hold = nextarg; \
395 if (argtable == NULL) { \
396 argtable = statargtable; \
397 __find_arguments (fmt0, orgap, &argtable); \
400 val = GETARG (int); \
404 val = GETARG (int); \
408 #ifdef FLOATING_POINT
412 /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
418 /* optimise fprintf(stderr) (and other unbuffered Unix files) */
419 if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
422 return (__sbprintf(fp, fmt0, ap));
429 uio.uio_iov = iovp = iov;
435 * Scan the format for conversions (`%' character).
438 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
440 if ((n = fmt - cp) != 0) {
441 if ((unsigned)ret + n > INT_MAX) {
450 fmt++; /* skip over '%' */
459 reswitch: switch (ch) {
462 * ``If the space and + flags both appear, the space
463 * flag will be ignored.''
474 * ``A negative field width argument is taken as a
475 * - flag followed by a positive field width.''
477 * They don't exclude field widths read from args.
491 if ((ch = *fmt++) == '*') {
493 prec = n < 0 ? -1 : n;
497 while (is_digit(ch)) {
498 n = 10 * n + to_digit(ch);
501 prec = n < 0 ? -1 : n;
505 * ``Note that 0 is taken as a flag, not as the
506 * beginning of a field width.''
511 case '1': case '2': case '3': case '4':
512 case '5': case '6': case '7': case '8': case '9':
515 n = 10 * n + to_digit(ch);
517 } while (is_digit(ch));
520 if (argtable == NULL) {
521 argtable = statargtable;
522 __find_arguments (fmt0, orgap,
529 #ifdef FLOATING_POINT
547 *(cp = buf) = GETARG(int);
556 if (flags & QUADINT) {
557 uqval = GETARG(quad_t);
558 if ((quad_t)uqval < 0) {
564 if ((long)ulval < 0) {
571 #ifdef FLOATING_POINT
580 fp_begin: if (prec == -1)
583 /* XXX this loses precision. */
584 _double = (double)GETARG(long double);
586 _double = GETARG(double);
587 /* do this before tricky precision changes */
588 if (isinf(_double)) {
595 if (isnan(_double)) {
601 if (dtoaresult != NULL) {
605 cp = cvt(_double, prec, flags, &softsign,
606 &expt, ch, &ndig, &dtoaresult);
607 if (ch == 'g' || ch == 'G') {
608 if (expt <= -4 || expt > prec)
609 ch = (ch == 'g') ? 'e' : 'E';
613 if (ch <= 'e') { /* 'e' or 'E' fmt */
615 expsize = exponent(expstr, expt, ch);
616 size = expsize + ndig;
617 if (ndig > 1 || flags & ALT)
619 } else if (ch == 'f') { /* f fmt */
622 if (prec || flags & ALT)
626 } else if (expt >= ndig) { /* fixed g fmt */
631 size = ndig + (expt > 0 ?
637 #endif /* FLOATING_POINT */
640 *GETARG(quad_t *) = ret;
641 else if (flags & LONGINT)
642 *GETARG(long *) = ret;
643 else if (flags & SHORTINT)
644 *GETARG(short *) = ret;
646 *GETARG(int *) = ret;
647 continue; /* no output */
653 uqval = GETARG(u_quad_t);
660 * ``The argument shall be a pointer to void. The
661 * value of the pointer is converted to a sequence
662 * of printable characters, in an implementation-
666 ulval = (u_long)GETARG(void *);
668 xdigs = "0123456789abcdef";
669 flags = (flags & ~QUADINT) | HEXPREFIX;
673 if ((cp = GETARG(char *)) == NULL)
677 * can't use strlen; can only look for the
678 * NUL in the first `prec' characters, and
679 * strlen() will go further.
681 char *p = memchr(cp, 0, (size_t)prec);
698 uqval = GETARG(u_quad_t);
704 xdigs = "0123456789ABCDEF";
707 xdigs = "0123456789abcdef";
708 hex: if (flags & QUADINT)
709 uqval = GETARG(u_quad_t);
713 /* leading 0x/X only if non-zero */
715 (flags & QUADINT ? uqval != 0 : ulval != 0))
718 /* unsigned conversions */
721 * ``... diouXx conversions ... if a precision is
722 * specified, the 0 flag will be ignored.''
725 number: if ((dprec = prec) >= 0)
729 * ``The result of converting a zero value with an
730 * explicit precision of zero is no characters.''
734 if (flags & QUADINT) {
735 if (uqval != 0 || prec != 0)
736 cp = __uqtoa(uqval, cp, base,
739 if (ulval != 0 || prec != 0)
740 cp = __ultoa(ulval, cp, base,
743 size = buf + BUF - cp;
745 default: /* "%?" prints ?, unless ? is NUL */
748 /* pretend it was %c with argument ch */
757 * All reasonable formats wind up here. At this point, `cp'
758 * points to a string which (if not flags&LADJUST) should be
759 * padded out to `width' places. If flags&ZEROPAD, it should
760 * first be prefixed by any sign or other prefix; otherwise,
761 * it should be blank padded before the prefix is emitted.
762 * After any left-hand padding and prefixing, emit zeroes
763 * required by a decimal [diouxX] precision, then print the
764 * string proper, then emit zeroes required by any leftover
765 * floating precision; finally, if LADJUST, pad with blanks.
767 * Compute actual size, so we know how much to pad.
768 * size excludes decimal prec; realsz includes it.
770 realsz = dprec > size ? dprec : size;
773 else if (flags & HEXPREFIX)
776 prsize = width > realsz ? width : realsz;
777 if ((unsigned)ret + prsize > INT_MAX) {
782 /* right-adjusting blank padding */
783 if ((flags & (LADJUST|ZEROPAD)) == 0)
784 PAD(width - realsz, blanks);
789 } else if (flags & HEXPREFIX) {
795 /* right-adjusting zero padding */
796 if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
797 PAD(width - realsz, zeroes);
799 /* leading zeroes from decimal precision */
800 PAD(dprec - size, zeroes);
802 /* the string or number proper */
803 #ifdef FLOATING_POINT
804 if ((flags & FPT) == 0) {
806 } else { /* glue together f_p fragments */
807 if (ch >= 'f') { /* 'f' or 'g' */
809 /* kludge for __dtoa irregularity */
811 if (expt < ndig || (flags & ALT) != 0) {
812 PRINT(decimal_point, 1);
813 PAD(ndig - 1, zeroes);
815 } else if (expt <= 0) {
817 PRINT(decimal_point, 1);
820 } else if (expt >= ndig) {
822 PAD(expt - ndig, zeroes);
824 PRINT(decimal_point, 1);
828 PRINT(decimal_point, 1);
829 PRINT(cp, ndig-expt);
831 } else { /* 'e' or 'E' */
832 if (ndig > 1 || flags & ALT) {
834 ox[1] = *decimal_point;
839 /* __dtoa irregularity */
840 PAD(ndig - 1, zeroes);
843 PRINT(expstr, expsize);
849 /* left-adjusting padding (always blank) */
851 PAD(width - realsz, blanks);
853 /* finally, adjust ret */
856 FLUSH(); /* copy out the I/O vectors */
861 #ifdef FLOATING_POINT
862 if (dtoaresult != NULL)
868 if ((argtable != NULL) && (argtable != statargtable))
875 * Type ids for argument type table.
891 #define T_LONG_DOUBLE 14
896 * Find all arguments when a positional parameter is encountered. Returns a
897 * table, indexed by argument number, of pointers to each arguments. The
898 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
899 * It will be replaces with a malloc-ed one if it overflows.
902 __find_arguments (const char *fmt0, va_list ap, void ***argtable)
904 char *fmt; /* format string */
905 int ch; /* character from fmt */
906 int n, n2; /* handy integer (short term usage) */
907 char *cp; /* handy char pointer (short term usage) */
908 int flags; /* flags as above */
909 int width; /* width from format (%8d), or 0 */
910 unsigned char *typetable; /* table of types */
911 unsigned char stattypetable [STATIC_ARG_TBL_SIZE];
912 int tablesize; /* current size of type table */
913 int tablemax; /* largest used index in table */
914 int nextarg; /* 1-based argument index */
917 * Add an argument type to the table, expanding if necessary.
919 #define ADDTYPE(type) \
920 ((nextarg >= tablesize) ? \
921 __grow_type_table(nextarg, &typetable, &tablesize) : 0, \
922 (nextarg > tablemax) ? tablemax = nextarg : 0, \
923 typetable[nextarg++] = type)
926 ((flags&LONGINT) ? ADDTYPE(T_LONG) : \
927 ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT)))
930 ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \
931 ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT)))
934 * Add * arguments to the type array.
939 while (is_digit(*cp)) { \
940 n2 = 10 * n2 + to_digit(*cp); \
944 int hold = nextarg; \
953 typetable = stattypetable;
954 tablesize = STATIC_ARG_TBL_SIZE;
957 memset (typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
960 * Scan the format for conversions (`%' character).
963 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
967 fmt++; /* skip over '%' */
973 reswitch: switch (ch) {
984 if ((ch = *fmt++) == '*') {
988 while (is_digit(ch)) {
994 case '1': case '2': case '3': case '4':
995 case '5': case '6': case '7': case '8': case '9':
998 n = 10 * n + to_digit(ch);
1000 } while (is_digit(ch));
1007 #ifdef FLOATING_POINT
1016 if (flags & LONGINT)
1032 if (flags & QUADINT) {
1038 #ifdef FLOATING_POINT
1044 if (flags & LONGDBL)
1045 ADDTYPE(T_LONG_DOUBLE);
1049 #endif /* FLOATING_POINT */
1051 if (flags & QUADINT)
1053 else if (flags & LONGINT)
1055 else if (flags & SHORTINT)
1059 continue; /* no output */
1064 if (flags & QUADINT)
1079 if (flags & QUADINT)
1086 if (flags & QUADINT)
1091 default: /* "%?" prints ?, unless ? is NUL */
1099 * Build the argument table.
1101 if (tablemax >= STATIC_ARG_TBL_SIZE) {
1102 *argtable = (void **)
1103 malloc (sizeof (void *) * (tablemax + 1));
1106 (*argtable) [0] = NULL;
1107 for (n = 1; n <= tablemax; n++) {
1108 switch (typetable [n]) {
1110 (*argtable) [n] = (void *) &va_arg (ap, int);
1113 (*argtable) [n] = (void *) &va_arg (ap, int);
1116 (*argtable) [n] = (void *) &va_arg (ap, int);
1119 (*argtable) [n] = (void *) &va_arg (ap, short *);
1122 (*argtable) [n] = (void *) &va_arg (ap, int);
1125 (*argtable) [n] = (void *) &va_arg (ap, unsigned int);
1128 (*argtable) [n] = (void *) &va_arg (ap, int *);
1131 (*argtable) [n] = (void *) &va_arg (ap, long);
1134 (*argtable) [n] = (void *) &va_arg (ap, unsigned long);
1137 (*argtable) [n] = (void *) &va_arg (ap, long *);
1140 (*argtable) [n] = (void *) &va_arg (ap, quad_t);
1143 (*argtable) [n] = (void *) &va_arg (ap, u_quad_t);
1146 (*argtable) [n] = (void *) &va_arg (ap, quad_t *);
1149 (*argtable) [n] = (void *) &va_arg (ap, double);
1152 (*argtable) [n] = (void *) &va_arg (ap, long double);
1155 (*argtable) [n] = (void *) &va_arg (ap, char *);
1158 (*argtable) [n] = (void *) &va_arg (ap, void *);
1163 if ((typetable != NULL) && (typetable != stattypetable))
1168 * Increase the size of the type table.
1171 __grow_type_table (int nextarg, unsigned char **typetable, int *tablesize)
1173 unsigned char *const oldtable = *typetable;
1174 const int oldsize = *tablesize;
1175 unsigned char *newtable;
1176 int newsize = oldsize * 2;
1178 if (newsize < nextarg + 1)
1179 newsize = nextarg + 1;
1180 if (oldsize == STATIC_ARG_TBL_SIZE) {
1181 if ((newtable = malloc(newsize)) == NULL)
1182 abort(); /* XXX handle better */
1183 bcopy(oldtable, newtable, oldsize);
1185 if ((newtable = reallocf(oldtable, newsize)) == NULL)
1186 abort(); /* XXX handle better */
1188 memset(&newtable[oldsize], T_UNUSED, newsize - oldsize);
1190 *typetable = newtable;
1191 *tablesize = newsize;
1195 #ifdef FLOATING_POINT
1197 extern char *__dtoa __P((double, int, int, int *, int *, char **, char **));
1200 cvt(double value, int ndigits, int flags, char *sign, int *decpt,
1201 int ch, int *length, char **dtoaresultp)
1204 char *digits, *bp, *rve;
1207 mode = 3; /* ndigits after the decimal point */
1210 * To obtain ndigits after the decimal point for the 'e'
1211 * and 'E' formats, round to ndigits + 1 significant
1214 if (ch == 'e' || ch == 'E')
1216 mode = 2; /* ndigits significant digits */
1218 digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve, dtoaresultp);
1220 if ((ch != 'g' && ch != 'G') || flags & ALT) {
1221 /* print trailing zeros */
1222 bp = digits + ndigits;
1224 if (*digits == '0' && value)
1225 *decpt = -ndigits + 1;
1228 if (value == 0) /* kludge for __dtoa irregularity */
1233 *length = rve - digits;
1238 exponent(char *p0, int exp, int fmtch)
1241 char expbuf[MAXEXP];
1251 t = expbuf + MAXEXP;
1254 *--t = to_char(exp % 10);
1255 } while ((exp /= 10) > 9);
1256 *--t = to_char(exp);
1257 for (; t < expbuf + MAXEXP; *p++ = *t++);
1261 *p++ = to_char(exp);
1265 #endif /* FLOATING_POINT */