date and time created 85/05/30 13:54:43 by mckusick
[unix-history] / usr / src / lib / libc / vax / string / strncat.s
CommitLineData
dadab5a2 1/* strncat.s 4.2 84/11/01 */
4bd005a5
SL
2
3/*
4 * Concatenate string s2 on the end of s1
5 * and return the base of s1. The parameter
6 * n is the maximum length of string s2 to
7 * concatenate.
8 *
9 * char *
10 * strncat(s1, s2, n)
11 * char *s1, *s2;
12 * int n;
13 */
dadab5a2 14#include "DEFS.h"
4bd005a5 15
dadab5a2 16ENTRY(strncat, R6)
4bd005a5
SL
17 movl 12(ap),r6 # r6 = n
18 bleq done # n <= 0
19 movl 4(ap),r3 # r3 = s1
20 movl r3,r1
210:
22 locc $0,$65535,(r1)
23 beql 0b
24 movl r1,r3 # r3 = index(s1, '\0');
25 movl 8(ap),r1 # r1 = s2
261:
27 movzwl $65535,r2 # r2 = bytes in first chunk
28 cmpl r6,r2 # r2 = min(bytes in chunk, n);
29 jgeq 2f
30 movl r6,r2
312:
32 subl2 r2,r6 # update n
33 locc $0,r2,(r1) # '\0' found?
34 jneq 3f
35 subl2 r2,r1 # back up pointer updated by locc
36 movc3 r2,(r1),(r3) # copy in next piece
37 tstl r6 # run out of space?
38 jneq 1b
39 clrb (r3) # force '\0' termination
40 jbr done
413:
42 subl2 r0,r2 # r2 = number of bytes to move
43 subl2 r2,r1 # back up pointer updated by locc
44 incl r2 # copy '\0' as well
45 movc3 r2,(r1),(r3) # copy in last piece
46done:
47 movl 4(ap),r0 # return s1
48 ret