libdl: first execute all destructors, then munmap library
[uclibc-ng.git] / libc / string / strlcat.c
blobd55761d4c842b01d4de8565e58827bdd75583a3c
1 /*
2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
8 /* OpenBSD function:
9 * Append at most n-1-strlen(dst) chars from src to dst and nul-terminate dst.
10 * Returns strlen(src) + strlen({original} dst), so truncation occurred if the
11 * return val is >= n.
12 * Note: If dst doesn't contain a nul in the first n chars, strlen(dst) is
13 * taken as n. */
15 #include "_string.h"
17 size_t strlcat(register char *__restrict dst,
18 register const char *__restrict src,
19 size_t n)
21 size_t len;
22 char dummy[1];
24 len = 0;
26 while (1) {
27 if (len >= n) {
28 dst = dummy;
29 break;
31 if (!*dst) {
32 break;
34 ++dst;
35 ++len;
38 while ((*dst = *src) != 0) {
39 if (++len < n) {
40 ++dst;
42 ++src;
45 return len;
47 libc_hidden_def(strlcat)