1: /* 2: * Copyright (c) 1987 Regents of the University of California. 3: * All rights reserved. The Berkeley software License Agreement 4: * specifies the terms and conditions for redistribution. 5: */ 6: 7: #ifdef LIBC_SCCS 8: <@(#)strncpy.s 1.1 (Berkeley) 1/20/87\0> 9: .even 10: #endif LIBC_SCCS 11: 12: /* 13: * Copy string s2 over top of string s1. 14: * Truncate or null-pad to n bytes. 15: * 16: * char * 17: * strncpy(s1, s2, n) 18: * char *s1, *s2; 19: */ 20: #include "DEFS.h" 21: 22: ENTRY(strncpy) 23: mov 6(sp),r0 / r0 = n 24: beq 3f / (all done if n == 0) 25: mov 2(sp),r1 / r1 = s1 26: mov r2,-(sp) / need an extra register for s2 ... 27: mov 6(sp),r2 / r2 = s2 28: 1: 29: movb (r2)+,(r1)+ / copy s2 to the end of s1 stopping at the 30: beq 4f / end of s2 or when n runs out ... 31: sob r0,1b 32: 2: 33: mov (sp)+,r2 / restore r2 34: 3: 35: mov 2(sp),r0 / and return s1 36: rts pc 37: 4: 38: dec r0 / the '\0' may also have run n out ... 39: beq 2b 40: 5: 41: clrb (r1)+ / null pad s1 till n runs out 42: sob r0,5b 43: br 2b / clean up and return