mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -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:
@ -536,7 +536,7 @@ static void scp_source_send_E(ScpSource *scp)
|
||||
assert(scp->n_pending_commands == 0);
|
||||
|
||||
scp->pending_commands[scp->n_pending_commands++] = cmd = strbuf_new();
|
||||
strbuf_catf(cmd, "E\012");
|
||||
put_fmt(cmd, "E\012");
|
||||
}
|
||||
|
||||
static void scp_source_send_CD(
|
||||
@ -550,7 +550,7 @@ static void scp_source_send_CD(
|
||||
if (scp->send_file_times && (attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
|
||||
scp->pending_commands[scp->n_pending_commands++] = cmd = strbuf_new();
|
||||
/* Our SFTP-based filesystem API doesn't support microsecond times */
|
||||
strbuf_catf(cmd, "T%lu 0 %lu 0\012", attrs.mtime, attrs.atime);
|
||||
put_fmt(cmd, "T%lu 0 %lu 0\012", attrs.mtime, attrs.atime);
|
||||
}
|
||||
|
||||
const char *slash;
|
||||
@ -559,9 +559,9 @@ static void scp_source_send_CD(
|
||||
slash+1, name.len - (slash+1 - (const char *)name.ptr));
|
||||
|
||||
scp->pending_commands[scp->n_pending_commands++] = cmd = strbuf_new();
|
||||
strbuf_catf(cmd, "%c%04o %"PRIu64" %.*s\012", cmdchar,
|
||||
(unsigned)(attrs.permissions & 07777),
|
||||
size, PTRLEN_PRINTF(name));
|
||||
put_fmt(cmd, "%c%04o %"PRIu64" %.*s\012", cmdchar,
|
||||
(unsigned)(attrs.permissions & 07777),
|
||||
size, PTRLEN_PRINTF(name));
|
||||
|
||||
if (cmdchar == 'C') {
|
||||
/* We'll also wait for an ack before sending the file data,
|
||||
|
Reference in New Issue
Block a user