mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -05:00
Marshalling macros put_dataz and put_datalit.
When I wanted to append an ordinary C string to a BinarySink, without any prefix length field or suffix terminator, I was using the idiom put_datapl(bs, ptrlen_from_asciz(string)); but I've finally decided that's too cumbersome, and it deserves a shorter name. put_dataz(bs, string) now does the same thing - in fact it's a macro expanding to exactly the above. While I'm at it, I've also added put_datalit(), which is the same except that it expects a C string literal (and will enforce that at compile time, via PTRLEN_LITERAL which it calls in turn). You can use that where possible to avoid the run-time cost of the strlen.
This commit is contained in:
@ -774,7 +774,7 @@ int main(int argc, char **argv)
|
||||
while (argc > 0) {
|
||||
if (cmdbuf->len > 0)
|
||||
put_byte(cmdbuf, ' '); /* add space separator */
|
||||
put_datapl(cmdbuf, ptrlen_from_asciz(p));
|
||||
put_dataz(cmdbuf, p);
|
||||
if (--argc > 0)
|
||||
p = *++argv;
|
||||
}
|
||||
|
@ -557,7 +557,7 @@ bool enum_settings_next(settings_e *handle, strbuf *out)
|
||||
fullpath = strbuf_new();
|
||||
|
||||
char *sessiondir = make_filename(INDEX_SESSIONDIR, NULL);
|
||||
put_datapl(fullpath, ptrlen_from_asciz(sessiondir));
|
||||
put_dataz(fullpath, sessiondir);
|
||||
sfree(sessiondir);
|
||||
put_byte(fullpath, '/');
|
||||
|
||||
@ -565,7 +565,7 @@ bool enum_settings_next(settings_e *handle, strbuf *out)
|
||||
|
||||
while ( (de = readdir(handle->dp)) != NULL ) {
|
||||
strbuf_shrink_to(fullpath, baselen);
|
||||
put_datapl(fullpath, ptrlen_from_asciz(de->d_name));
|
||||
put_dataz(fullpath, de->d_name);
|
||||
|
||||
if (stat(fullpath->s, &st) < 0 || !S_ISREG(st.st_mode))
|
||||
continue; /* try another one */
|
||||
|
Reference in New Issue
Block a user