From abf1b805231a7cd01a249c67413e7c1e3152b72e Mon Sep 17 00:00:00 2001 From: hpa Date: Tue, 21 Dec 2004 04:57:40 +0000 Subject: [PATCH] Add strlcpy(), strlcat() --- com32/lib/strlcat.c | 31 +++++++++++++++++++++++++++++++ com32/lib/strlcpy.c | 26 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 com32/lib/strlcat.c create mode 100644 com32/lib/strlcpy.c diff --git a/com32/lib/strlcat.c b/com32/lib/strlcat.c new file mode 100644 index 0000000..6111445 --- /dev/null +++ b/com32/lib/strlcat.c @@ -0,0 +1,31 @@ +/* + * strlcat.c + */ + +#include +#include + +size_t strlcat(char *dst, const char *src, size_t size) +{ + size_t bytes = 0; + char *q = dst; + const char *p = src; + char ch; + + while ( bytes < size && *q ) { + q++; + bytes++; + } + + while ( (ch = *p++) ) { + if ( bytes < size ) + *q++ = ch; + + bytes++; + } + + *q = '\0'; + return bytes; +} + + diff --git a/com32/lib/strlcpy.c b/com32/lib/strlcpy.c new file mode 100644 index 0000000..eb384c9 --- /dev/null +++ b/com32/lib/strlcpy.c @@ -0,0 +1,26 @@ +/* + * strlcpy.c + */ + +#include +#include + +size_t strlcpy(char *dst, const char *src, size_t size) +{ + size_t bytes = 0; + char *q = dst; + const char *p = src; + char ch; + + while ( (ch = *p++) ) { + if ( bytes < size ) + *q++ = ch; + + bytes++; + } + + *q = '\0'; + return bytes; +} + + -- 2.7.4