mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-18 11:31:00 -05:00
Generalise strbuf_catf() into put_fmt().
marshal.h now provides a macro put_fmt() which allows you to write arbitrary printf-formatted data to an arbitrary BinarySink. We already had this facility for strbufs in particular, in the form of strbuf_catf(). That was able to take advantage of knowing the inner structure of a strbuf to minimise memory allocation (it would snprintf directly into the strbuf's existing buffer if possible). For a general black-box BinarySink we can't do that, so instead we dupvprintf into a temporary buffer. For consistency, I've removed strbuf_catf, and converted all uses of it into the new put_fmt - and I've also added an extra vtable method in the BinarySink API, so that put_fmt can still use strbuf_catf's more efficient memory management when talking to a strbuf, and fall back to the simpler strategy when that's not available.
This commit is contained in:
2
misc.h
2
misc.h
@ -56,8 +56,6 @@ void *strbuf_append(strbuf *buf, size_t len);
|
||||
void strbuf_shrink_to(strbuf *buf, size_t new_len);
|
||||
void strbuf_shrink_by(strbuf *buf, size_t amount_to_remove);
|
||||
char *strbuf_to_str(strbuf *buf); /* does free buf, but you must free result */
|
||||
void strbuf_catf(strbuf *buf, const char *fmt, ...) PRINTF_LIKE(2, 3);
|
||||
void strbuf_catfv(strbuf *buf, const char *fmt, va_list ap);
|
||||
static inline void strbuf_clear(strbuf *buf) { strbuf_shrink_to(buf, 0); }
|
||||
bool strbuf_chomp(strbuf *buf, char char_to_remove);
|
||||
|
||||
|
Reference in New Issue
Block a user