From 43ecfce7d20360a5fdc53e5ced266eccc8723242 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Fri, 29 May 2020 14:41:05 -0700 Subject: blas code update --- sys/libn/string.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'sys/libn/string.c') diff --git a/sys/libn/string.c b/sys/libn/string.c index 7c152e3..e2cdddf 100644 --- a/sys/libn/string.c +++ b/sys/libn/string.c @@ -349,25 +349,29 @@ str·fit(string *s) // structure. This variant can append a substring of length len of the given // string to our buffer. The result is reallocated if not enough room is present // in the buffer. -void +int str·appendlen(string *s, vlong n, const byte* b) { - vlong bl = strlen(b); + /* + bl = strlen(b); if (n > bl) panicf("attempted to make a substring longer than string"); + */ str·grow(s, n); - if (*s == nil) return; + if (*s == nil) return 0; Hdr* h = (Hdr*)(*s - sizeof(Hdr)); memcpy(*s + str·len(*s), b, n); h->len += n; (*s)[h->len] = '\0'; + + return n; } // Append will append the given null terminated C string to the string data // structure. This variant will append the entire string. -void +int str·append(string *s, const byte* b) { return str·appendlen(s, strlen(b), b); @@ -376,17 +380,19 @@ str·append(string *s, const byte* b) // AppendByte will append the given byte to our string. // NOTE: As the byte is on the stack, it is not null-terminated. // Can not pass to the above functions. -void +int str·appendbyte(string *s, const byte b) { str·grow(s, 1); - if (*s == nil) return; + if (*s == nil) return 0; Hdr* h = (Hdr*)(*s - sizeof(Hdr)); *(*s + str·len(*s)) = b; h->len++; (*s)[h->len] = '\0'; // NOTE: I don't think an explicit zero is required..? + + return 1; } /* @@ -394,7 +400,7 @@ str·appendbyte(string *s, const byte b) * Returns the newly minted string */ -void +int str·appendf(string *s, const byte* fmt, ...) { va_list args; @@ -415,6 +421,8 @@ str·appendf(string *s, const byte* fmt, ...) Hdr* h = (Hdr*)(*s - sizeof(Hdr)); h->len += n; + + return n; } // Equals returns true if string s and t are equivalent. -- cgit v1.2.1