Subversion Repositories Kolibri OS

Rev

Rev 1408 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1408 Rev 1627
Line 1... Line 1...
1
#       _strncat()                                 Author: Kees J. Bot
1
/*	_strncat()					Author: Kees J. Bot */
2
#                                                  1 Jan 1994
-
 
3
# char *_strncat(char *s1, const char *s2, size_t edx)
-
 
4
#	Append string s2 to s1.
2
/*								1 Jan 1994 */
5
#
-
 
Line -... Line 3...
-
 
3
 
-
 
4
/* char *_strncat(char *s1, const char *s2, size_t edx) */
-
 
5
/*	Append string s2 to s1. */
6
 
6
/* */
Line 7... Line -...
7
.intel_syntax
-
 
8
 
-
 
9
.global __strncat
-
 
10
 
-
 
11
        .text
7
#include "asm.h"
12
	.align	16
8
 
13
__strncat:
9
ENTRY(_strncat)
14
	push	ebp
10
	push	%ebp
15
	mov	ebp, esp
11
	movl	%esp, %ebp
16
	push	esi
12
	push	%esi
17
	push	edi
13
	push	%edi
18
        mov     edi, [ebp+8]    # String s1
14
	movl	8(%ebp), %edi	/* String s1 */
19
	mov	ecx, -1
15
	movl	$-1, %ecx
20
	xorb	al, al		# Null byte
16
	xorb	%al, %al	/* Null byte */
21
	cld
17
	cld
22
	repne
18
 
23
	scasb			# Look for the zero byte in s1
19
	repne scasb	/* Look for the zero byte in s1 */
24
	dec	edi		# Back one up (and clear 'Z' flag)
20
	decl	%edi	/* Back one up (and clear 'Z' flag) */
25
	push	edi		# Save end of s1
21
	push	%edi	/* Save end of s1 */
26
        mov     edi, [12+ebp]   # edi = string s2
22
	movl	12(%ebp), %edi	/* edi = string s2 */
27
	mov	ecx, edx	# Maximum count
23
	movl	%edx, %ecx	/* Maximum count */
28
	repne
24
 
29
	scasb			# Look for the end of s2
25
	repne scasb	/* Look for the end of s2 */
-
 
26
	jne	no0
30
	jne	no0
27
	incl	%ecx	/* Exclude null byte */
31
	inc	ecx		# Exclude null byte
28
no0:
32
no0:	sub	edx, ecx	# Number of bytes in s2
29
	subl	%ecx, %edx	/* Number of bytes in s2 */
33
	mov	ecx, edx
30
	movl	%edx, %ecx
34
        mov     esi, [12+ebp]   # esi = string s2
31
	movl	12(%ebp), %esi	/* esi = string s2 */
35
	pop	edi		# edi = end of string s1
32
	pop	%edi	/* edi = end of string s1 */
36
	rep
33
 
37
	movsb			# Copy bytes
34
	rep movsb	/* Copy bytes */
38
	stosb			# Add a terminating null
35
	stosb	/* Add a terminating null */
39
        mov     eax, [8+ebp]    # Return s1
36
	movl	8(%ebp), %eax	/* Return s1 */
40
	pop	edi
37
	pop	%edi
41
	pop	esi
38
	pop	%esi