From ad541c67761b8aa6da1566802c347cac4018d0c2 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 2 Nov 2026 20:50:24 +0100 Subject: Move the build sources into src/ --- src/ot_fmt.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/ot_fmt.c (limited to 'src/ot_fmt.c') diff --git a/src/ot_fmt.c b/src/ot_fmt.c new file mode 100644 index 0000000..362c9b5 --- /dev/null +++ b/src/ot_fmt.c @@ -0,0 +1,40 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. */ + +/* System */ +#include +#include +#include + +/* Opentracker */ +#include "ot_fmt.h" + +void fmt_append(char **cursor, const char *end, const char *format, ...) { + va_list arguments; + size_t room; + int written; + + if (*cursor >= end) { + *cursor = (char *)end; + return; + } + + room = (size_t)(end - *cursor); + va_start(arguments, format); + written = vsnprintf(*cursor, room, format, arguments); + va_end(arguments); + + if (written < 0) + return; + *cursor = (size_t)written >= room ? (char *)end : *cursor + written; +} + +void fmt_bytes(char **cursor, const char *end, const void *bytes, size_t length) { + if (*cursor >= end || (size_t)(end - *cursor) < length) { + *cursor = (char *)end; + return; + } + + memcpy(*cursor, bytes, length); + *cursor += length; +} -- cgit v1.3