xref: /titanic_50/usr/src/lib/libast/common/string/strlcpy.c (revision 936b7af69172dce89b577831f79c0e18d15e854b)
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  * strlcpy implementation
25  */
26 
27 #define strlcpy		______strlcpy
28 
29 #include <ast.h>
30 
31 #undef	strlcpy
32 
33 #undef	_def_map_ast
34 #include <ast_map.h>
35 
36 #if _lib_strlcpy
37 
38 NoN(strlcpy)
39 
40 #else
41 
42 /*
43  * copy at most n chars from t into s
44  * result 0 terminated if n>0
45  * strlen(t) returned
46  */
47 
48 #if defined(__EXPORT__)
49 #define extern	__EXPORT__
50 #endif
51 
52 extern size_t
53 strlcpy(register char* s, register const char* t, register size_t n)
54 {
55 	const char*	o = t;
56 
57 	if (n)
58 		do
59 		{
60 			if (!--n)
61 			{
62 				*s = 0;
63 				break;
64 			}
65 		} while (*s++ = *t++);
66 	if (!n)
67 		while (*t++);
68 	return t - o - 1;
69 }
70 
71 #endif
72