From 167d5e33fcb821e51e2f9dcf460591737c3c7972 Mon Sep 17 00:00:00 2001 From: "Peter S. Mazinger" Date: Tue, 3 Jan 2006 14:50:18 +0000 Subject: Complete split of all the string functions. Hope haven't broken too much. wcscoll/strcoll needs some love ... --- libc/string/strlcat.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 libc/string/strlcat.c (limited to 'libc/string/strlcat.c') diff --git a/libc/string/strlcat.c b/libc/string/strlcat.c new file mode 100644 index 000000000..117b8e552 --- /dev/null +++ b/libc/string/strlcat.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2002 Manuel Novoa III + * Copyright (C) 2000-2005 Erik Andersen + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* OpenBSD function: + * Append at most n-1-strlen(dst) chars from src to dst and nul-terminate dst. + * Returns strlen(src) + strlen({original} dst), so truncation occurred if the + * return val is >= n. + * Note: If dst doesn't contain a nul in the first n chars, strlen(dst) is + * taken as n. */ + +#include "_string.h" + +size_t strlcat(register char *__restrict dst, + register const char *__restrict src, + size_t n) +{ + size_t len; + char dummy[1]; + + len = 0; + + while (1) { + if (len >= n) { + dst = dummy; + break; + } + if (!*dst) { + break; + } + ++dst; + ++len; + } + + while ((*dst = *src) != 0) { + if (++len < n) { + ++dst; + } + ++src; + } + + return len; +} -- cgit v1.2.3