strcpy.c 847 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. char *strcpy(char *dest, const char *src)
  8. {
  9. char *ret = dest;
  10. unsigned long himagic = 0x80808080L;
  11. unsigned long lomagic = 0x01010101L;
  12. while ((unsigned long)src & (sizeof src - 1))
  13. {
  14. if (!(*dest++ = *src++))
  15. {
  16. return ret;
  17. }
  18. }
  19. while (1)
  20. {
  21. unsigned long value = *(unsigned long*)src;
  22. unsigned long magic;
  23. src += sizeof (unsigned long);
  24. if ((magic = (value - lomagic) & himagic))
  25. {
  26. if (magic & ~value)
  27. {
  28. break;
  29. }
  30. }
  31. *(unsigned long*)dest = value;
  32. dest += sizeof (unsigned long);
  33. }
  34. src -= sizeof (unsigned long);
  35. while ((*dest++ = *src++))
  36. {
  37. }
  38. return ret;
  39. }
  40. libc_hidden_def(strcpy)