diff options
author | Simon Howard | 2014-03-29 20:37:11 -0400 |
---|---|---|
committer | Simon Howard | 2014-03-29 20:37:11 -0400 |
commit | e63a8d5e3b2ebc848e01c139756cd2096efe7c80 (patch) | |
tree | 14a1acba93dc2832dbbbcd267ec83af41adb818b /src/m_misc.c | |
parent | 62b5c602821cee8ac703ebe6362f3e1fc6d9ad3c (diff) | |
download | chocolate-doom-e63a8d5e3b2ebc848e01c139756cd2096efe7c80.tar.gz chocolate-doom-e63a8d5e3b2ebc848e01c139756cd2096efe7c80.tar.bz2 chocolate-doom-e63a8d5e3b2ebc848e01c139756cd2096efe7c80.zip |
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.
Diffstat (limited to 'src/m_misc.c')
-rw-r--r-- | src/m_misc.c | 21 |
1 files changed, 20 insertions, 1 deletions
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); |