diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-02 20:50:24 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-02 21:14:02 +0100 |
| commit | ad541c67761b8aa6da1566802c347cac4018d0c2 (patch) | |
| tree | a9166fa9d349911d69a6948e53b05344dcc348a0 /ot_fmt.c | |
| parent | c679ff8a3b1418a5960cc49ba6458a0007df54fa (diff) | |
Move the build sources into src/
Diffstat (limited to 'ot_fmt.c')
| -rw-r--r-- | ot_fmt.c | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/ot_fmt.c b/ot_fmt.c deleted file mode 100644 index 362c9b5..0000000 --- a/ot_fmt.c +++ /dev/null | |||
| @@ -1,40 +0,0 @@ | |||
| 1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | ||
| 2 | It is considered beerware. Prost. Skol. Cheers or whatever. */ | ||
| 3 | |||
| 4 | /* System */ | ||
| 5 | #include <stdarg.h> | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | |||
| 9 | /* Opentracker */ | ||
| 10 | #include "ot_fmt.h" | ||
| 11 | |||
| 12 | void fmt_append(char **cursor, const char *end, const char *format, ...) { | ||
| 13 | va_list arguments; | ||
| 14 | size_t room; | ||
| 15 | int written; | ||
| 16 | |||
| 17 | if (*cursor >= end) { | ||
| 18 | *cursor = (char *)end; | ||
| 19 | return; | ||
| 20 | } | ||
| 21 | |||
| 22 | room = (size_t)(end - *cursor); | ||
| 23 | va_start(arguments, format); | ||
| 24 | written = vsnprintf(*cursor, room, format, arguments); | ||
| 25 | va_end(arguments); | ||
| 26 | |||
| 27 | if (written < 0) | ||
| 28 | return; | ||
| 29 | *cursor = (size_t)written >= room ? (char *)end : *cursor + written; | ||
| 30 | } | ||
| 31 | |||
| 32 | void fmt_bytes(char **cursor, const char *end, const void *bytes, size_t length) { | ||
| 33 | if (*cursor >= end || (size_t)(end - *cursor) < length) { | ||
| 34 | *cursor = (char *)end; | ||
| 35 | return; | ||
| 36 | } | ||
| 37 | |||
| 38 | memcpy(*cursor, bytes, length); | ||
| 39 | *cursor += length; | ||
| 40 | } | ||
