xref: /titanic_44/usr/src/lib/libast/common/string/strlcat.c (revision 55553f719b521a0bb4deab6efc944cd30c1a56aa)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * strlcat implementation
25  */
26 
27 #define strlcat		______strlcat
28 
29 #include <ast.h>
30 
31 #undef	strlcat
32 
33 #undef	_def_map_ast
34 #include <ast_map.h>
35 
36 #if _lib_strlcat
37 
38 NoN(strlcat)
39 
40 #else
41 
42 /*
43  * append at t onto s limiting total size of s to n
44  * s 0 terminated if n>0
45  * min(n,strlen(s))+strlen(t) returned
46  */
47 
48 #if defined(__EXPORT__)
49 #define extern	__EXPORT__
50 #endif
51 
52 extern size_t
53 strlcat(register char* s, register const char* t, register size_t n)
54 {
55 	const char*	o = t;
56 
57 	if (n)
58 	{
59 		while (--n && *s)
60 			s++;
61 		if (n)
62 			do
63 			{
64 				if (!--n)
65 				{
66 					*s = 0;
67 					break;
68 				}
69 			} while (*s++ = *t++);
70 		else
71 			*s = 0;
72 	}
73 	if (!n)
74 		while (*t++);
75 	return t - o - 1;
76 }
77 
78 #endif
79