Support printf %n directive

This commit is contained in:
Justine Tunney 2024-07-28 22:27:06 -07:00
parent c1a0b017e9
commit 01b09bc817
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
8 changed files with 21 additions and 8 deletions

View file

@ -26,8 +26,8 @@
struct SprintfStr {
char *p;
size_t i;
size_t n;
int i;
int n;
};
static int vsnprintfputchar(const char *s, struct SprintfStr *t, size_t n) {
@ -58,7 +58,7 @@ static int vsnprintfputchar(const char *s, struct SprintfStr *t, size_t n) {
*/
int vsnprintf(char *buf, size_t size, const char *fmt, va_list va) {
struct SprintfStr str = {buf, 0, size};
int rc = __fmt(vsnprintfputchar, &str, fmt, va);
int rc = __fmt(vsnprintfputchar, &str, fmt, va, &str.i);
if (rc < 0)
return rc;
if (str.n)