9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

vsnprintf.c (346B)


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