rawmemchr.c 487 B

123456789101112131415161718192021222324
  1. /*
  2. * Adapted from strlen.c code
  3. *
  4. * Copyright (C) 2008 Denys Vlasenko <vda.linux@googlemail.com>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <string.h>
  9. #undef rawmemchr
  10. void *rawmemchr(const void *s, int c)
  11. {
  12. void *eax;
  13. int ecx, edi;
  14. __asm__ __volatile__(
  15. " repne; scasb\n"
  16. " leal -1(%%edi), %%eax\n"
  17. : "=&c" (ecx), "=&D" (edi), "=&a" (eax)
  18. : "0" (0xffffffff), "1" (s), "2" (c)
  19. );
  20. return eax;
  21. }
  22. libc_hidden_def(rawmemchr)