From e63a8d5e3b2ebc848e01c139756cd2096efe7c80 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 29 Mar 2014 20:37:11 -0400 Subject: misc: Add M_StringConcat. Just as M_StringCopy behaves the same as strlcpy(), M_StringConcat behaves the same as strlcat(). Use this in one location. --- src/m_misc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/m_misc.c') diff --git a/src/m_misc.c b/src/m_misc.c index 7bab3f1b..02031213 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -366,6 +366,25 @@ boolean M_StringCopy(char *dest, char *src, size_t dest_size) return strlen(dest) == strlen(src); } +// Safe string concat function that works like OpenBSD's strlcat(). +// Returns true if string not truncated. + +boolean M_StringConcat(char *dest, char *src, size_t dest_size) +{ + size_t offset; + + offset = strlen(dest); + if (offset > dest_size) + { + offset = dest_size; + } + + dest += offset; + dest_size -= offset; + + return M_StringCopy(dest, src, dest_size); +} + // Returns true if 's' begins with the specified prefix. boolean M_StringStartsWith(char *s, char *prefix) @@ -425,7 +444,7 @@ char *M_StringJoin(char *s, ...) break; } - strncat(result, v, result_len); + M_StringConcat(result, v, result_len); } va_end(args); -- cgit v1.2.3