aboutsummaryrefslogtreecommitdiff
path: root/src/base/string/appendf.c
blob: dee2065528c478777c05c55eee02b3b28b8e10d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "internal.h"

/*
 * appendf will append the given formatted string to our buffer.
 * returns the newly minted string
 */

int
string·appendf(string *s, byte* fmt, ...)
{
    int r, n;
    va_list args;

    va_start(args, fmt);
    do{
        r = string·cap(*s) - string·len(*s);
        n = fmt·vnsprint(*s + string·len(*s), r+1, fmt, args);
        string·grow(s, 2*string·cap(*s));
    }while(n==r);
    va_end(args);

    return n;
}