ref: 525464c6327088724d2b01356f91ca371d2767f4
parent: 29f18f0920e58066becfdbf810b080a4c97d8d2b
author: cancel <cancel@cancel.fm>
date: Tue Jan 7 04:18:01 EST 2020
Cleanup
--- a/thirdparty/gbstring.c
+++ b/thirdparty/gbstring.c
@@ -89,7 +89,19 @@
size_t len = str ? strlen(str) : 0;
return gbs_newlen(str, len);
}
-
+gbs gbs_newvprintf(const char *fmt, va_list ap) {
+ gbs s;
+ s = gbs_catvprintf(NULL, fmt, ap);
+ return s;
+}
+gbs gbs_newprintf(char const *fmt, ...) {
+ gbs s;
+ va_list ap;
+ va_start(ap, fmt);
+ s = gbs_catvprintf(NULL, fmt, ap);
+ va_end(ap);
+ return s;
+}
void gbs_free(gbs str) {
if (str == NULL)
return;
@@ -227,9 +239,7 @@
}
if (s == NULL)
return NULL;
- va_copy(cpy, ap);
- vsnprintf(s + old_len, (size_t)required + 1, fmt, cpy);
- va_end(cpy);
+ vsnprintf(s + old_len, (size_t)required + 1, fmt, ap);
return s;
}
--- a/thirdparty/gbstring.h
+++ b/thirdparty/gbstring.h
@@ -8,6 +8,12 @@
gbs gbs_newcap(size_t cap);
gbs gbs_newlen(void const *str, size_t len);
gbs gbs_new(char const *str);
+gbs gbs_newvprintf(const char *fmt, va_list ap);
+gbs gbs_newprintf(char const *fmt, ...)
+#ifdef __GNUC__
+ __attribute__((format(printf, 1, 2)))
+#endif
+ ;
void gbs_free(gbs str);
gbs gbs_dup(gbs const str);
@@ -21,6 +27,12 @@
gbs gbs_catlen(gbs str, void const *other, size_t len);
gbs gbs_cat(gbs str, char const *other);
gbs gbs_catgbs(gbs str, gbs const other);
+gbs gbs_catvprintf(gbs str, const char *fmt, va_list ap);
+gbs gbs_catprintf(gbs str, char const *fmt, ...)
+#ifdef __GNUC__
+ __attribute__((format(printf, 2, 3)))
+#endif
+ ;
gbs gbs_cpylen(gbs str, char const *cstr, size_t len);
gbs gbs_cpy(gbs str, char const *cstr);
@@ -30,12 +42,5 @@
bool gbs_equal(gbs const lhs, gbs const rhs);
gbs gbs_trim(gbs str, char const *cut_set);
-
-gbs gbs_catvprintf(gbs str, const char *fmt, va_list ap);
-gbs gbs_catprintf(gbs str, char const *fmt, ...)
-#ifdef __GNUC__
- __attribute__((format(printf, 2, 3)))
-#endif
- ;
size_t gbs_totalmemused(gbs const str);