1255365Sdes/*-
2255365Sdes * Copyright (c) 2011-2012 Dag-Erling Sm��rgrav
3255365Sdes * All rights reserved.
4255365Sdes *
5255365Sdes * Redistribution and use in source and binary forms, with or without
6255365Sdes * modification, are permitted provided that the following conditions
7255365Sdes * are met:
8255365Sdes * 1. Redistributions of source code must retain the above copyright
9255365Sdes *    notice, this list of conditions and the following disclaimer.
10255365Sdes * 2. Redistributions in binary form must reproduce the above copyright
11255365Sdes *    notice, this list of conditions and the following disclaimer in the
12255365Sdes *    documentation and/or other materials provided with the distribution.
13255365Sdes * 3. The name of the author may not be used to endorse or promote
14255365Sdes *    products derived from this software without specific prior written
15255365Sdes *    permission.
16255365Sdes *
17255365Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18255365Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19255365Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20255365Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21255365Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22255365Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23255365Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24255365Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25255365Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26255365Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27255365Sdes * SUCH DAMAGE.
28255365Sdes *
29255365Sdes * $Id: openpam_strlcat.c 648 2013-03-05 17:54:27Z des $
30255365Sdes */
31255365Sdes
32255365Sdes#ifdef HAVE_CONFIG_H
33255365Sdes# include "config.h"
34255365Sdes#endif
35255365Sdes
36255365Sdes#ifndef HAVE_STRLCAT
37255365Sdes
38255365Sdes#include <stddef.h>
39255365Sdes
40255365Sdes#include "openpam_strlcat.h"
41255365Sdes
42255365Sdes/* like strcat(3), but always NUL-terminates; returns strlen(src) */
43255365Sdessize_t
44255365Sdesopenpam_strlcat(char *dst, const char *src, size_t size)
45255365Sdes{
46255365Sdes	size_t len;
47255365Sdes
48255365Sdes	for (len = 0; *dst && size > 1; ++len, --size)
49255365Sdes		dst++;
50255365Sdes	for (; *src && size > 1; ++len, --size)
51255365Sdes		*dst++ = *src++;
52255365Sdes	*dst = '\0';
53255365Sdes	while (*src)
54255365Sdes		++len, ++src;
55255365Sdes	return (len);
56255365Sdes}
57255365Sdes
58255365Sdes#endif
59