scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

vsnprintf.c (345B)


      1 #include <stdarg.h>
      2 #include <stdio.h>
      3 
      4 #undef vsnprintf
      5 
      6 int
      7 vsnprintf(char *restrict s, size_t siz, const char *restrict fmt, va_list ap)
      8 {
      9 	FILE f;
     10 	int r;
     11 
     12 	f.flags = _IORW | _IOSTRG;
     13 	f.len = siz;
     14 	f.buf = s;
     15 	f.wp = s;
     16 	f.rp = s + siz;
     17 
     18 	r = vfprintf(&f, fmt, ap);
     19 	if (s) {
     20 		if (f.wp == f.rp)
     21 			--f.wp;
     22 		*f.wp = '\0';
     23 	}
     24 
     25 	return r;
     26 }