diff options
author | tron <tron@openttd.org> | 2005-02-06 13:41:02 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-02-06 13:41:02 +0000 |
commit | b2ae5b197ef3c9753e044f98d7973829d4848dba (patch) | |
tree | 0aab391e034d9f14ce3c721ca9f25bfc6395c9fc /string.c | |
parent | 498ccae27af050c66dfa70e9017eb45cefaf99ae (diff) | |
download | openttd-b2ae5b197ef3c9753e044f98d7973829d4848dba.tar.xz |
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/string.c b/string.c new file mode 100644 index 000000000..5022e7524 --- /dev/null +++ b/string.c @@ -0,0 +1,39 @@ +#include "stdafx.h" +#include "string.h" + +void ttd_strlcat(char *dst, const char *src, size_t size) +{ + assert(size > 0); + for (; size > 0 && *dst != '\0'; --size, ++dst) {} + assert(size > 0); + while (--size > 0 && *src != '\0') *dst++ = *src++; + *dst = '\0'; +} + + +void ttd_strlcpy(char *dst, const char *src, size_t size) +{ + assert(size > 0); + while (--size > 0 && *src != '\0') *dst++ = *src++; + *dst = '\0'; +} + + +char* strecat(char* dst, const char* src, const char* last) +{ + assert(last == NULL || dst <= last); + for (; *dst != '\0'; ++dst) + if (dst == last) return dst; + for (; *src != '\0' && dst != last; ++dst, ++src) *dst = *src; + *dst = '\0'; + return strecpy(dst, src, last); +} + + +char* strecpy(char* dst, const char* src, const char* last) +{ + assert(last == NULL || dst <= last); + for (; *src != '\0' && dst != last; ++dst, ++src) *dst = *src; + *dst = '\0'; + return dst; +} |