121438Sdist/* 2*61222Sbostic * Copyright (c) 1983, 1993 3*61222Sbostic * The Regents of the University of California. All rights reserved. 434481Sbostic * 542640Sbostic * %sccs.include.redist.c% 621438Sdist */ 717325Ssam 834819Sbostic#if defined(LIBC_SCCS) && !defined(lint) 9*61222Sbostic .asciz "@(#)strncpy.s 8.1 (Berkeley) 06/04/93" 1034819Sbostic#endif /* LIBC_SCCS and not lint */ 1121438Sdist 1217325Ssam/* 1317325Ssam * Copy string s2 over top of string s1. 1417325Ssam * Truncate or null-pad to n bytes. 1517325Ssam * 1617325Ssam * char * 1717325Ssam * strncpy(s1, s2, n) 1817325Ssam * char *s1, *s2; 1917325Ssam */ 2017329Ssam#include "DEFS.h" 2117325Ssam 2217329SsamENTRY(strncpy, R6) 2317325Ssam movl 12(ap),r6 # r6 = n 2417325Ssam bleq done # n <= 0 2517325Ssam movl 4(ap),r3 # r3 = s1 2617325Ssam movl 8(ap),r1 # r1 = s2 2717325Ssam1: 2817325Ssam movzwl $65535,r2 # r2 = bytes in first chunk 2917325Ssam cmpl r6,r2 # r2 = min(bytes in chunk, n); 3017325Ssam jgeq 2f 3117325Ssam movl r6,r2 3217325Ssam2: 3317325Ssam subl2 r2,r6 # update n 3417325Ssam locc $0,r2,(r1) # '\0' found? 3517325Ssam jneq 3f 3617325Ssam subl2 r2,r1 # back up pointer updated by locc 3717325Ssam movc3 r2,(r1),(r3) # copy in next piece 3817325Ssam tstl r6 # run out of space? 3917325Ssam jneq 1b 4017325Ssam jbr done 4117325Ssam3: # copy up to '\0' logic 4217325Ssam addl2 r0,r6 # r6 = number of null-pad bytes 4317325Ssam subl2 r0,r2 # r2 = number of bytes to move 4417325Ssam subl2 r2,r1 # back up pointer updated by locc 4517325Ssam movc3 r2,(r1),(r3) # copy in last piece 4617325Ssam4: # null-pad logic 4717325Ssam movzwl $65535,r2 # r2 = bytes in first chunk 4817325Ssam cmpl r6,r2 # r2 = min(bytes in chunk, n); 4917325Ssam jgeq 5f 5017325Ssam movl r6,r2 5117325Ssam5: 5217325Ssam subl2 r2,r6 # update n 5317325Ssam movc5 $0,(r3),$0,r2,(r3)# pad with '\0's 5417325Ssam tstl r6 # finished padding? 5517325Ssam jneq 4b 5617325Ssamdone: 5717325Ssam movl 4(ap),r0 # return s1 5817325Ssam ret 59