vsnprint.c - 9base - revived minimalist port of Plan 9 userland to Unix | |
git clone git://git.suckless.org/9base | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
vsnprint.c (509B) | |
--- | |
1 /* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ | |
2 #include <stdlib.h> | |
3 #include <stdarg.h> | |
4 #include "plan9.h" | |
5 #include "fmt.h" | |
6 #include "fmtdef.h" | |
7 | |
8 int | |
9 vsnprint(char *buf, int len, char *fmt, va_list args) | |
10 { | |
11 Fmt f; | |
12 | |
13 if(len <= 0) | |
14 return -1; | |
15 f.runes = 0; | |
16 f.start = buf; | |
17 f.to = buf; | |
18 f.stop = buf + len - 1; | |
19 f.flush = 0; | |
20 f.farg = nil; | |
21 f.nfmt = 0; | |
22 VA_COPY(f.args,args); | |
23 fmtlocaleinit(&f, nil, nil, nil); | |
24 dofmt(&f, fmt); | |
25 VA_END(f.args); | |
26 *(char*)f.to = '\0'; | |
27 return (char*)f.to - buf; | |
28 } |