xref: /csrg-svn/lib/libc/string/strncpy.c (revision 35098)
11989Swnj /*
2*35098Sbostic  * Copyright (c) 1988 Regents of the University of California.
3*35098Sbostic  * All rights reserved.
4*35098Sbostic  *
5*35098Sbostic  * Redistribution and use in source and binary forms are permitted
6*35098Sbostic  * provided that the above copyright notice and this paragraph are
7*35098Sbostic  * duplicated in all such forms and that any documentation,
8*35098Sbostic  * advertising materials, and other materials related to such
9*35098Sbostic  * distribution and use acknowledge that the software was developed
10*35098Sbostic  * by the University of California, Berkeley.  The name of the
11*35098Sbostic  * University may not be used to endorse or promote products derived
12*35098Sbostic  * from this software without specific prior written permission.
13*35098Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*35098Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*35098Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
161989Swnj  */
171989Swnj 
18*35098Sbostic #if defined(LIBC_SCCS) && !defined(lint)
19*35098Sbostic static char sccsid[] = "@(#)strncpy.c	5.3 (Berkeley) 07/18/88";
20*35098Sbostic #endif /* LIBC_SCCS and not lint */
21*35098Sbostic 
221989Swnj char *
23*35098Sbostic strncpy(to, from, cnt)
24*35098Sbostic 	register char *to, *from;
25*35098Sbostic 	register int cnt;
261989Swnj {
27*35098Sbostic 	char *save = to;
281989Swnj 
29*35098Sbostic 	for (; cnt && (*from = *to); --cnt, ++from, ++to);
30*35098Sbostic 	for (; cnt; --cnt, ++from)
31*35098Sbostic 		*from = '\0';
32*35098Sbostic 	return(save);
331989Swnj }
34