1/* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific written prior permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13#if defined(SYSLIBC_SCCS) && !defined(lint) 14_sccsid:.asciz "@(#)strncat.s 5.4 (Berkeley) 05/25/88" 15#endif /* SYSLIBC_SCCS and not lint */ 16 17/* 18 * Concatenate string s2 on the end of s1 19 * and return the base of s1. The parameter 20 * n is the maximum length of string s2 to 21 * concatenate. 22 * 23 * char * 24 * strncat(s1, s2, n) 25 * char *s1, *s2; 26 * int n; 27 */ 28#include "DEFS.h" 29 30ENTRY(strncat, R6) 31 movl 12(ap),r6 # r6 = n 32 bleq done # n <= 0 33 movl 4(ap),r3 # r3 = s1 34 movl r3,r1 350: 36 locc $0,$65535,(r1) 37 beql 0b 38 movl r1,r3 # r3 = index(s1, '\0'); 39 movl 8(ap),r1 # r1 = s2 401: 41 movzwl $65535,r2 # r2 = bytes in first chunk 42 cmpl r6,r2 # r2 = min(bytes in chunk, n); 43 jgeq 2f 44 movl r6,r2 452: 46 subl2 r2,r6 # update n 47 locc $0,r2,(r1) # '\0' found? 48 jneq 3f 49 subl2 r2,r1 # back up pointer updated by locc 50 movc3 r2,(r1),(r3) # copy in next piece 51 tstl r6 # run out of space? 52 jneq 1b 53 clrb (r3) # force '\0' termination 54 jbr done 553: 56 subl2 r0,r2 # r2 = number of bytes to move 57 subl2 r2,r1 # back up pointer updated by locc 58 incl r2 # copy '\0' as well 59 movc3 r2,(r1),(r3) # copy in last piece 60done: 61 movl 4(ap),r0 # return s1 62 ret 63