Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*      strrchr()                                       Author: Kees J. Bot */
  2. /*                                                              2 Jan 1994 */
  3.  
  4. /* char *strrchr(const char *s, int c) */
  5. /*      Look for the last occurrence a character in a string. */
  6. /* */
  7. #include "asm.h"
  8.  
  9. ENTRY(strrchr)
  10.         push    %ebp
  11.         movl    %esp, %ebp
  12.         push    %edi
  13.         movl    8(%ebp), %edi   /* edi = string */
  14.         movl    $-1, %ecx
  15.         xorb    %al, %al
  16.         cld
  17.  
  18.         repne scasb     /* Look for the end of the string */
  19.         notl    %ecx    /* -1 - ecx = Length of the string + null */
  20.         decl    %edi    /* Put edi back on the zero byte */
  21.         movb    12(%ebp), %al   /* The character to look for */
  22.         std     /* Downwards search */
  23.  
  24.         repne scasb
  25.         cld     /* Direction bit back to default */
  26.         jne     failure
  27.         leal    1(%edi), %eax   /* Found it */
  28.         pop     %edi
  29.         pop     %ebp
  30.         ret
  31. failure:
  32.         xorl    %eax, %eax      /* Not there */
  33.         pop     %edi
  34.         pop     %ebp
  35.         ret
  36.