Commit | Line | Data |
---|---|---|
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 | ||
7 | #ifndef lint | |
8 | static char sccsid[] = "@(#)strcpyn.c 4.2 (Berkeley) %G%"; | |
9 | #endif not lint | |
10 | ||
2039143b BJ |
11 | /* |
12 | * Copy s2 to s1, truncating or null-padding to always copy n bytes | |
13 | * return s1 | |
14 | */ | |
15 | ||
16 | char * | |
17 | strcpyn(s1, s2, n) | |
18 | register 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 | } |