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