#include #include #include "Strn.h" /* * Copy src to dst, truncating or null-padding to always copy n-1 bytes. * * This routine differs from strncpy in that it returns a pointer to the end * of the buffer, instead of strncat which returns a pointer to the start. */ char * Strnpcpy(char *const dst, const char *const src, size_t n) { register char *d; register const char *s; register char c; char *ret; register size_t i; d = dst; if (n != 0) { s = src; /* If they specified a maximum of n characters, use n - 1 chars to * hold the copy, and the last character in the array as a NUL. * This is the difference between the regular strncpy routine. * strncpy doesn't guarantee that your new string will have a * NUL terminator, but this routine does. */ for (i=1; i