2 build a test version with
3 gcc -g -DDRIVER -I../.. -I../../include -o test-snprintf snprintf.c fmtu*long.o
7 Unix snprintf implementation.
8 derived from inetutils/libinetutils/snprintf.c Version 1.1
10 Copyright (C) 2001 Free Software Foundation, Inc.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General License for more details.
22 You should have received a copy of the GNU General License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 * added changes from Miles Bader
30 * corrected a bug with %f
31 * added support for %#g
32 * added more comments :-)
34 * supporting must ANSI syntaxic_sugars
38 THANKS(for the patches and ideas):
47 * Currently doesn't handle (and bash/readline doesn't use):
48 * * *M$ width, precision specifications
49 * * %N$ numbered argument conversions
50 * * inf, nan floating values imperfect (if isinf(), isnan() not in libc)
51 * * support for `F' is imperfect with ldfallback(), since underlying
52 * printf may not handle it -- should ideally have another autoconf test
55 #define FLOATING_POINT
61 #if defined(DRIVER) && !defined(HAVE_CONFIG_H)
62 #define HAVE_LONG_LONG
63 #define HAVE_LONG_DOUBLE
65 #define HAVE_PRINTF_A_FORMAT
67 #define HAVE_ISINF_IN_LIBC
68 #define HAVE_ISNAN_IN_LIBC
70 #define HAVE_STRINGIZE
77 #if !defined (HAVE_SNPRINTF) || !defined (HAVE_ASPRINTF)
79 #include <bashtypes.h>
81 #if defined(PREFER_STDARG)
94 #include <chartypes.h>
100 #ifdef FLOATING_POINT
101 # include <float.h> /* for manifest constants */
102 # include <stdio.h> /* for sprintf */
112 #include <shmbutil.h>
117 # define FL_PREFIX 0x01 /* add 0x, 0X, or 0 prefix as appropriate */
118 # define FL_ADDBASE 0x02 /* add base# prefix to converted value */
119 # define FL_HEXUPPER 0x04 /* use uppercase when converting to hex */
120 # define FL_UNSIGNED 0x08 /* don't add any sign */
121 extern char *fmtulong __P((unsigned long int, int, char *, size_t, int));
122 extern char *fmtullong __P((unsigned long long int, int, char *, size_t, int));
126 # define FREE(x) if (x) free (x)
129 /* Bound on length of the string representing an integer value of type T.
130 Subtract one for the sign bit if T is signed;
131 302 / 1000 is log10 (2) rounded up;
132 add one for integer division truncation;
133 add one more for a minus sign if t is signed. */
134 #define INT_STRLEN_BOUND(t) \
135 ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \
136 + 1 + TYPE_SIGNED (t))
138 /* conversion flags */
139 #define PF_ALTFORM 0x00001 /* # */
140 #define PF_HEXPREFIX 0x00002 /* 0[Xx] */
141 #define PF_LADJUST 0x00004 /* - */
142 #define PF_ZEROPAD 0x00008 /* 0 */
143 #define PF_PLUS 0x00010 /* + */
144 #define PF_SPACE 0x00020 /* ' ' */
145 #define PF_THOUSANDS 0x00040 /* ' */
147 #define PF_DOT 0x00080 /* `.precision' */
148 #define PF_STAR_P 0x00100 /* `*' after precision */
149 #define PF_STAR_W 0x00200 /* `*' before or without precision */
151 /* length modifiers */
152 #define PF_SIGNEDCHAR 0x00400 /* hh */
153 #define PF_SHORTINT 0x00800 /* h */
154 #define PF_LONGINT 0x01000 /* l */
155 #define PF_LONGLONG 0x02000 /* ll */
156 #define PF_LONGDBL 0x04000 /* L */
157 #define PF_INTMAX_T 0x08000 /* j */
158 #define PF_SIZE_T 0x10000 /* z */
159 #define PF_PTRDIFF_T 0x20000 /* t */
161 #define PF_ALLOCBUF 0x40000 /* for asprintf, vasprintf */
163 #define PFM_SN 0x01 /* snprintf, vsnprintf */
164 #define PFM_AS 0x02 /* asprintf, vasprintf */
166 #define ASBUFSIZE 128
168 #define x_digs "0123456789abcdef"
169 #define X_digs "0123456789ABCDEF"
171 static char intbuf[INT_STRLEN_BOUND(unsigned long) + 1];
175 static char *grouping;
178 * For the FLOATING POINT FORMAT :
179 * the challenge was finding a way to
180 * manipulate the Real numbers without having
181 * to resort to mathematical function(it
182 * would require to link with -lm) and not
183 * going down to the bit pattern(not portable)
185 * so a number, a real is:
187 real = integral + fraction
189 integral = ... + a(2)*10^2 + a(1)*10^1 + a(0)*10^0
190 fraction = b(1)*10^-1 + b(2)*10^-2 + ...
196 from then it was simple math
200 * size of the buffer for the integral part
201 * and the fraction part
203 #define MAX_INT 99 + 1 /* 1 for the null */
204 #define MAX_FRACT 307 + 1
207 * These functions use static buffers to store the results,
208 * and so are not reentrant
210 #define itoa(n) fmtulong(n, 10, intbuf, sizeof(intbuf), 0);
211 #define dtoa(n, p, f) numtoa(n, 10, p, f)
213 #define SWAP_INT(a,b) {int t; t = (a); (a) = (b); (b) = t;}
215 #define GETARG(type) (va_arg(args, type))
217 /* Macros that do proper sign extension and handle length modifiers. Used
218 for the integer conversion specifiers. */
219 #define GETSIGNED(p) \
220 (((p)->flags & PF_LONGINT) \
222 : (((p)->flags & PF_SHORTINT) ? (long)(short)GETARG (int) \
223 : (long)GETARG (int)))
225 #define GETUNSIGNED(p) \
226 (((p)->flags & PF_LONGINT) \
227 ? GETARG (unsigned long) \
228 : (((p)->flags & PF_SHORTINT) ? (unsigned long)(unsigned short)GETARG (int) \
229 : (unsigned long)GETARG (unsigned int)))
232 #ifdef HAVE_LONG_DOUBLE
233 #define GETLDOUBLE(p) GETARG (long double)
235 #define GETDOUBLE(p) GETARG (double)
237 #define SET_SIZE_FLAGS(p, type) \
238 if (sizeof (type) > sizeof (int)) \
239 (p)->flags |= PF_LONGINT; \
240 if (sizeof (type) > sizeof (long)) \
241 (p)->flags |= PF_LONGLONG;
243 /* this struct holds everything we need */
247 char *base; /* needed for [v]asprintf */
255 int width, precision;
259 /* the floating point stuff */
260 #ifdef FLOATING_POINT
261 static double pow_10 __P((int));
262 static int log_10 __P((double));
263 static double integral __P((double, double *));
264 static char *numtoa __P((double, int, int, char **));
267 static void init_data __P((struct DATA *, char *, size_t, const char *, int));
268 static void init_conv_flag __P((struct DATA *));
271 #ifdef FLOATING_POINT
272 static void floating __P((struct DATA *, double));
273 static void exponent __P((struct DATA *, double));
275 static void number __P((struct DATA *, unsigned long, int));
276 #ifdef HAVE_LONG_LONG
277 static void lnumber __P((struct DATA *, unsigned long long, int));
279 static void pointer __P((struct DATA *, unsigned long));
280 static void strings __P((struct DATA *, char *));
282 #ifdef FLOATING_POINT
283 # define FALLBACK_FMTSIZE 32
284 # define FALLBACK_BASE 4096
285 # define LFALLBACK_BASE 5120
286 # ifdef HAVE_LONG_DOUBLE
287 static void ldfallback __P((struct DATA *, const char *, const char *, long double));
289 static void dfallback __P((struct DATA *, const char *, const char *, double));
292 static char *groupnum __P((char *));
295 static void memory_error_and_abort ();
296 static void *xmalloc __P((size_t));
297 static void *xrealloc __P((void *, size_t));
298 static void xfree __P((void *));
300 # include <xmalloc.h>
303 /* those are defines specific to snprintf to hopefully
304 * make the code clearer :-)
312 /* round off to the precision */
313 #define ROUND(d, p) \
315 d - pow_10(-(p)->precision) * 0.5 : \
316 d + pow_10(-(p)->precision) * 0.5
318 /* set default precision */
319 #define DEF_PREC(p) \
320 if ((p)->precision == NOT_FOUND) \
323 /* put a char. increment the number of chars written even if we've exceeded
324 the vsnprintf/snprintf buffer size (for the return value) */
325 #define PUT_CHAR(c, p) \
328 if (((p)->flags & PF_ALLOCBUF) && ((p)->counter >= (p)->length - 1)) \
330 (p)->length += ASBUFSIZE; \
331 (p)->base = (char *)xrealloc((p)->base, (p)->length); \
332 (p)->holder = (p)->base + (p)->counter; /* in case reallocated */ \
334 if ((p)->counter < (p)->length) \
335 *(p)->holder++ = (c); \
340 /* Output a string. P->WIDTH has already been adjusted for padding. */
341 #define PUT_STRING(string, len, p) \
345 while ((len)-- > 0) \
347 PUT_CHAR (*(string), (p)); \
354 #define PUT_PLUS(d, p, zero) \
355 if ((d) > zero && (p)->justify == RIGHT) \
358 #define PUT_SPACE(d, p, zero) \
359 if (((p)->flags & PF_SPACE) && (d) > zero) \
363 #define PAD_RIGHT(p) \
364 if ((p)->width > 0 && (p)->justify != LEFT) \
365 for (; (p)->width > 0; (p)->width--) \
366 PUT_CHAR((p)->pad, p)
369 #define PAD_LEFT(p) \
370 if ((p)->width > 0 && (p)->justify == LEFT) \
371 for (; (p)->width > 0; (p)->width--) \
372 PUT_CHAR((p)->pad, p)
374 /* pad with zeros from decimal precision */
375 #define PAD_ZERO(p) \
376 if ((p)->precision > 0) \
377 for (; (p)->precision > 0; (p)->precision--) \
380 /* if width and prec. in the args */
381 #define STAR_ARGS(p) \
383 if ((p)->flags & PF_STAR_W) \
385 (p)->width = GETARG (int); \
386 if ((p)->width < 0) \
388 (p)->flags |= PF_LADJUST; \
389 (p)->justify = LEFT; \
390 (p)->width = -(p)->width; \
393 if ((p)->flags & PF_STAR_P) \
395 (p)->precision = GETARG (int); \
396 if ((p)->precision < 0) \
398 (p)->flags &= ~PF_STAR_P; \
399 (p)->precision = NOT_FOUND; \
404 #if defined (HAVE_LOCALE_H)
405 # define GETLOCALEDATA(d, t, g) \
410 (d) = '.'; (t) = -1; (g) = 0; /* defaults */ \
414 if (lv->decimal_point && lv->decimal_point[0]) \
415 (d) = lv->decimal_point[0]; \
416 if (lv->thousands_sep && lv->thousands_sep[0]) \
417 (t) = lv->thousands_sep[0]; \
418 (g) = lv->grouping ? lv->grouping : ""; \
419 if (*(g) == '\0' || *(g) == CHAR_MAX || (t) == -1) (g) = 0; \
425 # define GETLOCALEDATA(d, t, g) \
426 ( (d) = '.', (t) = ',', g = "\003" )
429 #ifdef FLOATING_POINT
431 * Find the nth power of 10
439 /* handle common cases with fast switch statement. */
442 case -3: return .001;
448 case 3: return 1000.;
454 for (n += 4; n < 0; n++)
460 for (n -= 4; n > 0; n--)
468 * Find the integral part of the log in base 10
469 * Note: this not a real log10()
470 I just need and approximation(integerpart) of x in:
506 * This function return the fraction part of a double
507 * and set in ip the integral part.
508 * In many ways it resemble the modf() found on most Un*x
517 double real_integral = 0.;
519 /* take care of the obvious */
520 /* equal to zero ? */
527 /* negative number ? */
538 /* the real work :-) */
539 for (j = log_10(real); j >= 0; j--)
542 s = (real - real_integral)/p;
546 real_integral += i*p;
549 return (real - real_integral);
552 #define PRECISION 1.e-6
554 * return an ascii representation of the integral part of the number
555 * and set fract to be an ascii representation of the fraction part
556 * the container for the fraction and the integral part or staticly
557 * declare with fix size
560 numtoa(number, base, precision, fract)
566 double ip, fp; /* integer and fraction part */
568 int digits = MAX_INT - 1;
569 static char integral_part[MAX_INT];
570 static char fraction_part[MAX_FRACT];
574 /* taking care of the obvious case: 0.0 */
577 integral_part[0] = '0';
578 integral_part[1] = '\0';
579 fraction_part[0] = '0';
580 fraction_part[1] = '\0';
582 *fract = fraction_part;
583 return integral_part;
586 /* for negative numbers */
587 if ((sign = number) < 0.)
590 digits--; /* sign consume one digit */
593 fraction = integral(number, &ip);
596 /* do the integral part */
599 integral_part[0] = '0';
604 for ( i = 0; i < digits && number != 0.; ++i)
607 fp = integral(number, &ip);
608 ch = (int)((fp + PRECISION)*base); /* force to round */
609 integral_part[i] = (ch <= 9) ? ch + '0' : ch + 'a' - 10;
610 if (! ISXDIGIT((unsigned char)integral_part[i]))
611 break; /* bail out overflow !! */
616 /* Oh No !! out of bound, ho well fill it up ! */
618 for (i = 0; i < digits; ++i)
619 integral_part[i] = '9';
623 integral_part[i++] = '-';
625 integral_part[i] = '\0';
627 /* reverse every thing */
628 for ( i--, j = 0; j < i; j++, i--)
629 SWAP_INT(integral_part[i], integral_part[j]);
631 /* the fractional part */
632 for (i=0, fp=fraction; precision > 0 && i < MAX_FRACT ; i++, precision--)
634 fraction_part[i] = (int)((fp + PRECISION)*10. + '0');
635 if (! DIGIT(fraction_part[i])) /* underflow ? */
637 fp = (fp*10.0) - (double)(long)((fp + PRECISION)*10.);
639 fraction_part[i] = '\0';
641 if (fract != (char **)0)
642 *fract = fraction_part;
644 return integral_part;
648 /* for %d and friends, it puts in holder
649 * the representation with the right padding
661 /* An explicit precision turns off the zero-padding flag. */
662 if ((p->flags & PF_ZEROPAD) && p->precision >= 0 && (p->flags & PF_DOT))
663 p->flags &= ~PF_ZEROPAD;
665 sd = d; /* signed for ' ' padding in base 10 */
666 flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0;
668 flags |= FL_HEXUPPER;
670 tmp = fmtulong (d, base, intbuf, sizeof(intbuf), flags);
672 if ((p->flags & PF_THOUSANDS))
674 GETLOCALEDATA(decpoint, thoussep, grouping);
675 if (grouping && (t = groupnum (tmp)))
679 p->width -= strlen(tmp);
682 if ((p->flags & PF_DOT) && p->precision > 0)
684 p->precision -= strlen(tmp);
695 if (p->flags & PF_ALTFORM)
699 if (p->flags & PF_ALTFORM)
717 #ifdef HAVE_LONG_LONG
719 * identical to number() but works for `long long'
724 unsigned long long d;
731 /* An explicit precision turns off the zero-padding flag. */
732 if ((p->flags & PF_ZEROPAD) && p->precision >= 0 && (p->flags & PF_DOT))
733 p->flags &= ~PF_ZEROPAD;
735 sd = d; /* signed for ' ' padding in base 10 */
736 flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0;
738 flags |= FL_HEXUPPER;
740 tmp = fmtullong (d, base, intbuf, sizeof(intbuf), flags);
742 if ((p->flags & PF_THOUSANDS))
744 GETLOCALEDATA(decpoint, thoussep, grouping);
745 if (grouping && (t = groupnum (tmp)))
749 p->width -= strlen(tmp);
752 if ((p->flags & PF_DOT) && p->precision > 0)
754 p->precision -= strlen(tmp);
765 if (p->flags & PF_ALTFORM)
769 if (p->flags & PF_ALTFORM)
795 tmp = fmtulong(d, 16, intbuf, sizeof(intbuf), 0);
796 p->width -= strlen(tmp);
799 /* prefix '0x' for pointers */
820 if (p->precision != NOT_FOUND) /* the smallest number */
821 len = (len < p->precision ? len : p->precision);
824 PUT_STRING (tmp, len, p);
828 /* %ls wide-character strings */
839 memset (&mbs, '\0', sizeof (mbstate_t));
840 ws = (const wchar_t *)tmp;
843 if (p->precision != NOT_FOUND)
845 os = (char *)xmalloc (p->precision + 1);
846 len = wcsrtombs (os, &ws, p->precision, &mbs);
850 len = wcsrtombs (NULL, &ws, 0, &mbs);
851 if (len != (size_t)-1)
853 memset (&mbs, '\0', sizeof (mbstate_t));
854 os = (char *)xmalloc (len + 1);
855 (void)wcsrtombs (os, &ws, len + 1, &mbs);
858 if (len == (size_t)-1)
860 /* invalid multibyte sequence; bail now. */
866 PUT_STRING (os, len, p);
879 lbuf = (char *)malloc (MB_CUR_MAX+1);
882 memset (&mbs, '\0', sizeof (mbstate_t));
883 len = wcrtomb (lbuf, wc, &mbs);
884 if (len == (size_t)-1)
885 /* conversion failed; bail now. */
889 PUT_STRING (l, len, p);
892 #endif /* HANDLE_MULTIBYTE */
894 #ifdef FLOATING_POINT
896 #ifndef HAVE_ISINF_IN_LIBC
897 /* Half-assed versions, since we don't want to link with libm. */
905 else if (d > DBL_MAX)
913 #ifndef HAVE_ISNAN_IN_LIBC
922 /* Check for [+-]infinity and NaN. If MODE == 1, we check for Infinity, else
923 (mode == 2) we check for NaN. This does the necessary printing. Returns
924 1 if Inf or Nan, 0 if not. */
926 chkinfnan(p, d, mode)
929 int mode; /* == 1 for inf, == 2 for nan */
935 i = (mode == 1) ? isinf(d) : isnan(d);
938 big = (mode == 1) ? "INF" : "NAN";
939 small = (mode == 1) ? "inf" : "nan";
941 tmp = (*p->pf == 'F' || *p->pf == 'G' || *p->pf == 'E') ? big : small;
955 /* %f %F %g %G floating point representation */
961 char *tmp, *tmp2, *t;
964 if (d != 0 && (chkinfnan(p, d, 1) || chkinfnan(p, d, 2)))
965 return; /* already printed nan or inf */
967 GETLOCALEDATA(decpoint, thoussep, grouping);
970 tmp = dtoa(d, p->precision, &tmp2);
972 if ((p->flags & PF_THOUSANDS) && grouping && (t = groupnum (tmp)))
975 /* calculate the padding. 1 for the dot */
976 p->width = p->width -
977 ((d > 0. && p->justify == RIGHT) ? 1:0) -
978 ((p->flags & PF_SPACE) ? 1:0) -
979 strlen(tmp) - p->precision - 1;
986 PUT_CHAR(*tmp, p); /* the integral */
991 if (p->precision != 0 || (p->flags & PF_ALTFORM))
992 PUT_CHAR(decpoint, p); /* put the '.' */
994 if ((*p->pf == 'g' || *p->pf == 'G') && (p->flags & PF_ALTFORM) == 0)
995 /* smash the trailing zeros unless altform */
996 for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] == '0'; i--)
999 for (; *tmp2; tmp2++)
1000 PUT_CHAR(*tmp2, p); /* the fraction */
1005 /* %e %E %g %G exponent representation */
1014 if (chkinfnan(p, d, 1) || chkinfnan(p, d, 2))
1015 return; /* already printed nan or inf */
1017 GETLOCALEDATA(decpoint, thoussep, grouping);
1020 d = d / pow_10(j); /* get the Mantissa */
1022 tmp = dtoa(d, p->precision, &tmp2);
1024 /* 1 for unit, 1 for the '.', 1 for 'e|E',
1025 * 1 for '+|-', 2 for 'exp' */
1026 /* calculate how much padding need */
1027 p->width = p->width -
1028 ((d > 0. && p->justify == RIGHT) ? 1:0) -
1029 ((p->flags & PF_SPACE) ? 1:0) - p->precision - 6;
1033 PUT_SPACE(d, p, 0.);
1041 if (p->precision != 0 || (p->flags & PF_ALTFORM))
1042 PUT_CHAR(decpoint, p); /* the '.' */
1044 if ((*p->pf == 'g' || *p->pf == 'G') && (p->flags & PF_ALTFORM) == 0)
1045 /* smash the trailing zeros unless altform */
1046 for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] == '0'; i--)
1049 for (; *tmp2; tmp2++)
1050 PUT_CHAR(*tmp2, p); /* the fraction */
1052 /* the exponent put the 'e|E' */
1053 if (*p->pf == 'g' || *p->pf == 'e')
1058 /* the sign of the exp */
1068 /* pad out to at least two spaces. pad with `0' if the exponent is a
1083 /* Return a new string with the digits in S grouped according to the locale's
1084 grouping info and thousands separator. If no grouping should be performed,
1085 this returns NULL; the caller needs to check for it. */
1090 char *se, *ret, *re, *g;
1093 if (grouping == 0 || *grouping <= 0 || *grouping == CHAR_MAX)
1094 return ((char *)NULL);
1096 /* find min grouping to size returned string */
1097 for (len = *grouping, g = grouping; *g; g++)
1098 if (*g > 0 && *g < len)
1102 len = slen / len + 1;
1103 ret = (char *)xmalloc (slen + len + 1);
1104 re = ret + slen + len;
1115 /* handle `-' inserted by numtoa() and the fmtu* family here. */
1116 if (se > s && se[-1] == '-')
1119 /* begin new group. */
1120 if (--len == 0 && se > s)
1123 len = *++g; /* was g++, but that uses first char twice (glibc bug, too) */
1125 len = *--g; /* use previous grouping */
1126 else if (*g == CHAR_MAX)
1138 memmove (ret, re, strlen (re) + 1);
1146 /* initialize the conversion specifiers */
1151 p->flags &= PF_ALLOCBUF; /* preserve PF_ALLOCBUF flag */
1152 p->precision = p->width = NOT_FOUND;
1153 p->justify = NOT_FOUND;
1158 init_data (p, string, length, format, mode)
1165 p->length = length - 1; /* leave room for '\0' */
1166 p->holder = p->base = string;
1169 p->flags = (mode == PFM_AS) ? PF_ALLOCBUF : 0;
1173 #if defined (__STDC__)
1174 vsnprintf_internal(struct DATA *data, char *string, size_t length, const char *format, va_list args)
1176 vsnprintf_internal(data, string, length, format, args)
1184 double d; /* temporary holder */
1185 #ifdef HAVE_LONG_DOUBLE
1186 long double ld; /* for later */
1189 #ifdef HAVE_LONG_LONG
1190 unsigned long long ull;
1194 #if HANDLE_MULTIBYTE
1198 const char *convstart;
1201 /* Sanity check, the string length must be >= 0. C99 actually says that
1202 LENGTH can be zero here, in the case of snprintf/vsnprintf (it's never
1203 0 in the case of asprintf/vasprintf), and the return value is the number
1204 of characters that would have been written. */
1211 /* Reset these for each call because the locale might have changed. */
1212 decpoint = thoussep = 0;
1216 for (; c = *(data->pf); data->pf++)
1224 convstart = data->pf;
1225 init_conv_flag (data); /* initialise format flags */
1228 for (state = 1; state && *data->pf; )
1231 /* fmtend = data->pf */
1232 #if defined (FLOATING_POINT) && defined (HAVE_LONG_DOUBLE)
1233 if (data->flags & PF_LONGDBL)
1240 # ifdef HAVE_PRINTF_A_FORMAT
1244 ld = GETLDOUBLE (data);
1245 ldfallback (data, convstart, data->pf, ld);
1249 #endif /* FLOATING_POINT && HAVE_LONG_DOUBLE */
1253 /* Parse format flags */
1254 case '\0': /* a NULL here ? ? bail out */
1255 *data->holder = '\0';
1256 return data->counter;
1259 data->flags |= PF_ALTFORM;
1262 data->flags |= PF_ZEROPAD;
1266 if (data->flags & PF_DOT)
1267 data->flags |= PF_STAR_P;
1269 data->flags |= PF_STAR_W;
1272 if ((data->flags & PF_DOT) == 0)
1274 data->flags |= PF_LADJUST;
1275 data->justify = LEFT;
1281 if ((data->flags & PF_PLUS) == 0)
1282 data->flags |= PF_SPACE;
1285 if ((data->flags & PF_DOT) == 0)
1287 data->flags |= PF_PLUS;
1288 data->justify = RIGHT;
1292 data->flags |= PF_THOUSANDS;
1295 case '1': case '2': case '3':
1296 case '4': case '5': case '6':
1297 case '7': case '8': case '9':
1301 n = n * 10 + TODIGIT(c);
1305 data->pf--; /* went too far */
1308 if (data->flags & PF_DOT)
1309 data->precision = negprec ? NOT_FOUND : n;
1314 /* optional precision */
1316 data->flags |= PF_DOT;
1317 data->precision = 0;
1320 /* length modifiers */
1322 data->flags |= (data->flags & PF_SHORTINT) ? PF_SIGNEDCHAR : PF_SHORTINT;
1325 data->flags |= (data->flags & PF_LONGINT) ? PF_LONGLONG : PF_LONGINT;
1328 data->flags |= PF_LONGDBL;
1331 data->flags |= PF_LONGLONG;
1334 data->flags |= PF_INTMAX_T;
1335 SET_SIZE_FLAGS(data, intmax_t);
1338 data->flags |= PF_SIZE_T;
1339 SET_SIZE_FLAGS(data, size_t);
1342 data->flags |= PF_PTRDIFF_T;
1343 SET_SIZE_FLAGS(data, ptrdiff_t);
1346 /* Conversion specifiers */
1347 #ifdef FLOATING_POINT
1348 case 'f': /* float, double */
1351 d = GETDOUBLE(data);
1360 d = GETDOUBLE(data);
1363 * for '%g|%G' ANSI: use f if exponent
1364 * is in the range or [-4,p] exclusively
1367 if (-4 < i && i < data->precision)
1369 /* reset precision */
1370 data->precision -= i + 1;
1375 /* reduce precision by 1 because of leading digit before
1376 decimal point in e format. */
1383 case 'E': /* Exponent double */
1385 d = GETDOUBLE(data);
1389 # ifdef HAVE_PRINTF_A_FORMAT
1393 d = GETDOUBLE(data);
1394 dfallback(data, convstart, data->pf, d);
1397 # endif /* HAVE_PRINTF_A_FORMAT */
1398 #endif /* FLOATING_POINT */
1400 data->flags |= PF_LONGINT;
1404 #ifdef HAVE_LONG_LONG
1405 if (data->flags & PF_LONGLONG)
1407 ull = GETARG (unsigned long long);
1408 lnumber(data, ull, 10);
1413 ul = GETUNSIGNED(data);
1414 number(data, ul, 10);
1419 data->flags |= PF_LONGINT;
1421 case 'd': /* decimal */
1424 #ifdef HAVE_LONG_LONG
1425 if (data->flags & PF_LONGLONG)
1427 ull = GETARG (long long);
1428 lnumber(data, ull, 10);
1433 ul = GETSIGNED(data);
1434 number(data, ul, 10);
1438 case 'o': /* octal */
1440 #ifdef HAVE_LONG_LONG
1441 if (data->flags & PF_LONGLONG)
1443 ull = GETARG (unsigned long long);
1444 lnumber(data, ull, 8);
1449 ul = GETUNSIGNED(data);
1450 number(data, ul, 8);
1455 case 'X': /* hexadecimal */
1457 #ifdef HAVE_LONG_LONG
1458 if (data->flags & PF_LONGLONG)
1460 ull = GETARG (unsigned long long);
1461 lnumber(data, ull, 16);
1466 ul = GETUNSIGNED(data);
1467 number(data, ul, 16);
1473 ul = (unsigned long)GETARG (void *);
1477 #if HANDLE_MULTIBYTE
1479 data->flags |= PF_LONGINT;
1482 case 'c': /* character */
1484 #if HANDLE_MULTIBYTE
1485 if (data->flags & PF_LONGINT)
1487 wc = GETARG (wint_t);
1498 #if HANDLE_MULTIBYTE
1500 data->flags |= PF_LONGINT;
1503 case 's': /* string */
1505 #if HANDLE_MULTIBYTE
1506 if (data->flags & PF_LONGINT)
1508 ws = GETARG (wchar_t *);
1509 wstrings (data, ws);
1514 s = GETARG (char *);
1520 #ifdef HAVE_LONG_LONG
1521 if (data->flags & PF_LONGLONG)
1522 *(GETARG (long long *)) = data->counter;
1525 if (data->flags & PF_LONGINT)
1526 *(GETARG (long *)) = data->counter;
1527 else if (data->flags & PF_SHORTINT)
1528 *(GETARG (short *)) = data->counter;
1530 *(GETARG (int *)) = data->counter;
1533 case '%': /* nothing just % */
1534 PUT_CHAR('%', data);
1538 /* is this an error ? maybe bail out */
1542 } /* end of `%' for loop */
1543 } /* end of format string for loop */
1545 if (data->length >= 0)
1546 *data->holder = '\0'; /* the end ye ! */
1548 return data->counter;
1551 #if defined (FLOATING_POINT) && defined (HAVE_LONG_DOUBLE)
1553 * Printing floating point numbers accurately is an art. I'm not good
1554 * at it. Fall back to sprintf for long double formats.
1557 ldfallback (data, fs, fe, ld)
1559 const char *fs, *fe;
1563 char fmtbuf[FALLBACK_FMTSIZE], *obuf;
1566 fl = LFALLBACK_BASE + (data->precision < 6 ? 6 : data->precision) + 2;
1567 obuf = (char *)xmalloc (fl);
1569 strncpy (fmtbuf, fs, fl);
1572 if ((data->flags & PF_STAR_W) && (data->flags & PF_STAR_P))
1573 sprintf (obuf, fmtbuf, data->width, data->precision, ld);
1574 else if (data->flags & PF_STAR_W)
1575 sprintf (obuf, fmtbuf, data->width, ld);
1576 else if (data->flags & PF_STAR_P)
1577 sprintf (obuf, fmtbuf, data->precision, ld);
1579 sprintf (obuf, fmtbuf, ld);
1581 for (x = obuf; *x; x++)
1582 PUT_CHAR (*x, data);
1585 #endif /* FLOATING_POINT && HAVE_LONG_DOUBLE */
1587 #ifdef FLOATING_POINT
1588 /* Used for %a, %A if the libc printf supports them. */
1590 dfallback (data, fs, fe, d)
1592 const char *fs, *fe;
1596 char fmtbuf[FALLBACK_FMTSIZE], obuf[FALLBACK_BASE];
1600 strncpy (fmtbuf, fs, fl);
1603 if ((data->flags & PF_STAR_W) && (data->flags & PF_STAR_P))
1604 sprintf (obuf, fmtbuf, data->width, data->precision, d);
1605 else if (data->flags & PF_STAR_W)
1606 sprintf (obuf, fmtbuf, data->width, d);
1607 else if (data->flags & PF_STAR_P)
1608 sprintf (obuf, fmtbuf, data->precision, d);
1610 sprintf (obuf, fmtbuf, d);
1612 for (x = obuf; *x; x++)
1613 PUT_CHAR (*x, data);
1615 #endif /* FLOATING_POINT */
1617 #ifndef HAVE_SNPRINTF
1620 #if defined (__STDC__)
1621 vsnprintf(char *string, size_t length, const char *format, va_list args)
1623 vsnprintf(string, length, format, args)
1632 if (string == 0 && length != 0)
1634 init_data (&data, string, length, format, PFM_SN);
1635 return (vsnprintf_internal(&data, string, length, format, args));
1639 #if defined(PREFER_STDARG)
1640 snprintf(char *string, size_t length, const char * format, ...)
1642 snprintf(string, length, format, va_alist)
1653 SH_VA_START(args, format);
1655 if (string == 0 && length != 0)
1657 init_data (&data, string, length, format, PFM_SN);
1658 rval = vsnprintf_internal (&data, string, length, format, args);
1665 #endif /* HAVE_SNPRINTF */
1667 #ifndef HAVE_ASPRINTF
1670 #if defined (__STDC__)
1671 vasprintf(char **stringp, const char *format, va_list args)
1673 vasprintf(stringp, format, args)
1683 string = (char *)xmalloc(ASBUFSIZE);
1684 init_data (&data, string, ASBUFSIZE, format, PFM_AS);
1685 r = vsnprintf_internal(&data, string, ASBUFSIZE, format, args);
1686 *stringp = data.base; /* not string in case reallocated */
1691 #if defined(PREFER_STDARG)
1692 asprintf(char **stringp, const char * format, ...)
1694 asprintf(stringp, format, va_alist)
1703 SH_VA_START(args, format);
1705 rval = vasprintf (stringp, format, args);
1719 memory_error_and_abort ()
1721 write (2, "out of virtual memory\n", 22);
1731 ret = malloc(bytes);
1733 memory_error_and_abort ();
1738 xrealloc (pointer, bytes)
1744 ret = pointer ? realloc(pointer, bytes) : malloc(bytes);
1746 memory_error_and_abort ();
1758 /* set of small tests for snprintf() */
1765 #ifdef HAVE_LOCALE_H
1766 setlocale(LC_ALL, "");
1770 si = snprintf((char *)NULL, 0, "abcde\n");
1771 printf("snprintf returns %d with NULL first argument and size of 0\n", si);
1772 si = snprintf(holder, 0, "abcde\n");
1773 printf("snprintf returns %d with non-NULL first argument and size of 0\n", si);
1774 si = snprintf((char *)NULL, 16, "abcde\n");
1775 printf("snprintf returns %d with NULL first argument and non-zero size\n", si);
1778 printf("Suite of test for snprintf:\n");
1779 printf("a_format\n");
1780 printf("printf() format\n");
1781 printf("snprintf() format\n\n");
1783 /* Checking the field widths */
1785 printf("/%%ld %%ld/, 336, 336\n");
1786 snprintf(holder, sizeof holder, "/%ld %ld/\n", 336, 336);
1787 asprintf(&h, "/%ld %ld/\n", 336, 336);
1788 printf("/%ld %ld/\n", 336, 336);
1789 printf("%s", holder);
1792 printf("/%%d/, 336\n");
1793 snprintf(holder, sizeof holder, "/%d/\n", 336);
1794 asprintf(&h, "/%d/\n", 336);
1795 printf("/%d/\n", 336);
1796 printf("%s", holder);
1799 printf("/%%2d/, 336\n");
1800 snprintf(holder, sizeof holder, "/%2d/\n", 336);
1801 asprintf(&h, "/%2d/\n", 336);
1802 printf("/%2d/\n", 336);
1803 printf("%s", holder);
1806 printf("/%%10d/, 336\n");
1807 snprintf(holder, sizeof holder, "/%10d/\n", 336);
1808 asprintf(&h, "/%10d/\n", 336);
1809 printf("/%10d/\n", 336);
1810 printf("%s", holder);
1813 printf("/%%-10d/, 336\n");
1814 snprintf(holder, sizeof holder, "/%-10d/\n", 336);
1815 asprintf(&h, "/%-10d/\n", 336);
1816 printf("/%-10d/\n", 336);
1817 printf("%s", holder);
1821 /* floating points */
1823 printf("/%%f/, 1234.56\n");
1824 snprintf(holder, sizeof holder, "/%f/\n", 1234.56);
1825 asprintf(&h, "/%f/\n", 1234.56);
1826 printf("/%f/\n", 1234.56);
1827 printf("%s", holder);
1830 printf("/%%e/, 1234.56\n");
1831 snprintf(holder, sizeof holder, "/%e/\n", 1234.56);
1832 asprintf(&h, "/%e/\n", 1234.56);
1833 printf("/%e/\n", 1234.56);
1834 printf("%s", holder);
1837 printf("/%%4.2f/, 1234.56\n");
1838 snprintf(holder, sizeof holder, "/%4.2f/\n", 1234.56);
1839 asprintf(&h, "/%4.2f/\n", 1234.56);
1840 printf("/%4.2f/\n", 1234.56);
1841 printf("%s", holder);
1844 printf("/%%3.1f/, 1234.56\n");
1845 snprintf(holder, sizeof holder, "/%3.1f/\n", 1234.56);
1846 asprintf(&h, "/%3.1f/\n", 1234.56);
1847 printf("/%3.1f/\n", 1234.56);
1848 printf("%s", holder);
1851 printf("/%%10.3f/, 1234.56\n");
1852 snprintf(holder, sizeof holder, "/%10.3f/\n", 1234.56);
1853 asprintf(&h, "/%10.3f/\n", 1234.56);
1854 printf("/%10.3f/\n", 1234.56);
1855 printf("%s", holder);
1858 printf("/%%10.3e/, 1234.56\n");
1859 snprintf(holder, sizeof holder, "/%10.3e/\n", 1234.56);
1860 asprintf(&h, "/%10.3e/\n", 1234.56);
1861 printf("/%10.3e/\n", 1234.56);
1862 printf("%s", holder);
1865 printf("/%%+4.2f/, 1234.56\n");
1866 snprintf(holder, sizeof holder, "/%+4.2f/\n", 1234.56);
1867 asprintf(&h, "/%+4.2f/\n", 1234.56);
1868 printf("/%+4.2f/\n", 1234.56);
1869 printf("%s", holder);
1872 printf("/%%010.2f/, 1234.56\n");
1873 snprintf(holder, sizeof holder, "/%010.2f/\n", 1234.56);
1874 asprintf(&h, "/%010.2f/\n", 1234.56);
1875 printf("/%010.2f/\n", 1234.56);
1876 printf("%s", holder);
1879 #define BLURB "Outstanding acting !"
1880 /* strings precisions */
1882 printf("/%%2s/, \"%s\"\n", BLURB);
1883 snprintf(holder, sizeof holder, "/%2s/\n", BLURB);
1884 asprintf(&h, "/%2s/\n", BLURB);
1885 printf("/%2s/\n", BLURB);
1886 printf("%s", holder);
1889 printf("/%%22s/ %s\n", BLURB);
1890 snprintf(holder, sizeof holder, "/%22s/\n", BLURB);
1891 asprintf(&h, "/%22s/\n", BLURB);
1892 printf("/%22s/\n", BLURB);
1893 printf("%s", holder);
1896 printf("/%%22.5s/ %s\n", BLURB);
1897 snprintf(holder, sizeof holder, "/%22.5s/\n", BLURB);
1898 asprintf(&h, "/%22.5s/\n", BLURB);
1899 printf("/%22.5s/\n", BLURB);
1900 printf("%s", holder);
1903 printf("/%%-22.5s/ %s\n", BLURB);
1904 snprintf(holder, sizeof holder, "/%-22.5s/\n", BLURB);
1905 asprintf(&h, "/%-22.5s/\n", BLURB);
1906 printf("/%-22.5s/\n", BLURB);
1907 printf("%s", holder);
1910 /* see some flags */
1912 printf("%%x %%X %%#x, 31, 31, 31\n");
1913 snprintf(holder, sizeof holder, "%x %X %#x\n", 31, 31, 31);
1914 asprintf(&h, "%x %X %#x\n", 31, 31, 31);
1915 printf("%x %X %#x\n", 31, 31, 31);
1916 printf("%s", holder);
1919 printf("**%%d**%% d**%% d**, 42, 42, -42\n");
1920 snprintf(holder, sizeof holder, "**%d**% d**% d**\n", 42, 42, -42);
1921 asprintf(&h, "**%d**% d**% d**\n", 42, 42, -42);
1922 printf("**%d**% d**% d**\n", 42, 42, -42);
1923 printf("%s", holder);
1928 printf("/%%g/, 31.4\n");
1929 snprintf(holder, sizeof holder, "/%g/\n", 31.4);
1930 asprintf(&h, "/%g/\n", 31.4);
1931 printf("/%g/\n", 31.4);
1932 printf("%s", holder);
1935 printf("/%%.6g/, 31.4\n");
1936 snprintf(holder, sizeof holder, "/%.6g/\n", 31.4);
1937 asprintf(&h, "/%.6g/\n", 31.4);
1938 printf("/%.6g/\n", 31.4);
1939 printf("%s", holder);
1942 printf("/%%.1G/, 31.4\n");
1943 snprintf(holder, sizeof holder, "/%.1G/\n", 31.4);
1944 asprintf(&h, "/%.1G/\n", 31.4);
1945 printf("/%.1G/\n", 31.4);
1946 printf("%s", holder);
1949 printf("/%%.1G/, 3100000000.4\n");
1950 snprintf(holder, sizeof holder, "/%.1G/\n", 3100000000.4);
1951 asprintf(&h, "/%.1G/\n", 3100000000.4);
1952 printf("/%.1G/\n", 3100000000.4);
1953 printf("%s", holder);
1957 printf("abc%n", &i); printf("%d\n", i);
1958 snprintf(holder, sizeof holder, "abc%n", &i);
1959 printf("%s", holder); printf("%d\n\n", i);
1960 asprintf(&h, "abc%n", &i);
1961 printf("%s", h); printf("%d\n\n", i);
1963 printf("%%*.*s --> 10.10\n");
1964 snprintf(holder, sizeof holder, "%*.*s\n", 10, 10, BLURB);
1965 asprintf(&h, "%*.*s\n", 10, 10, BLURB);
1966 printf("%*.*s\n", 10, 10, BLURB);
1967 printf("%s", holder);
1970 printf("%%%%%%%%\n");
1971 snprintf(holder, sizeof holder, "%%%%\n");
1972 asprintf(&h, "%%%%\n");
1974 printf("%s", holder);
1977 #define BIG "Hello this is a too big string for the buffer"
1978 /* printf("A buffer to small of 10, trying to put this:\n");*/
1979 printf("<%%>, %s\n", BIG);
1980 i = snprintf(holder, 10, "%s\n", BIG);
1981 i = asprintf(&h, "%s", BIG);
1982 printf("<%s>\n", BIG);
1983 printf("<%s>\n", holder);
1984 printf("<%s>\n\n", h);
1986 printf ("<%%p> vsnprintf\n");
1987 i = snprintf(holder, 100, "%p", vsnprintf);
1988 i = asprintf(&h, "%p", vsnprintf);
1989 printf("<%p>\n", vsnprintf);
1990 printf("<%s>\n", holder);
1991 printf("<%s>\n\n", h);
1993 printf ("<%%lu> LONG_MAX+1\n");
1994 i = snprintf(holder, 100, "%lu", (unsigned long)(LONG_MAX)+1);
1995 i = asprintf(&h, "%lu", (unsigned long)(LONG_MAX)+1);
1996 printf("<%lu>\n", (unsigned long)(LONG_MAX)+1);
1997 printf("<%s>\n", holder);
1998 printf("<%s>\n\n", h);
2000 #ifdef HAVE_LONG_LONG
2001 printf ("<%%llu> LLONG_MAX+1\n");
2002 i = snprintf(holder, 100, "%llu", (unsigned long long)(LLONG_MAX)+1);
2003 i = asprintf(&h, "%llu", (unsigned long long)(LLONG_MAX)+1);
2004 printf("<%llu>\n", (unsigned long long)(LLONG_MAX)+1);
2005 printf("<%s>\n", holder);
2006 printf("<%s>\n\n", h);
2009 #ifdef HAVE_LONG_DOUBLE
2010 printf ("<%%6.2LE> 42.42\n");
2011 i = snprintf(holder, 100, "%6.2LE", (long double)42.42);
2012 i = asprintf(&h, "%6.2LE", (long double)42.42);
2013 printf ("<%6.2LE>\n", (long double)42.42);
2014 printf ("<%s>\n", holder);
2015 printf ("<%s>\n\n", h);
2018 #ifdef HAVE_PRINTF_A_FORMAT
2019 printf ("<%%6.2A> 42.42\n");
2020 i = snprintf(holder, 100, "%6.2A", 42.42);
2021 i = asprintf(&h, "%6.2A", 42.42);
2022 printf ("<%6.2A>\n", 42.42);
2023 printf ("<%s>\n", holder);
2024 printf ("<%s>\n\n", h);
2026 printf ("<%%6.2LA> 42.42\n");
2027 i = snprintf(holder, 100, "%6.2LA", (long double)42.42);
2028 i = asprintf(&h, "%6.2LA", (long double)42.42);
2029 printf ("<%6.2LA>\n", (long double)42.42);
2030 printf ("<%s>\n", holder);
2031 printf ("<%s>\n\n", h);
2034 printf ("<%%.10240f> DBL_MAX\n");
2035 si = snprintf(holder, 100, "%.10240f", DBL_MAX);
2036 ai = asprintf(&h, "%.10240f", DBL_MAX);
2037 printf ("<%.10240f>\n", DBL_MAX);
2038 printf ("<%d> <%s>\n", si, holder);
2039 printf ("<%d> <%s>\n\n", ai, h);
2041 printf ("<%%.10240Lf> LDBL_MAX\n");
2042 si = snprintf(holder, 100, "%.10240Lf", (long double)LDBL_MAX);
2043 ai = asprintf(&h, "%.10240Lf", (long double)LDBL_MAX);
2044 printf ("<%.10240Lf>\n", (long double)LDBL_MAX);
2045 printf ("<%d> <%s>\n", si, holder);
2046 printf ("<%d> <%s>\n\n", ai, h);
2049 printf("/%%g/, 421.2345\n");
2050 snprintf(holder, sizeof holder, "/%g/\n", 421.2345);
2051 asprintf(&h, "/%g/\n", 421.2345);
2052 printf("/%g/\n", 421.2345);
2053 printf("%s", holder);
2056 printf("/%%g/, 4214.2345\n");
2057 snprintf(holder, sizeof holder, "/%g/\n", 4214.2345);
2058 asprintf(&h, "/%g/\n", 4214.2345);
2059 printf("/%g/\n", 4214.2345);
2060 printf("%s", holder);
2063 printf("/%%.5g/, 4214.2345\n");
2064 snprintf(holder, sizeof holder, "/%.5g/\n", 4214.2345);
2065 asprintf(&h, "/%.5g/\n", 4214.2345);
2066 printf("/%.5g/\n", 4214.2345);
2067 printf("%s", holder);
2070 printf("/%%.4g/, 4214.2345\n");
2071 snprintf(holder, sizeof holder, "/%.4g/\n", 4214.2345);
2072 asprintf(&h, "/%.4g/\n", 4214.2345);
2073 printf("/%.4g/\n", 4214.2345);
2074 printf("%s", holder);
2077 printf("/%%'ld %%'ld/, 12345, 1234567\n");
2078 snprintf(holder, sizeof holder, "/%'ld %'ld/\n", 12345, 1234567);
2079 asprintf(&h, "/%'ld %'ld/\n", 12345, 1234567);
2080 printf("/%'ld %'ld/\n", 12345, 1234567);
2081 printf("%s", holder);
2084 printf("/%%'ld %%'ld/, 336, 3336\n");
2085 snprintf(holder, sizeof holder, "/%'ld %'ld/\n", 336, 3336);
2086 asprintf(&h, "/%'ld %'ld/\n", 336, 3336);
2087 printf("/%'ld %'ld/\n", 336, 3336);
2088 printf("%s", holder);
2091 printf("/%%'ld %%'ld/, -42786, -142786\n");
2092 snprintf(holder, sizeof holder, "/%'ld %'ld/\n", -42786, -142786);
2093 asprintf(&h, "/%'ld %'ld/\n", -42786, -142786);
2094 printf("/%'ld %'ld/\n", -42786, -142786);
2095 printf("%s", holder);
2098 printf("/%%'f %%'f/, 421.2345, 421234.56789\n");
2099 snprintf(holder, sizeof holder, "/%'f %'f/\n", 421.2345, 421234.56789);
2100 asprintf(&h, "/%'f %'f/\n", 421.2345, 421234.56789);
2101 printf("/%'f %'f/\n", 421.2345, 421234.56789);
2102 printf("%s", holder);
2105 printf("/%%'f %%'f/, -421.2345, -421234.56789\n");
2106 snprintf(holder, sizeof holder, "/%'f %'f/\n", -421.2345, -421234.56789);
2107 asprintf(&h, "/%'f %'f/\n", -421.2345, -421234.56789);
2108 printf("/%'f %'f/\n", -421.2345, -421234.56789);
2109 printf("%s", holder);
2112 printf("/%%'g %%'g/, 421.2345, 421234.56789\n");
2113 snprintf(holder, sizeof holder, "/%'g %'g/\n", 421.2345, 421234.56789);
2114 asprintf(&h, "/%'g %'g/\n", 421.2345, 421234.56789);
2115 printf("/%'g %'g/\n", 421.2345, 421234.56789);
2116 printf("%s", holder);
2119 printf("/%%'g %%'g/, -421.2345, -421234.56789\n");
2120 snprintf(holder, sizeof holder, "/%'g %'g/\n", -421.2345, -421234.56789);
2121 asprintf(&h, "/%'g %'g/\n", -421.2345, -421234.56789);
2122 printf("/%'g %'g/\n", -421.2345, -421234.56789);
2123 printf("%s", holder);
2127 printf("/%%'g/, 4213455.8392\n");
2128 snprintf(holder, sizeof holder, "/%'g/\n", 4213455.8392);
2129 asprintf(&h, "/%'g/\n", 4213455.8392);
2130 printf("/%'g/\n", 4213455.8392);
2131 printf("%s", holder);