strcpy.c 900 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (C) 2006-2007 Axis Communications AB
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <string.h>
  7. /* Experimentally off - libc_hidden_proto(strcpy) */
  8. char *strcpy(char *dest, const char *src)
  9. {
  10. char *ret = dest;
  11. unsigned long himagic = 0x80808080L;
  12. unsigned long lomagic = 0x01010101L;
  13. while ((unsigned long)src & (sizeof src - 1))
  14. {
  15. if (!(*dest++ = *src++))
  16. {
  17. return ret;
  18. }
  19. }
  20. while (1)
  21. {
  22. unsigned long value = *(unsigned long*)src;
  23. unsigned long magic;
  24. src += sizeof (unsigned long);
  25. if ((magic = (value - lomagic) & himagic))
  26. {
  27. if (magic & ~value)
  28. {
  29. break;
  30. }
  31. }
  32. *(unsigned long*)dest = value;
  33. dest += sizeof (unsigned long);
  34. }
  35. src -= sizeof (unsigned long);
  36. while ((*dest++ = *src++))
  37. {
  38. }
  39. return ret;
  40. }
  41. libc_hidden_def(strcpy)