tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

snprintf.c (809B)


      1 #ifndef HAVE_SNPRINTF
      2 
      3 #include <sys/types.h>
      4 #include <stddef.h>
      5 #include <stdio.h>
      6 
      7 #include "prtypes.h"
      8 
      9 #include <ncompat.h>
     10 
     11 #include <stdarg.h>
     12 
     13 int
     14 snprintf(char *str, size_t n, const char *fmt, ...)
     15 {
     16    va_list ap;
     17 #ifdef VSPRINTF_CHARSTAR
     18    char *rp;
     19 #else
     20    int rval;
     21 #endif
     22    va_start(ap, fmt);
     23 #ifdef VSPRINTF_CHARSTAR
     24    rp = vsprintf(str, fmt, ap);
     25    va_end(ap);
     26    return (strlen(rp));
     27 #else
     28    rval = vsprintf(str, fmt, ap);
     29    va_end(ap);
     30    return (rval);
     31 #endif
     32 }
     33 
     34 int
     35 vsnprintf(str, n, fmt, ap)
     36 char *str;
     37 size_t n;
     38 const char *fmt;
     39 va_list ap;
     40 {
     41 #ifdef VSPRINTF_CHARSTAR
     42    return (strlen(vsprintf(str, fmt, ap)));
     43 #else
     44    return (vsprintf(str, fmt, ap));
     45 #endif
     46 }
     47 
     48 #endif /* HAVE_SNPRINTF */
     49 
     50 /* Some compilers don't like an empty source file. */
     51 static int dummy = 0;