1*2264Sjacobs /*
2*2264Sjacobs  * CDDL HEADER START
3*2264Sjacobs  *
4*2264Sjacobs  * The contents of this file are subject to the terms of the
5*2264Sjacobs  * Common Development and Distribution License (the "License").
6*2264Sjacobs  * You may not use this file except in compliance with the License.
7*2264Sjacobs  *
8*2264Sjacobs  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2264Sjacobs  * or http://www.opensolaris.org/os/licensing.
10*2264Sjacobs  * See the License for the specific language governing permissions
11*2264Sjacobs  * and limitations under the License.
12*2264Sjacobs  *
13*2264Sjacobs  * When distributing Covered Code, include this CDDL HEADER in each
14*2264Sjacobs  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2264Sjacobs  * If applicable, add the following below this CDDL HEADER, with the
16*2264Sjacobs  * fields enclosed by brackets "[]" replaced with your own identifying
17*2264Sjacobs  * information: Portions Copyright [yyyy] [name of copyright owner]
18*2264Sjacobs  *
19*2264Sjacobs  * CDDL HEADER END
20*2264Sjacobs  */
21*2264Sjacobs 
22*2264Sjacobs /*
23*2264Sjacobs  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*2264Sjacobs  * Use is subject to license terms.
25*2264Sjacobs  *
26*2264Sjacobs  */
27*2264Sjacobs 
28*2264Sjacobs /* $Id: misc.c 146 2006-03-24 00:26:54Z njacobs $ */
29*2264Sjacobs 
30*2264Sjacobs #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*2264Sjacobs 
32*2264Sjacobs /*LINTLIBRARY*/
33*2264Sjacobs 
34*2264Sjacobs #include <string.h>
35*2264Sjacobs #include <papi.h>
36*2264Sjacobs 
37*2264Sjacobs #include <config-site.h>
38*2264Sjacobs 
39*2264Sjacobs /*
40*2264Sjacobs  * The implementations of strlcpy() and strlcat() have been taken directly
41*2264Sjacobs  * from OpenSolaris.  The contents of this file originated from
42*2264Sjacobs  *     usr/src/lib/libc/port/gen/strlcpy.c
43*2264Sjacobs  *     usr/src/lib/libc/port/gen/strcat.c
44*2264Sjacobs  */
45*2264Sjacobs 
46*2264Sjacobs #ifndef HAVE_STRLCPY
47*2264Sjacobs size_t
48*2264Sjacobs strlcpy(char *dst, const char *src, size_t len)
49*2264Sjacobs {
50*2264Sjacobs 	size_t slen = strlen(src);
51*2264Sjacobs 	size_t copied;
52*2264Sjacobs 
53*2264Sjacobs 	if (len == 0)
54*2264Sjacobs 		return (slen);
55*2264Sjacobs 
56*2264Sjacobs 	if (slen >= len)
57*2264Sjacobs 		copied = len - 1;
58*2264Sjacobs 	else
59*2264Sjacobs 		copied = slen;
60*2264Sjacobs 	(void) memcpy(dst, src, copied);
61*2264Sjacobs 	dst[copied] = '\0';
62*2264Sjacobs 	return (slen);
63*2264Sjacobs }
64*2264Sjacobs #endif
65*2264Sjacobs 
66*2264Sjacobs #ifndef HAVE_STRLCAT
67*2264Sjacobs size_t
68*2264Sjacobs strlcat(char *dst, const char *src, size_t dstsize)
69*2264Sjacobs {
70*2264Sjacobs 	char *df = dst;
71*2264Sjacobs 	size_t left = dstsize;
72*2264Sjacobs 	size_t l1;
73*2264Sjacobs 	size_t l2 = strlen(src);
74*2264Sjacobs 	size_t copied;
75*2264Sjacobs 
76*2264Sjacobs 	while (left-- != 0 && *df != '\0')
77*2264Sjacobs 		df++;
78*2264Sjacobs 	l1 = df - dst;
79*2264Sjacobs 	if (dstsize == l1)
80*2264Sjacobs 		return (l1 + l2);
81*2264Sjacobs 
82*2264Sjacobs 	copied = l1 + l2 >= dstsize ? dstsize - l1 - 1 : l2;
83*2264Sjacobs 	(void) memcpy(dst + l1, src, copied);
84*2264Sjacobs 	dst[l1+copied] = '\0';
85*2264Sjacobs 	return (l1 + l2);
86*2264Sjacobs }
87*2264Sjacobs #endif
88