rewritten from manual page; add Berkeley specific header
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 19 Jul 1988 07:43:26 +0000 (23:43 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 19 Jul 1988 07:43:26 +0000 (23:43 -0800)
SCCS-vsn: lib/libc/string/strncpy.c 5.3

usr/src/lib/libc/string/strncpy.c

index 5c3b968..a0288d6 100644 (file)
@@ -1,25 +1,33 @@
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strncpy.c  5.2 (Berkeley) %G%";
-#endif LIBC_SCCS and not lint
-
 /*
 /*
- * Copy s2 to s1, truncating or null-padding to always copy n bytes
- * return s1
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  */
 
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strncpy.c  5.3 (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
 char *
 char *
-strncpy(s1, s2, n)
-register char *s1, *s2;
+strncpy(to, from, cnt)
+       register char *to, *from;
+       register int cnt;
 {
 {
-       register i;
-       register char *os1;
+       char *save = to;
 
 
-       os1 = s1;
-       for (i = 0; i < n; i++)
-               if ((*s1++ = *s2++) == '\0') {
-                       while (++i < n)
-                               *s1++ = '\0';
-                       return(os1);
-               }
-       return(os1);
+       for (; cnt && (*from = *to); --cnt, ++from, ++to);
+       for (; cnt; --cnt, ++from)
+               *from = '\0';
+       return(save);
 }
 }