	.file	"strncat.s"
/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 *
 */

/*	Copyright (c) 1986 AT&T	*/
/*	All Rights Reserved	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any	*/
/*	actual or intended publication of such source code.	*/

	.ident	"@(#)$Header: strncat.s 1.3 89/10/10 $"

/*
 * Concatenate s2 on the end of s1.  S1's space must be large enough.
 * At most n characters are moved.
 * Return s1.
 */

/*	#include <sys/types.h>
 *	char *
 *	strncat(s1, s2, n)
 */

#include "sys.s"

#define STRNCAT \
	; slodb				/* 5, get byte, incr %esi */	\
	; sstob				/* 4, put byte, incr %edi */	\
	; testb %al,%al			/* 2, end of string? */		\
	; jz	strncat_done		/* 3 or 7+M */			\
	; decl	%ecx			/* 2, decr count */		\
	; jz	strncat_zero		/* 3 or 7+M */

ENTRY(strncat)
	pushl	%esi			/* save %esi */
	pushl	%edi			/* save %esi */
	xorl	%ecx,%ecx
	decl	%ecx			/* large count */
	movl	8+SPARG0,%edi		/* s1 */
	movl	8+SPARG1,%esi		/* s2 */
	xorb	%al,%al			/* match null in %al */

	repnz;	scab			/* scan forward till null byte */

	decl	%edi			/* backup to null byte */
	movl	8+SPARG2, %ecx		/* get count */
	testl	%ecx,%ecx		/* zero count means no work to do */
	jz	strncat_done

strncat_loop:
	STRNCAT				/* 19 */
	STRNCAT				/* 19 */
	STRNCAT				/* 19 */
	STRNCAT				/* 19 */
	STRNCAT				/* 19 */
	STRNCAT				/* 19 */
	STRNCAT				/* 19 */
	STRNCAT				/* 19 */
	jmp	strncat_loop		/* 8 */

strncat_zero:
	movb	$0,(%edi)		/* write null byte */
strncat_done:
	movl	8+SPARG0,%eax		/* return s1 */
	popl	%edi
	popl	%esi
	ret
