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