From 521d01e8ad87e931af3e9a763cc84a6cf7fe5ee3 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sun, 5 Dec 2021 09:47:21 -0800 Subject: Feat: basic string and memory functions Continue filling out the basic standard lib functions. Included prototypes of the str* and mem* families. Plan to add e(str|mem) and n(str|mem) variants as well. --- src/base/string/makef.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/base/string/makef.c') diff --git a/src/base/string/makef.c b/src/base/string/makef.c index 8fb9c38..1e0d917 100644 --- a/src/base/string/makef.c +++ b/src/base/string/makef.c @@ -1,25 +1,22 @@ #include "internal.h" -// Newf returns a new dynamic string object +// makef returns a new dynamic string object string -str·makef(const byte *fmt, ...) +string·makef(byte *fmt, ...) { vlong n; string s; va_list args; + char bytes[256]; - va_start(args, fmt); - n = vsnprintf(nil, 0, fmt, args); - va_end(args); - - s = str·makecap(nil, 0, n); + s = string·makecap(nil, 0, arrlen(bytes)); va_start(args, fmt); - vsnprintf(s, n + 1, fmt, args); + do{ + n = fmt·vnsprint(bytes, arrlen(bytes), fmt, args); + string·append(&s, bytes); + }while(n==arrlen(bytes)); va_end(args); - Hdr* h = (Hdr*)(s - sizeof(Hdr)); - h->len = n; - return s; } -- cgit v1.2.1