2010-09-27 02:57:18 +04:00
|
|
|
/* _strnlen() Author: Kees J. Bot */
|
|
|
|
/* 1 Jan 1994 */
|
2010-02-12 23:11:35 +03:00
|
|
|
|
2010-09-27 02:57:18 +04:00
|
|
|
/* size_t _strnlen(const char *s, size_t ecx) */
|
|
|
|
/* Return the length of a string. */
|
|
|
|
/* */
|
|
|
|
#include "asm.h"
|
2010-02-12 23:11:35 +03:00
|
|
|
|
2010-09-27 02:57:18 +04:00
|
|
|
ENTRY(_strnlen)
|
|
|
|
push %ebp
|
|
|
|
movl %esp, %ebp
|
|
|
|
push %edi
|
|
|
|
movl 8(%ebp), %edi /* edi = string */
|
|
|
|
xorb %al, %al /* Look for a zero byte */
|
|
|
|
movl %ecx, %edx /* Save maximum count */
|
|
|
|
cmpb $1, %cl /* 'Z' bit must be clear if ecx = 0 */
|
|
|
|
cld
|
2010-02-12 23:11:35 +03:00
|
|
|
|
2010-09-27 02:57:18 +04:00
|
|
|
repne scasb /* Look for zero */
|
|
|
|
jne no0
|
|
|
|
incl %ecx /* Don't count zero byte */
|
2010-02-12 23:11:35 +03:00
|
|
|
no0:
|
2010-09-27 02:57:18 +04:00
|
|
|
movl %edx, %eax
|
|
|
|
subl %ecx, %eax /* Compute bytes scanned */
|
|
|
|
pop %edi
|
|
|
|
pop %ebp
|
|
|
|
ret
|