/*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * Chris Torek. * * %sccs.include.redist.c% */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)strncpy.c 5.6 (Berkeley) 01/26/91"; #endif /* LIBC_SCCS and not lint */ #include #include /* * Copy src to dst, truncating or null-padding to always copy n bytes. * Return dst. */ char * strncpy(dst, src, n) char *dst; const char *src; register size_t n; { if (n != 0) { register char *d = dst; register const char *s = src; do { if ((*d++ = *s++) == 0) { /* NUL pad the remaining n-1 bytes */ while (--n != 0) *d++ = 0; break; } } while (--n != 0); } return (dst); }