strncat.c 376 B

12345678910111213141516171819202122232425
  1. /* $Id$ */
  2. char *strncat(s1, s2, n)
  3. register char *s1, *s2;
  4. int n;
  5. {
  6. /* Append s2 to the end of s1, but no more than n characters */
  7. char *original = s1;
  8. if (n <= 0) return(s1);
  9. /* Find the end of s1. */
  10. while (*s1++ != 0) ;
  11. s1--;
  12. /* Now copy s2 to the end of s1. */
  13. while (*s1++ = *s2++) {
  14. if (--n == 0) {
  15. *s1 = 0;
  16. break;
  17. }
  18. }
  19. return(original);
  20. }