]>
git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/stdio/vsnprintf.c
1 #include "stdio_impl.h"
12 #define MIN(a, b) ((a) < (b) ? (a) : (b))
14 static size_t sn_write(FILE *f
, const unsigned char *s
, size_t l
)
16 struct cookie
*c
= f
->cookie
;
17 size_t k
= MIN(c
->n
, f
->wpos
- f
->wbase
);
19 memcpy(c
->s
, f
->wbase
, k
);
30 f
->wpos
= f
->wbase
= f
->buf
;
31 /* pretend to succeed, even if we discarded extra data */
35 int vsnprintf(char *restrict s
, size_t n
, const char *restrict fmt
, va_list ap
)
39 struct cookie c
= { .s
= n
? s
: dummy
, .n
= n
? n
-1 : 0 };
54 return vfprintf(&f
, fmt
, ap
);