Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. # _strnlen() Author: Kees J. Bot  1 Jan 1994
  2.  
  3. # size_t _strnlen(const char *s, size_t ecx)
  4. # Return the length of a string.
  5.  
  6. .intel_syntax
  7.  
  8. .globl __strnlen
  9.  
  10. .text
  11.            .align  16
  12. __strnlen:
  13.            push    ebp
  14.            mov     ebp, esp
  15.            push    edi
  16.            mov     edi, [ebp+8]    # edi = string
  17.            xorb    al, al          # Look for a zero byte
  18.            mov     edx, ecx        # Save maximum count
  19.            cmpb    cl, 1           # 'Z' bit must be clear if ecx = 0
  20.            cld
  21.            repne
  22.            scasb                   # Look for zero
  23.            jne     no0
  24.            inc     ecx             # Don't count zero byte
  25. no0:
  26.            mov     eax, edx
  27.            sub     eax, ecx        # Compute bytes scanned
  28.            pop     edi
  29.            pop     ebp
  30.            ret
  31.