mutt stable branch with some hacks
1/**************************************************************
2 * Original:
3 * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
4 * A bombproof version of doprnt (dopr) included.
5 * Sigh. This sort of thing is always nasty do deal with. Note that
6 * the version here does not include floating point...
7 *
8 * snprintf() is used instead of sprintf() as it does limit checks
9 * for string length. This covers a nasty loophole.
10 *
11 * The other functions are there to prevent NULL pointers from
12 * causing nast effects.
13 *
14 * More Recently:
15 * Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43
16 * This was ugly. It is still ugly. I opted out of floating point
17 * numbers, but the formatter understands just about everything
18 * from the normal C string format, at least as far as I can tell from
19 * the Solaris 2.5 printf(3S) man page.
20 *
21 * Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1
22 * Ok, added some minimal floating point support, which means this
23 * probably requires libm on most operating systems. Don't yet
24 * support the exponent (e,E) and sigfig (g,G). Also, fmtint()
25 * was pretty badly broken, it just wasn't being exercised in ways
26 * which showed it, so that's been fixed. Also, formatted the code
27 * to mutt conventions, and removed dead code left over from the
28 * original. Also, there is now a builtin-test, just compile with:
29 * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
30 * and run snprintf for results.
31 *
32 * Thomas Roessler <roessler@does-not-exist.org> 01/27/98 for mutt 0.89i
33 * The PGP code was using unsigned hexadecimal formats.
34 * Unfortunately, unsigned formats simply didn't work.
35 *
36 * Michael Elkins <me@mutt.org> 03/05/98 for mutt 0.90.8
37 * The original code assumed that both snprintf() and vsnprintf() were
38 * missing. Some systems only have snprintf() but not vsnprintf(), so
39 * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
40 *
41 * Holger Weiss <holger@zedat.fu-berlin.de> 07/23/06 for mutt 1.5.13
42 * A C99 compliant [v]snprintf() returns the number of characters that
43 * would have been written to a sufficiently sized buffer (excluding
44 * the '\0'). Mutt now relies on this behavior, but the original
45 * code simply returned the length of the resulting output string, so
46 * that's been fixed.
47 *
48 **************************************************************/
49
50#if HAVE_CONFIG_H
51# include "config.h"
52#endif
53
54#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
55
56#include <string.h>
57# include <ctype.h>
58#include <sys/types.h>
59
60/* Define this as a fall through, HAVE_STDARG_H is probably already set */
61
62#define HAVE_VARARGS_H
63
64/* varargs declarations: */
65
66#if defined(HAVE_STDARG_H)
67# include <stdarg.h>
68# define HAVE_STDARGS /* let's hope that works everywhere (mj) */
69# define VA_LOCAL_DECL va_list ap
70# define VA_START(f) va_start(ap, f)
71# define VA_SHIFT(v,t) ; /* no-op for ANSI */
72# define VA_END va_end(ap)
73#else
74# if defined(HAVE_VARARGS_H)
75# include <varargs.h>
76# undef HAVE_STDARGS
77# define VA_LOCAL_DECL va_list ap
78# define VA_START(f) va_start(ap) /* f is ignored! */
79# define VA_SHIFT(v,t) v = va_arg(ap,t)
80# define VA_END va_end(ap)
81# else
82/*XX ** NO VARARGS ** XX*/
83# endif
84#endif
85
86/*int snprintf (char *str, size_t count, const char *fmt, ...);*/
87/*int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);*/
88
89static int dopr (char *buffer, size_t maxlen, const char *format,
90 va_list args);
91static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
92 char *value, int flags, int min, int max);
93static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
94 long value, int base, int min, int max, int flags);
95static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
96 long double fvalue, int min, int max, int flags);
97static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
98
99/*
100 * dopr(): poor man's version of doprintf
101 */
102
103/* format read states */
104#define DP_S_DEFAULT 0
105#define DP_S_FLAGS 1
106#define DP_S_MIN 2
107#define DP_S_DOT 3
108#define DP_S_MAX 4
109#define DP_S_MOD 5
110#define DP_S_CONV 6
111#define DP_S_DONE 7
112
113/* format flags - Bits */
114#define DP_F_MINUS (1 << 0)
115#define DP_F_PLUS (1 << 1)
116#define DP_F_SPACE (1 << 2)
117#define DP_F_NUM (1 << 3)
118#define DP_F_ZERO (1 << 4)
119#define DP_F_UP (1 << 5)
120#define DP_F_UNSIGNED (1 << 6)
121
122/* Conversion Flags */
123#define DP_C_SHORT 1
124#define DP_C_LONG 2
125#define DP_C_LONGLONG 3
126#define DP_C_LDOUBLE 4
127
128#define char_to_int(p) (p - '0')
129#undef MAX
130#define MAX(p,q) ((p >= q) ? p : q)
131
132static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
133{
134 char ch;
135 long value;
136 long double fvalue;
137 char *strvalue;
138 int min;
139 int max;
140 int state;
141 int flags;
142 int cflags;
143 size_t currlen;
144
145 state = DP_S_DEFAULT;
146 currlen = flags = cflags = min = 0;
147 max = -1;
148 ch = *format++;
149
150 while (state != DP_S_DONE)
151 {
152 if (ch == '\0')
153 state = DP_S_DONE;
154
155 switch(state)
156 {
157 case DP_S_DEFAULT:
158 if (ch == '%')
159 state = DP_S_FLAGS;
160 else
161 dopr_outch (buffer, &currlen, maxlen, ch);
162 ch = *format++;
163 break;
164 case DP_S_FLAGS:
165 switch (ch)
166 {
167 case '-':
168 flags |= DP_F_MINUS;
169 ch = *format++;
170 break;
171 case '+':
172 flags |= DP_F_PLUS;
173 ch = *format++;
174 break;
175 case ' ':
176 flags |= DP_F_SPACE;
177 ch = *format++;
178 break;
179 case '#':
180 flags |= DP_F_NUM;
181 ch = *format++;
182 break;
183 case '0':
184 flags |= DP_F_ZERO;
185 ch = *format++;
186 break;
187 default:
188 state = DP_S_MIN;
189 break;
190 }
191 break;
192 case DP_S_MIN:
193 if (isdigit((unsigned char)ch))
194 {
195 min = 10*min + char_to_int (ch);
196 ch = *format++;
197 }
198 else if (ch == '*')
199 {
200 min = va_arg (args, int);
201 ch = *format++;
202 state = DP_S_DOT;
203 }
204 else
205 state = DP_S_DOT;
206 break;
207 case DP_S_DOT:
208 if (ch == '.')
209 {
210 state = DP_S_MAX;
211 ch = *format++;
212 }
213 else
214 state = DP_S_MOD;
215 break;
216 case DP_S_MAX:
217 if (isdigit((unsigned char)ch))
218 {
219 if (max < 0)
220 max = 0;
221 max = 10*max + char_to_int (ch);
222 ch = *format++;
223 }
224 else if (ch == '*')
225 {
226 max = va_arg (args, int);
227 ch = *format++;
228 state = DP_S_MOD;
229 }
230 else
231 state = DP_S_MOD;
232 break;
233 case DP_S_MOD:
234 switch (ch)
235 {
236 case 'h':
237 cflags = DP_C_SHORT;
238 ch = *format++;
239 break;
240 case 'l':
241 cflags = DP_C_LONG;
242 ch = *format++;
243 if (ch == 'l')
244 {
245 cflags = DP_C_LONGLONG;
246 ch = *format++;
247 }
248 break;
249 case 'L':
250 cflags = DP_C_LDOUBLE;
251 ch = *format++;
252 break;
253 default:
254 break;
255 }
256 state = DP_S_CONV;
257 break;
258 case DP_S_CONV:
259 switch (ch)
260 {
261 case 'd':
262 case 'i':
263 if (cflags == DP_C_SHORT)
264 value = va_arg (args, short int);
265 else if (cflags == DP_C_LONG)
266 value = va_arg (args, long int);
267 else if (cflags == DP_C_LONGLONG)
268 value = va_arg (args, long long int);
269 else
270 value = va_arg (args, int);
271 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
272 break;
273 case 'o':
274 flags |= DP_F_UNSIGNED;
275 if (cflags == DP_C_SHORT)
276 value = va_arg (args, unsigned short int);
277 else if (cflags == DP_C_LONG)
278 value = va_arg (args, unsigned long int);
279 else if (cflags == DP_C_LONGLONG)
280 value = va_arg (args, unsigned long long int);
281 else
282 value = va_arg (args, unsigned int);
283 fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
284 break;
285 case 'u':
286 flags |= DP_F_UNSIGNED;
287 if (cflags == DP_C_SHORT)
288 value = va_arg (args, unsigned short int);
289 else if (cflags == DP_C_LONG)
290 value = va_arg (args, unsigned long int);
291 else if (cflags == DP_C_LONGLONG)
292 value = va_arg (args, unsigned long long int);
293 else
294 value = va_arg (args, unsigned int);
295 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
296 break;
297 case 'X':
298 flags |= DP_F_UP;
299 case 'x':
300 flags |= DP_F_UNSIGNED;
301 if (cflags == DP_C_SHORT)
302 value = va_arg (args, unsigned short int);
303 else if (cflags == DP_C_LONG)
304 value = va_arg (args, unsigned long int);
305 else if (cflags == DP_C_LONGLONG)
306 value = va_arg (args, unsigned long long int);
307 else
308 value = va_arg (args, unsigned int);
309 fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
310 break;
311 case 'f':
312 if (cflags == DP_C_LDOUBLE)
313 fvalue = va_arg (args, long double);
314 else
315 fvalue = va_arg (args, double);
316 /* um, floating point? */
317 fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
318 break;
319 case 'E':
320 flags |= DP_F_UP;
321 case 'e':
322 if (cflags == DP_C_LDOUBLE)
323 fvalue = va_arg (args, long double);
324 else
325 fvalue = va_arg (args, double);
326 break;
327 case 'G':
328 flags |= DP_F_UP;
329 case 'g':
330 if (cflags == DP_C_LDOUBLE)
331 fvalue = va_arg (args, long double);
332 else
333 fvalue = va_arg (args, double);
334 break;
335 case 'c':
336 dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
337 break;
338 case 's':
339 strvalue = va_arg (args, char *);
340 fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
341 break;
342 case 'p':
343 flags |= DP_F_UNSIGNED;
344 strvalue = va_arg (args, void *);
345 fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
346 break;
347 case 'n':
348 if (cflags == DP_C_SHORT)
349 {
350 short int *num;
351 num = va_arg (args, short int *);
352 *num = currlen;
353 }
354 else if (cflags == DP_C_LONG)
355 {
356 long int *num;
357 num = va_arg (args, long int *);
358 *num = currlen;
359 }
360 else if (cflags == DP_C_LONGLONG)
361 {
362 long long int *num;
363 num = va_arg (args, long long int *);
364 *num = currlen;
365 }
366 else
367 {
368 int *num;
369 num = va_arg (args, int *);
370 *num = currlen;
371 }
372 break;
373 case '%':
374 dopr_outch (buffer, &currlen, maxlen, ch);
375 break;
376 case 'w':
377 /* not supported yet, treat as next char */
378 ch = *format++;
379 break;
380 default:
381 /* Unknown, skip */
382 break;
383 }
384 ch = *format++;
385 state = DP_S_DEFAULT;
386 flags = cflags = min = 0;
387 max = -1;
388 break;
389 case DP_S_DONE:
390 break;
391 default:
392 /* hmm? */
393 break; /* some picky compilers need this */
394 }
395 }
396 if (currlen < maxlen - 1)
397 buffer[currlen] = '\0';
398 else
399 buffer[maxlen - 1] = '\0';
400
401 return (int)currlen;
402}
403
404static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
405 char *value, int flags, int min, int max)
406{
407 int padlen, strln; /* amount to pad */
408 int cnt = 0;
409
410 if (!value)
411 {
412 value = "<NULL>";
413 }
414
415 for (strln = 0; value[strln]; ++strln); /* strlen */
416 padlen = min - strln;
417 if (padlen < 0)
418 padlen = 0;
419 if (flags & DP_F_MINUS)
420 padlen = -padlen; /* Left Justify */
421
422 while ((padlen > 0) && (max == -1 || cnt < max))
423 {
424 dopr_outch (buffer, currlen, maxlen, ' ');
425 --padlen;
426 ++cnt;
427 }
428 while (*value && (max == -1 || cnt < max))
429 {
430 dopr_outch (buffer, currlen, maxlen, *value++);
431 ++cnt;
432 }
433 while ((padlen < 0) && (max == -1 || cnt < max))
434 {
435 dopr_outch (buffer, currlen, maxlen, ' ');
436 ++padlen;
437 ++cnt;
438 }
439}
440
441/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
442
443static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
444 long value, int base, int min, int max, int flags)
445{
446 int signvalue = 0;
447 unsigned long uvalue;
448 char convert[20];
449 int place = 0;
450 int spadlen = 0; /* amount to space pad */
451 int zpadlen = 0; /* amount to zero pad */
452 int caps = 0;
453
454 if (max < 0)
455 max = 0;
456
457 uvalue = value;
458
459 if(!(flags & DP_F_UNSIGNED))
460 {
461 if( value < 0 ) {
462 signvalue = '-';
463 uvalue = -value;
464 }
465 else
466 if (flags & DP_F_PLUS) /* Do a sign (+/i) */
467 signvalue = '+';
468 else
469 if (flags & DP_F_SPACE)
470 signvalue = ' ';
471 }
472
473 if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
474
475 do {
476 convert[place++] =
477 (caps? "0123456789ABCDEF":"0123456789abcdef")
478 [uvalue % (unsigned)base ];
479 uvalue = (uvalue / (unsigned)base );
480 } while(uvalue && (place < 20));
481 if (place == 20) place--;
482 convert[place] = 0;
483
484 zpadlen = max - place;
485 spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
486 if (zpadlen < 0) zpadlen = 0;
487 if (spadlen < 0) spadlen = 0;
488 if (flags & DP_F_ZERO)
489 {
490 zpadlen = MAX(zpadlen, spadlen);
491 spadlen = 0;
492 }
493 if (flags & DP_F_MINUS)
494 spadlen = -spadlen; /* Left Justifty */
495
496#ifdef DEBUG_SNPRINTF
497 dprint (1, (debugfile, "zpad: %d, spad: %d, min: %d, max: %d, place: %d\n",
498 zpadlen, spadlen, min, max, place));
499#endif
500
501 /* Spaces */
502 while (spadlen > 0)
503 {
504 dopr_outch (buffer, currlen, maxlen, ' ');
505 --spadlen;
506 }
507
508 /* Sign */
509 if (signvalue)
510 dopr_outch (buffer, currlen, maxlen, signvalue);
511
512 /* Zeros */
513 if (zpadlen > 0)
514 {
515 while (zpadlen > 0)
516 {
517 dopr_outch (buffer, currlen, maxlen, '0');
518 --zpadlen;
519 }
520 }
521
522 /* Digits */
523 while (place > 0)
524 dopr_outch (buffer, currlen, maxlen, convert[--place]);
525
526 /* Left Justified spaces */
527 while (spadlen < 0) {
528 dopr_outch (buffer, currlen, maxlen, ' ');
529 ++spadlen;
530 }
531}
532
533static long double abs_val (long double value)
534{
535 long double result = value;
536
537 if (value < 0)
538 result = -value;
539
540 return result;
541}
542
543static long double pow10 (int exp)
544{
545 long double result = 1;
546
547 while (exp)
548 {
549 result *= 10;
550 exp--;
551 }
552
553 return result;
554}
555
556static long round (long double value)
557{
558 long intpart;
559
560 intpart = value;
561 value = value - intpart;
562 if (value >= 0.5)
563 intpart++;
564
565 return intpart;
566}
567
568static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
569 long double fvalue, int min, int max, int flags)
570{
571 int signvalue = 0;
572 long double ufvalue;
573 char iconvert[20];
574 char fconvert[20];
575 int iplace = 0;
576 int fplace = 0;
577 int padlen = 0; /* amount to pad */
578 int zpadlen = 0;
579 int caps = 0;
580 long intpart;
581 long fracpart;
582
583 /*
584 * AIX manpage says the default is 0, but Solaris says the default
585 * is 6, and sprintf on AIX defaults to 6
586 */
587 if (max < 0)
588 max = 6;
589
590 ufvalue = abs_val (fvalue);
591
592 if (fvalue < 0)
593 signvalue = '-';
594 else
595 if (flags & DP_F_PLUS) /* Do a sign (+/i) */
596 signvalue = '+';
597 else
598 if (flags & DP_F_SPACE)
599 signvalue = ' ';
600
601#if 0
602 if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
603#endif
604
605 intpart = ufvalue;
606
607 /*
608 * Sorry, we only support 9 digits past the decimal because of our
609 * conversion method
610 */
611 if (max > 9)
612 max = 9;
613
614 /* We "cheat" by converting the fractional part to integer by
615 * multiplying by a factor of 10
616 */
617 fracpart = round ((pow10 (max)) * (ufvalue - intpart));
618
619 if (fracpart >= pow10 (max))
620 {
621 intpart++;
622 fracpart -= pow10 (max);
623 }
624
625#ifdef DEBUG_SNPRINTF
626 dprint (1, (debugfile, "fmtfp: %f =? %d.%d\n", fvalue, intpart, fracpart));
627#endif
628
629 /* Convert integer part */
630 do {
631 iconvert[iplace++] =
632 (caps? "0123456789ABCDEF":"0123456789abcdef")[intpart % 10];
633 intpart = (intpart / 10);
634 } while(intpart && (iplace < 20));
635 if (iplace == 20) iplace--;
636 iconvert[iplace] = 0;
637
638 /* Convert fractional part */
639 do {
640 fconvert[fplace++] =
641 (caps? "0123456789ABCDEF":"0123456789abcdef")[fracpart % 10];
642 fracpart = (fracpart / 10);
643 } while(fracpart && (fplace < 20));
644 if (fplace == 20) fplace--;
645 fconvert[fplace] = 0;
646
647 /* -1 for decimal point, another -1 if we are printing a sign */
648 padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
649 zpadlen = max - fplace;
650 if (zpadlen < 0)
651 zpadlen = 0;
652 if (padlen < 0)
653 padlen = 0;
654 if (flags & DP_F_MINUS)
655 padlen = -padlen; /* Left Justifty */
656
657 if ((flags & DP_F_ZERO) && (padlen > 0))
658 {
659 if (signvalue)
660 {
661 dopr_outch (buffer, currlen, maxlen, signvalue);
662 --padlen;
663 signvalue = 0;
664 }
665 while (padlen > 0)
666 {
667 dopr_outch (buffer, currlen, maxlen, '0');
668 --padlen;
669 }
670 }
671 while (padlen > 0)
672 {
673 dopr_outch (buffer, currlen, maxlen, ' ');
674 --padlen;
675 }
676 if (signvalue)
677 dopr_outch (buffer, currlen, maxlen, signvalue);
678
679 while (iplace > 0)
680 dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]);
681
682 /*
683 * Decimal point. This should probably use locale to find the correct
684 * char to print out.
685 */
686 dopr_outch (buffer, currlen, maxlen, '.');
687
688 while (fplace > 0)
689 dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]);
690
691 while (zpadlen > 0)
692 {
693 dopr_outch (buffer, currlen, maxlen, '0');
694 --zpadlen;
695 }
696
697 while (padlen < 0)
698 {
699 dopr_outch (buffer, currlen, maxlen, ' ');
700 ++padlen;
701 }
702}
703
704static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c)
705{
706 if (*currlen < maxlen)
707 buffer[*currlen] = c;
708 (*currlen)++;
709}
710#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
711
712#ifndef HAVE_VSNPRINTF
713int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
714{
715 str[0] = 0;
716 return(dopr(str, count, fmt, args));
717}
718#endif /* !HAVE_VSNPRINTF */
719
720#ifndef HAVE_SNPRINTF
721/* VARARGS3 */
722#ifdef HAVE_STDARGS
723int snprintf (char *str,size_t count,const char *fmt,...)
724#else
725int snprintf (va_alist) va_dcl
726#endif
727{
728#ifndef HAVE_STDARGS
729 char *str;
730 size_t count;
731 char *fmt;
732#endif
733 int len;
734 VA_LOCAL_DECL;
735
736 VA_START (fmt);
737 VA_SHIFT (str, char *);
738 VA_SHIFT (count, size_t );
739 VA_SHIFT (fmt, char *);
740 len = vsnprintf(str, count, fmt, ap);
741 VA_END;
742 return(len);
743}
744
745#ifdef TEST_SNPRINTF
746#ifndef LONG_STRING
747#define LONG_STRING 1024
748#endif
749int main (void)
750{
751 char buf1[LONG_STRING];
752 char buf2[LONG_STRING];
753 char *fp_fmt[] = {
754 "%-1.5f",
755 "%1.5f",
756 "%123.9f",
757 "%10.5f",
758 "% 10.5f",
759 "%+22.9f",
760 "%+4.9f",
761 "%01.3f",
762 "%4f",
763 "%3.1f",
764 "%3.2f",
765 NULL
766 };
767 double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
768 0.9996, 1.996, 4.136, 0};
769 char *int_fmt[] = {
770 "%-1.5d",
771 "%1.5d",
772 "%123.9d",
773 "%5.5d",
774 "%10.5d",
775 "% 10.5d",
776 "%+22.33d",
777 "%01.3d",
778 "%4d",
779 NULL
780 };
781 long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
782 int x, y;
783 int fail = 0;
784 int num = 0;
785
786 printf ("Testing snprintf format codes against system sprintf...\n");
787
788 for (x = 0; fp_fmt[x] != NULL ; x++)
789 for (y = 0; fp_nums[y] != 0 ; y++)
790 {
791 snprintf (buf1, sizeof (buf1), fp_fmt[x], fp_nums[y]);
792 sprintf (buf2, fp_fmt[x], fp_nums[y]);
793 if (strcmp (buf1, buf2))
794 {
795 printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n", /* __SPRINTF_CHECKED__ */
796 fp_fmt[x], buf1, buf2);
797 fail++;
798 }
799 num++;
800 }
801
802 for (x = 0; int_fmt[x] != NULL ; x++)
803 for (y = 0; int_nums[y] != 0 ; y++)
804 {
805 snprintf (buf1, sizeof (buf1), int_fmt[x], int_nums[y]);
806 sprintf (buf2, int_fmt[x], int_nums[y]);
807 if (strcmp (buf1, buf2))
808 {
809 printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n", /* __SPRINTF_CHECKED__ */
810 int_fmt[x], buf1, buf2);
811 fail++;
812 }
813 num++;
814 }
815 printf ("%d tests failed out of %d.\n", fail, num);
816}
817#endif /* SNPRINTF_TEST */
818
819#endif /* !HAVE_SNPRINTF */