new template
[unix-history] / usr / src / lib / libcompat / 4.1 / strcpyn.c
CommitLineData
503553be
KM
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
2ce81398
DS
7#if defined(LIBC_SCCS) && !defined(lint)
8static char sccsid[] = "@(#)strcpyn.c 4.3 (Berkeley) %G%";
9#endif LIBC_SCCS and not lint
503553be 10
2039143b
BJ
11/*
12 * Copy s2 to s1, truncating or null-padding to always copy n bytes
13 * return s1
14 */
15
16char *
17strcpyn(s1, s2, n)
18register char *s1, *s2;
19{
20 register i;
21 register char *os1;
22
23 os1 = s1;
24 for (i = 0; i < n; i++)
25 if ((*s1++ = *s2++) == '\0') {
26 while (++i < n)
27 *s1++ = '\0';
28 return(os1);
29 }
30 return(os1);
31}