strncpy.c 466 B

123456789101112131415161718192021222324
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. #include <string.h>
  7. char *
  8. strncpy(char *ret, register const char *s2, register size_t n)
  9. {
  10. register char *s1 = ret;
  11. if (n>0) {
  12. while((*s1++ = *s2++) && --n > 0)
  13. /* EMPTY */ ;
  14. if ((*--s2 == '\0') && --n > 0) {
  15. do {
  16. *s1++ = '\0';
  17. } while(--n > 0);
  18. }
  19. }
  20. return ret;
  21. }