vsnprint.c (520B) download
1/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */
2#include "fmt.h"
3#include "fmtdef.h"
4#include "plan9.h"
5
6#include <stdarg.h>
7#include <stdlib.h>
8
9int vsnprint(char* buf, int len, char* fmt, va_list args) {
10 Fmt f;
11
12 if (len <= 0)
13 return -1;
14 f.runes = 0;
15 f.start = buf;
16 f.to = buf;
17 f.stop = buf + len - 1;
18 f.flush = 0;
19 f.farg = nil;
20 f.nfmt = 0;
21 VA_COPY(f.args, args);
22 fmtlocaleinit(&f, nil, nil, nil);
23 dofmt(&f, fmt);
24 VA_END(f.args);
25 *(char*) f.to = '\0';
26 return (char*) f.to - buf;
27}