[comp.os.minix] New version of strncpy

bds@lzaz.ATT.COM (B.SZABLAK) (01/04/89)

The recent version of stevie posted here would crash frequently on
"puts". I've tracked the problem down to a bug in strncpy. Following
is the new version of strncpy that fixes the problems I was having
(stevie whas calling strncpy with n == 0 which may be a bug in itself):

char *strncpy(s1, s2, n)
register char *s1, *s2;
register n;
{
/* Copy s2 to s1, but at most n characters. */

  char *original = s1;

  while (n > 0 && *s2) {
	*s1++ = *s2++;
	--n;
  }
  while (--n >= 0) *s1++ = 0;
  return(original);
}