Subversion Repositories Kolibri OS

Rev

Rev 1408 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*      _strnlen()                                      Author: Kees J. Bot */
  2. /*                                                              1 Jan 1994 */
  3.  
  4. /* size_t _strnlen(const char *s, size_t ecx) */
  5. /*      Return the length of a string. */
  6. /* */
  7. #include "asm.h"
  8.  
  9. ENTRY(_strnlen)
  10.         push    %ebp
  11.         movl    %esp, %ebp
  12.         push    %edi
  13.         movl    8(%ebp), %edi   /* edi = string */
  14.         xorb    %al, %al        /* Look for a zero byte */
  15.         movl    %ecx, %edx      /* Save maximum count */
  16.         cmpb    $1, %cl /* 'Z' bit must be clear if ecx = 0 */
  17.         cld
  18.  
  19.         repne scasb     /* Look for zero */
  20.         jne     no0
  21.         incl    %ecx    /* Don't count zero byte */
  22. no0:
  23.         movl    %edx, %eax
  24.         subl    %ecx, %eax      /* Compute bytes scanned */
  25.         pop     %edi
  26.         pop     %ebp
  27.         ret
  28.