strncpy.c 230 B

123456789101112131415161718
  1. #include <u.h>
  2. #include <libc.h>
  3. char*
  4. strncpy(char *s1, char *s2, long n)
  5. {
  6. int i;
  7. char *os1;
  8. os1 = s1;
  9. for(i = 0; i < n; i++)
  10. if((*s1++ = *s2++) == 0) {
  11. while(++i < n)
  12. *s1++ = 0;
  13. return os1;
  14. }
  15. return os1;
  16. }