xref: /original-bsd/lib/libc/vax/string/strncat.s (revision c3e32dec)
1/*
2 * Copyright (c) 1983, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
9	.asciz "@(#)strncat.s	8.1 (Berkeley) 06/04/93"
10#endif /* LIBC_SCCS and not lint */
11
12/*
13 * Concatenate string s2 on the end of s1
14 * and return the base of s1.  The parameter
15 * n is the maximum length of string s2 to
16 * concatenate.
17 *
18 * char *
19 * strncat(s1, s2, n)
20 *	char *s1, *s2;
21 *	int n;
22 */
23#include "DEFS.h"
24
25ENTRY(strncat, R6)
26	movl	12(ap),r6	# r6 = n
27	bleq	done		# n <= 0
28	movl	4(ap),r3	# r3 = s1
29	movl	r3,r1
300:
31	locc	$0,$65535,(r1)
32	beql	0b
33	movl	r1,r3		# r3 = index(s1, '\0');
34	movl	8(ap),r1	# r1 = s2
351:
36	movzwl	$65535,r2	# r2 = bytes in first chunk
37	cmpl	r6,r2		# r2 = min(bytes in chunk, n);
38	jgeq	2f
39	movl	r6,r2
402:
41	subl2	r2,r6		# update n
42	locc	$0,r2,(r1)	# '\0' found?
43	jneq	3f
44	subl2	r2,r1		# back up pointer updated by locc
45	movc3	r2,(r1),(r3)	# copy in next piece
46	tstl	r6		# run out of space?
47	jneq	1b
48	clrb	(r3)		# force '\0' termination
49	jbr	done
503:
51	subl2	r0,r2		# r2 = number of bytes to move
52	subl2	r2,r1		# back up pointer updated by locc
53	incl	r2		# copy '\0' as well
54	movc3	r2,(r1),(r3)	# copy in last piece
55done:
56	movl	4(ap),r0	# return s1
57	ret
58