| Line | |
|---|
| 1 | ! _strnlen() Author: Kees J. Bot
|
|---|
| 2 | ! 1 Jan 1994
|
|---|
| 3 | .sect .text; .sect .rom; .sect .data; .sect .bss
|
|---|
| 4 |
|
|---|
| 5 | ! size_t _strnlen(const char *s, size_t ecx)
|
|---|
| 6 | ! Return the length of a string.
|
|---|
| 7 | !
|
|---|
| 8 | .sect .text
|
|---|
| 9 | .define __strnlen
|
|---|
| 10 | .align 16
|
|---|
| 11 | __strnlen:
|
|---|
| 12 | push ebp
|
|---|
| 13 | mov ebp, esp
|
|---|
| 14 | push edi
|
|---|
| 15 | mov edi, 8(ebp) ! edi = string
|
|---|
| 16 | xorb al, al ! Look for a zero byte
|
|---|
| 17 | mov edx, ecx ! Save maximum count
|
|---|
| 18 | cmpb cl, 1 ! 'Z' bit must be clear if ecx = 0
|
|---|
| 19 | cld
|
|---|
| 20 | repne
|
|---|
| 21 | scasb ! Look for zero
|
|---|
| 22 | jne no0
|
|---|
| 23 | inc ecx ! Don't count zero byte
|
|---|
| 24 | no0: mov eax, edx
|
|---|
| 25 | sub eax, ecx ! Compute bytes scanned
|
|---|
| 26 | pop edi
|
|---|
| 27 | pop ebp
|
|---|
| 28 | ret
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.