From e9ccf5e2f26d57fadb17f7912ecc9b97838b8642 Mon Sep 17 00:00:00 2001 From: Avril Date: Tue, 13 Jul 2021 19:27:55 +0100 Subject: [PATCH] Basic implementation of more sensible string mutating functions for display format string creation. (`strncat_n()`, `strncpy_n()`.) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO: Better `dest` parameter bounds checking. Fortune for naka's current commit: Future small blessing − 末小吉 --- src/display.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/display.c b/src/display.c index eba9cca..174126f 100644 --- a/src/display.c +++ b/src/display.c @@ -11,7 +11,24 @@ #define FLAGSET(f, flag) (( (f) & (flag) ) == (flag)) #define DFLAGSET(f, flagname) FLAGSET(f, DISPF_SHOW_ ## flagname) -//TODO: This probably won't work. Write wrappers for strncpy(), strncat() that return number of bytes written isntead of useless pointer that we already have. +// Returns number of bytes written to `dest`. Otherwise same as `strncpy()`. +static usize strncpy_n(char*pOUT dest, const char* restrict src, usize n) +{ + usize i; + for(i=0;i