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/libc/stdio/vfprintf.c,v 1.6 2005/01/31 22:29:40 dillon Exp $
42 * Actual printf innards.
44 * This code is large and complicated...
47 #include "namespace.h"
48 #include <sys/types.h>
56 #include "un-namespace.h"
58 #include "libc_private.h"
62 /* Define FLOATING_POINT to get floating point. */
63 #define FLOATING_POINT
65 static int __sprint (FILE *, struct __suio *);
66 static int __sbprintf (FILE *, const char *, va_list);
67 static char * __ultoa (u_long, char *, int, int, char *);
68 static char * __uqtoa (u_quad_t, char *, int, int, char *);
69 static void __find_arguments (const char *, va_list, void ***);
70 static void __grow_type_table (int, unsigned char **, int *);
73 * Flush out all the vectors defined by the given uio,
74 * then reset it so that it can be reused.
77 __sprint(FILE *fp, struct __suio *uio)
81 if (uio->uio_resid == 0) {
85 err = __sfvwrite(fp, uio);
92 * Helper function for `fprintf to unbuffered unix file': creates a
93 * temporary buffer. We only work on write-only files; this avoids
94 * worries about ungetc buffers and so forth.
97 __sbprintf(FILE *fp, const char *fmt, va_list ap)
101 unsigned char buf[BUFSIZ];
103 /* copy the important variables */
104 fake._flags = fp->_flags & ~__SNBF;
105 fake._file = fp->_file;
106 fake._cookie = fp->_cookie;
107 fake._write = fp->_write;
109 /* set up the buffer */
110 fake._bf._base = fake._p = buf;
111 fake._bf._size = fake._w = sizeof(buf);
112 fake._lbfsize = 0; /* not actually used, but Just In Case */
114 /* do the work, then copy any error status */
115 ret = __vfprintf(&fake, fmt, ap);
116 if (ret >= 0 && __fflush(&fake))
118 if (fake._flags & __SERR)
119 fp->_flags |= __SERR;
124 * Macros for converting digits to letters and vice versa
126 #define to_digit(c) ((c) - '0')
127 #define is_digit(c) ((unsigned)to_digit(c) <= 9)
128 #define to_char(n) ((n) + '0')
131 * Convert an unsigned long to ASCII for printf purposes, returning
132 * a pointer to the first character of the string representation.
133 * Octal numbers can be forced to have a leading zero; hex numbers
134 * use the given digits.
137 __ultoa(u_long val, char *endp, int base, int octzero, char *xdigs)
143 * Handle the three cases separately, in the hope of getting
144 * better/faster code.
148 if (val < 10) { /* many numbers are 1 digit */
149 *--cp = to_char(val);
153 * On many machines, unsigned arithmetic is harder than
154 * signed arithmetic, so we do at most one unsigned mod and
155 * divide; this is sufficient to reduce the range of
156 * the incoming value to where signed arithmetic works.
158 if (val > LONG_MAX) {
159 *--cp = to_char(val % 10);
164 *--cp = to_char(sval % 10);
171 *--cp = to_char(val & 7);
174 if (octzero && *cp != '0')
180 *--cp = xdigs[val & 15];
191 /* Identical to __ultoa, but for quads. */
193 __uqtoa(u_quad_t val, char *endp, int base, int octzero, char *xdigs)
198 /* quick test for small values; __ultoa is typically much faster */
199 /* (perhaps instead we should run until small, then call __ultoa?) */
200 if (val <= ULONG_MAX)
201 return (__ultoa((u_long)val, endp, base, octzero, xdigs));
205 *--cp = to_char(val % 10);
208 if (val > QUAD_MAX) {
209 *--cp = to_char(val % 10);
214 *--cp = to_char(sval % 10);
221 *--cp = to_char(val & 7);
224 if (octzero && *cp != '0')
230 *--cp = xdigs[val & 15];
245 vfprintf(FILE *fp, const char *fmt0, va_list ap)
250 ret = __vfprintf(fp, fmt0, ap);
255 #ifdef FLOATING_POINT
260 #define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */
263 static char *cvt (double, int, int, char *, int *, int, int *, char **);
264 static int exponent (char *, int, int);
266 #else /* no FLOATING_POINT */
270 #endif /* FLOATING_POINT */
272 #define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */
275 * Flags used during conversion.
277 #define ALT 0x001 /* alternate form */
278 #define HEXPREFIX 0x002 /* add 0x or 0X prefix */
279 #define LADJUST 0x004 /* left adjustment */
280 #define LONGDBL 0x008 /* long double */
281 #define LONGINT 0x010 /* long integer */
282 #define QUADINT 0x020 /* quad integer */
283 #define SHORTINT 0x040 /* short integer */
284 #define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
285 #define FPT 0x100 /* Floating point number */
287 * Non-MT-safe version
290 __vfprintf(FILE *fp, const char *fmt0, va_list ap)
292 char *fmt; /* format string */
293 int ch; /* character from fmt */
294 int n, n2; /* handy integer (short term usage) */
295 char *cp; /* handy char pointer (short term usage) */
296 struct __siov *iovp; /* for PRINT macro */
297 int flags; /* flags as above */
298 int ret; /* return value accumulator */
299 int width; /* width from format (%8d), or 0 */
300 int prec; /* precision from format (%.3d), or -1 */
301 char sign; /* sign prefix (' ', '+', '-', or \0) */
302 #ifdef FLOATING_POINT
303 char *decimal_point = localeconv()->decimal_point;
304 char softsign; /* temporary negative sign for floats */
305 double _double; /* double precision arguments %[eEfgG] */
306 int expt; /* integer value of exponent */
307 int expsize; /* character count for expstr */
308 int ndig; /* actual number of digits returned by cvt */
309 char expstr[7]; /* buffer for exponent string */
310 char *dtoaresult; /* buffer allocated by dtoa */
312 u_long ulval; /* integer arguments %[diouxX] */
313 u_quad_t uqval; /* %q integers */
314 int base; /* base for [diouxX] conversion */
315 int dprec; /* a copy of prec if [diouxX], 0 otherwise */
316 int realsz; /* field size expanded by dprec, sign, etc */
317 int size; /* size of converted field or string */
318 int prsize; /* max size of printed field */
319 char *xdigs; /* digits for [xX] conversion */
321 struct __suio uio; /* output information: summary */
322 struct __siov iov[NIOV];/* ... and individual io vectors */
323 char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
324 char ox[2]; /* space for 0x hex-prefix */
325 void **argtable; /* args, built due to positional arg */
326 void *statargtable [STATIC_ARG_TBL_SIZE];
327 int nextarg; /* 1-based argument index */
328 va_list orgap; /* original argument pointer */
331 * Choose PADSIZE to trade efficiency vs. size. If larger printf
332 * fields occur frequently, increase PADSIZE and make the initialisers
335 #define PADSIZE 16 /* pad chunk size */
336 static char blanks[PADSIZE] =
337 {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
338 static char zeroes[PADSIZE] =
339 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
342 * BEWARE, these `goto error' on error, and PAD uses `n'.
344 #define PRINT(ptr, len) { \
345 iovp->iov_base = (ptr); \
346 iovp->iov_len = (len); \
347 uio.uio_resid += (len); \
349 if (++uio.uio_iovcnt >= NIOV) { \
350 if (__sprint(fp, &uio)) \
355 #define PAD(howmany, with) { \
356 if ((n = (howmany)) > 0) { \
357 while (n > PADSIZE) { \
358 PRINT(with, PADSIZE); \
365 if (uio.uio_resid && __sprint(fp, &uio)) \
367 uio.uio_iovcnt = 0; \
372 * Get the argument indexed by nextarg. If the argument table is
373 * built, use it to get the argument. If its not, get the next
374 * argument (and arguments must be gotten sequentially).
376 #define GETARG(type) \
377 ((argtable != NULL) ? *((type*)(argtable[nextarg++])) : \
378 (nextarg++, va_arg(ap, type)))
381 * To extend shorts properly, we need both signed and unsigned
382 * argument extraction methods.
385 (flags&LONGINT ? GETARG(long) : \
386 flags&SHORTINT ? (long)(short)GETARG(int) : \
389 (flags&LONGINT ? GETARG(u_long) : \
390 flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
391 (u_long)GETARG(u_int))
394 * Get * arguments, including the form *nn$. Preserve the nextarg
395 * that the argument can be gotten once the type is determined.
397 #define GETASTER(val) \
400 while (is_digit(*cp)) { \
401 n2 = 10 * n2 + to_digit(*cp); \
405 int hold = nextarg; \
406 if (argtable == NULL) { \
407 argtable = statargtable; \
408 __find_arguments (fmt0, orgap, &argtable); \
411 val = GETARG (int); \
415 val = GETARG (int); \
419 #ifdef FLOATING_POINT
422 /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
427 /* optimise fprintf(stderr) (and other unbuffered Unix files) */
428 if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
430 return (__sbprintf(fp, fmt0, ap));
437 uio.uio_iov = iovp = iov;
443 * Scan the format for conversions (`%' character).
446 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
448 if ((n = fmt - cp) != 0) {
449 if ((unsigned)ret + n > INT_MAX) {
458 fmt++; /* skip over '%' */
467 reswitch: switch (ch) {
470 * ``If the space and + flags both appear, the space
471 * flag will be ignored.''
482 * ``A negative field width argument is taken as a
483 * - flag followed by a positive field width.''
485 * They don't exclude field widths read from args.
499 if ((ch = *fmt++) == '*') {
501 prec = n < 0 ? -1 : n;
505 while (is_digit(ch)) {
506 n = 10 * n + to_digit(ch);
509 prec = n < 0 ? -1 : n;
513 * ``Note that 0 is taken as a flag, not as the
514 * beginning of a field width.''
519 case '1': case '2': case '3': case '4':
520 case '5': case '6': case '7': case '8': case '9':
523 n = 10 * n + to_digit(ch);
525 } while (is_digit(ch));
528 if (argtable == NULL) {
529 argtable = statargtable;
530 __find_arguments (fmt0, orgap,
537 #ifdef FLOATING_POINT
555 *(cp = buf) = GETARG(int);
564 if (flags & QUADINT) {
565 uqval = GETARG(quad_t);
566 if ((quad_t)uqval < 0) {
572 if ((long)ulval < 0) {
579 #ifdef FLOATING_POINT
588 fp_begin: if (prec == -1)
591 /* XXX this loses precision. */
592 _double = (double)GETARG(long double);
594 _double = GETARG(double);
595 /* do this before tricky precision changes */
596 if (isinf(_double)) {
603 if (isnan(_double)) {
609 if (dtoaresult != NULL) {
613 cp = cvt(_double, prec, flags, &softsign,
614 &expt, ch, &ndig, &dtoaresult);
615 if (ch == 'g' || ch == 'G') {
616 if (expt <= -4 || expt > prec)
617 ch = (ch == 'g') ? 'e' : 'E';
621 if (ch <= 'e') { /* 'e' or 'E' fmt */
623 expsize = exponent(expstr, expt, ch);
624 size = expsize + ndig;
625 if (ndig > 1 || flags & ALT)
627 } else if (ch == 'f') { /* f fmt */
630 if (prec || flags & ALT)
634 } else if (expt >= ndig) { /* fixed g fmt */
639 size = ndig + (expt > 0 ?
645 #endif /* FLOATING_POINT */
648 *GETARG(quad_t *) = ret;
649 else if (flags & LONGINT)
650 *GETARG(long *) = ret;
651 else if (flags & SHORTINT)
652 *GETARG(short *) = ret;
654 *GETARG(int *) = ret;
655 continue; /* no output */
661 uqval = GETARG(u_quad_t);
668 * ``The argument shall be a pointer to void. The
669 * value of the pointer is converted to a sequence
670 * of printable characters, in an implementation-
674 ulval = (u_long)GETARG(void *);
676 xdigs = "0123456789abcdef";
677 flags = (flags & ~QUADINT) | HEXPREFIX;
681 if ((cp = GETARG(char *)) == NULL)
685 * can't use strlen; can only look for the
686 * NUL in the first `prec' characters, and
687 * strlen() will go further.
689 char *p = memchr(cp, 0, (size_t)prec);
706 uqval = GETARG(u_quad_t);
712 xdigs = "0123456789ABCDEF";
715 xdigs = "0123456789abcdef";
716 hex: if (flags & QUADINT)
717 uqval = GETARG(u_quad_t);
721 /* leading 0x/X only if non-zero */
723 (flags & QUADINT ? uqval != 0 : ulval != 0))
726 /* unsigned conversions */
729 * ``... diouXx conversions ... if a precision is
730 * specified, the 0 flag will be ignored.''
733 number: if ((dprec = prec) >= 0)
737 * ``The result of converting a zero value with an
738 * explicit precision of zero is no characters.''
742 if (flags & QUADINT) {
743 if (uqval != 0 || prec != 0)
744 cp = __uqtoa(uqval, cp, base,
747 if (ulval != 0 || prec != 0)
748 cp = __ultoa(ulval, cp, base,
751 size = buf + BUF - cp;
753 default: /* "%?" prints ?, unless ? is NUL */
756 /* pretend it was %c with argument ch */
765 * All reasonable formats wind up here. At this point, `cp'
766 * points to a string which (if not flags&LADJUST) should be
767 * padded out to `width' places. If flags&ZEROPAD, it should
768 * first be prefixed by any sign or other prefix; otherwise,
769 * it should be blank padded before the prefix is emitted.
770 * After any left-hand padding and prefixing, emit zeroes
771 * required by a decimal [diouxX] precision, then print the
772 * string proper, then emit zeroes required by any leftover
773 * floating precision; finally, if LADJUST, pad with blanks.
775 * Compute actual size, so we know how much to pad.
776 * size excludes decimal prec; realsz includes it.
778 realsz = dprec > size ? dprec : size;
781 else if (flags & HEXPREFIX)
784 prsize = width > realsz ? width : realsz;
785 if ((unsigned)ret + prsize > INT_MAX) {
790 /* right-adjusting blank padding */
791 if ((flags & (LADJUST|ZEROPAD)) == 0)
792 PAD(width - realsz, blanks);
797 } else if (flags & HEXPREFIX) {
803 /* right-adjusting zero padding */
804 if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
805 PAD(width - realsz, zeroes);
807 /* leading zeroes from decimal precision */
808 PAD(dprec - size, zeroes);
810 /* the string or number proper */
811 #ifdef FLOATING_POINT
812 if ((flags & FPT) == 0) {
814 } else { /* glue together f_p fragments */
815 if (ch >= 'f') { /* 'f' or 'g' */
817 /* kludge for __dtoa irregularity */
819 if (expt < ndig || (flags & ALT) != 0) {
820 PRINT(decimal_point, 1);
821 PAD(ndig - 1, zeroes);
823 } else if (expt <= 0) {
825 PRINT(decimal_point, 1);
828 } else if (expt >= ndig) {
830 PAD(expt - ndig, zeroes);
832 PRINT(decimal_point, 1);
836 PRINT(decimal_point, 1);
837 PRINT(cp, ndig-expt);
839 } else { /* 'e' or 'E' */
840 if (ndig > 1 || flags & ALT) {
842 ox[1] = *decimal_point;
847 /* __dtoa irregularity */
848 PAD(ndig - 1, zeroes);
851 PRINT(expstr, expsize);
857 /* left-adjusting padding (always blank) */
859 PAD(width - realsz, blanks);
861 /* finally, adjust ret */
864 FLUSH(); /* copy out the I/O vectors */
869 #ifdef FLOATING_POINT
870 if (dtoaresult != NULL)
875 if ((argtable != NULL) && (argtable != statargtable))
882 * Type ids for argument type table.
898 #define T_LONG_DOUBLE 14
903 * Find all arguments when a positional parameter is encountered. Returns a
904 * table, indexed by argument number, of pointers to each arguments. The
905 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
906 * It will be replaces with a malloc-ed one if it overflows.
909 __find_arguments (const char *fmt0, va_list ap, void ***argtable)
911 char *fmt; /* format string */
912 int ch; /* character from fmt */
913 int n, n2; /* handy integer (short term usage) */
914 char *cp; /* handy char pointer (short term usage) */
915 int flags; /* flags as above */
916 int width; /* width from format (%8d), or 0 */
917 unsigned char *typetable; /* table of types */
918 unsigned char stattypetable [STATIC_ARG_TBL_SIZE];
919 int tablesize; /* current size of type table */
920 int tablemax; /* largest used index in table */
921 int nextarg; /* 1-based argument index */
924 * Add an argument type to the table, expanding if necessary.
926 #define ADDTYPE(type) \
927 ((nextarg >= tablesize) ? \
928 __grow_type_table(nextarg, &typetable, &tablesize) : 0, \
929 (nextarg > tablemax) ? tablemax = nextarg : 0, \
930 typetable[nextarg++] = type)
933 ((flags&LONGINT) ? ADDTYPE(T_LONG) : \
934 ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT)))
937 ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \
938 ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT)))
941 * Add * arguments to the type array.
946 while (is_digit(*cp)) { \
947 n2 = 10 * n2 + to_digit(*cp); \
951 int hold = nextarg; \
960 typetable = stattypetable;
961 tablesize = STATIC_ARG_TBL_SIZE;
964 memset (typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
967 * Scan the format for conversions (`%' character).
970 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
974 fmt++; /* skip over '%' */
980 reswitch: switch (ch) {
991 if ((ch = *fmt++) == '*') {
995 while (is_digit(ch)) {
1001 case '1': case '2': case '3': case '4':
1002 case '5': case '6': case '7': case '8': case '9':
1005 n = 10 * n + to_digit(ch);
1007 } while (is_digit(ch));
1014 #ifdef FLOATING_POINT
1023 if (flags & LONGINT)
1039 if (flags & QUADINT) {
1045 #ifdef FLOATING_POINT
1051 if (flags & LONGDBL)
1052 ADDTYPE(T_LONG_DOUBLE);
1056 #endif /* FLOATING_POINT */
1058 if (flags & QUADINT)
1060 else if (flags & LONGINT)
1062 else if (flags & SHORTINT)
1066 continue; /* no output */
1071 if (flags & QUADINT)
1086 if (flags & QUADINT)
1093 if (flags & QUADINT)
1098 default: /* "%?" prints ?, unless ? is NUL */
1106 * Build the argument table.
1108 if (tablemax >= STATIC_ARG_TBL_SIZE) {
1109 *argtable = (void **)
1110 malloc (sizeof (void *) * (tablemax + 1));
1113 (*argtable) [0] = NULL;
1114 for (n = 1; n <= tablemax; n++) {
1115 switch (typetable [n]) {
1117 (*argtable) [n] = (void *) &va_arg (ap, int);
1120 (*argtable) [n] = (void *) &va_arg (ap, int);
1123 (*argtable) [n] = (void *) &va_arg (ap, int);
1126 (*argtable) [n] = (void *) &va_arg (ap, short *);
1129 (*argtable) [n] = (void *) &va_arg (ap, int);
1132 (*argtable) [n] = (void *) &va_arg (ap, unsigned int);
1135 (*argtable) [n] = (void *) &va_arg (ap, int *);
1138 (*argtable) [n] = (void *) &va_arg (ap, long);
1141 (*argtable) [n] = (void *) &va_arg (ap, unsigned long);
1144 (*argtable) [n] = (void *) &va_arg (ap, long *);
1147 (*argtable) [n] = (void *) &va_arg (ap, quad_t);
1150 (*argtable) [n] = (void *) &va_arg (ap, u_quad_t);
1153 (*argtable) [n] = (void *) &va_arg (ap, quad_t *);
1156 (*argtable) [n] = (void *) &va_arg (ap, double);
1159 (*argtable) [n] = (void *) &va_arg (ap, long double);
1162 (*argtable) [n] = (void *) &va_arg (ap, char *);
1165 (*argtable) [n] = (void *) &va_arg (ap, void *);
1170 if ((typetable != NULL) && (typetable != stattypetable))
1175 * Increase the size of the type table.
1178 __grow_type_table (int nextarg, unsigned char **typetable, int *tablesize)
1180 unsigned char *const oldtable = *typetable;
1181 const int oldsize = *tablesize;
1182 unsigned char *newtable;
1183 int newsize = oldsize * 2;
1185 if (newsize < nextarg + 1)
1186 newsize = nextarg + 1;
1187 if (oldsize == STATIC_ARG_TBL_SIZE) {
1188 if ((newtable = malloc(newsize)) == NULL)
1189 abort(); /* XXX handle better */
1190 bcopy(oldtable, newtable, oldsize);
1192 if ((newtable = reallocf(oldtable, newsize)) == NULL)
1193 abort(); /* XXX handle better */
1195 memset(&newtable[oldsize], T_UNUSED, newsize - oldsize);
1197 *typetable = newtable;
1198 *tablesize = newsize;
1202 #ifdef FLOATING_POINT
1204 extern char *__dtoa (double, int, int, int *, int *, char **, char **);
1207 cvt(double value, int ndigits, int flags, char *sign, int *decpt,
1208 int ch, int *length, char **dtoaresultp)
1211 char *digits, *bp, *rve;
1214 mode = 3; /* ndigits after the decimal point */
1217 * To obtain ndigits after the decimal point for the 'e'
1218 * and 'E' formats, round to ndigits + 1 significant
1221 if (ch == 'e' || ch == 'E')
1223 mode = 2; /* ndigits significant digits */
1225 digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve, dtoaresultp);
1227 if ((ch != 'g' && ch != 'G') || flags & ALT) {
1228 /* print trailing zeros */
1229 bp = digits + ndigits;
1231 if (*digits == '0' && value)
1232 *decpt = -ndigits + 1;
1235 if (value == 0) /* kludge for __dtoa irregularity */
1240 *length = rve - digits;
1245 exponent(char *p0, int exp, int fmtch)
1248 char expbuf[MAXEXP];
1258 t = expbuf + MAXEXP;
1261 *--t = to_char(exp % 10);
1262 } while ((exp /= 10) > 9);
1263 *--t = to_char(exp);
1264 for (; t < expbuf + MAXEXP; *p++ = *t++);
1268 *p++ = to_char(exp);
1272 #endif /* FLOATING_POINT */