xref: /csrg-svn/lib/libc/vax/string/strncat.s (revision 61222)
121436Sdist/*
2*61222Sbostic * Copyright (c) 1983, 1993
3*61222Sbostic *	The Regents of the University of California.  All rights reserved.
434481Sbostic *
542639Sbostic * %sccs.include.redist.c%
621436Sdist */
717323Ssam
834819Sbostic#if defined(LIBC_SCCS) && !defined(lint)
9*61222Sbostic	.asciz "@(#)strncat.s	8.1 (Berkeley) 06/04/93"
1034819Sbostic#endif /* LIBC_SCCS and not lint */
1121436Sdist
1217323Ssam/*
1317323Ssam * Concatenate string s2 on the end of s1
1417323Ssam * and return the base of s1.  The parameter
1517323Ssam * n is the maximum length of string s2 to
1617323Ssam * concatenate.
1717323Ssam *
1817323Ssam * char *
1917323Ssam * strncat(s1, s2, n)
2017323Ssam *	char *s1, *s2;
2117323Ssam *	int n;
2217323Ssam */
2317329Ssam#include "DEFS.h"
2417323Ssam
2517329SsamENTRY(strncat, R6)
2617323Ssam	movl	12(ap),r6	# r6 = n
2717323Ssam	bleq	done		# n <= 0
2817323Ssam	movl	4(ap),r3	# r3 = s1
2917323Ssam	movl	r3,r1
3017323Ssam0:
3117323Ssam	locc	$0,$65535,(r1)
3217323Ssam	beql	0b
3317323Ssam	movl	r1,r3		# r3 = index(s1, '\0');
3417323Ssam	movl	8(ap),r1	# r1 = s2
3517323Ssam1:
3617323Ssam	movzwl	$65535,r2	# r2 = bytes in first chunk
3717323Ssam	cmpl	r6,r2		# r2 = min(bytes in chunk, n);
3817323Ssam	jgeq	2f
3917323Ssam	movl	r6,r2
4017323Ssam2:
4117323Ssam	subl2	r2,r6		# update n
4217323Ssam	locc	$0,r2,(r1)	# '\0' found?
4317323Ssam	jneq	3f
4417323Ssam	subl2	r2,r1		# back up pointer updated by locc
4517323Ssam	movc3	r2,(r1),(r3)	# copy in next piece
4617323Ssam	tstl	r6		# run out of space?
4717323Ssam	jneq	1b
4817323Ssam	clrb	(r3)		# force '\0' termination
4917323Ssam	jbr	done
5017323Ssam3:
5117323Ssam	subl2	r0,r2		# r2 = number of bytes to move
5217323Ssam	subl2	r2,r1		# back up pointer updated by locc
5317323Ssam	incl	r2		# copy '\0' as well
5417323Ssam	movc3	r2,(r1),(r3)	# copy in last piece
5517323Ssamdone:
5617323Ssam	movl	4(ap),r0	# return s1
5717323Ssam	ret
58