From 1f9494979268b62ed4b4588fb7d9e790c0e12100 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 26 Oct 2026 22:32:52 +0100 Subject: replace all calls to sprintf with a format helper that advances a cursor. Also convert the meta-formatter (i.e. results printer) to this scheme --- ot_fmt.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ot_fmt.h (limited to 'ot_fmt.h') diff --git a/ot_fmt.h b/ot_fmt.h new file mode 100644 index 0000000..851b2d8 --- /dev/null +++ b/ot_fmt.h @@ -0,0 +1,21 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. + + $id$ */ + +#ifndef OT_FMT_H__ +#define OT_FMT_H__ + +#include + +/* Appending to a cursor that walks a fixed buffer. Both take the cursor by + reference and advance it, so a reply is written as a run of statements and + no caller does pointer arithmetic of its own. */ + +void fmt_append(char **cursor, const char *end, const char *format, ...) __attribute__((format(printf, 3, 4))); + +/* Append raw bytes for the binary stretches of a bencoded reply. + Either everything is appended or nothing at all */ +void fmt_bytes(char **cursor, const char *end, const void *bytes, size_t length); + +#endif -- cgit v1.3