memcmp.c 782 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (C) 2002 Manuel Novoa III
  3. * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include "_string.h"
  8. #ifdef WANT_WIDE
  9. # define Wmemcmp wmemcmp
  10. #else
  11. # define Wmemcmp memcmp
  12. #endif
  13. int Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n)
  14. {
  15. register const Wuchar *r1 = (const Wuchar *) s1;
  16. register const Wuchar *r2 = (const Wuchar *) s2;
  17. #ifdef WANT_WIDE
  18. while (n && (*r1 == *r2)) {
  19. ++r1;
  20. ++r2;
  21. --n;
  22. }
  23. return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
  24. #else
  25. int r = 0;
  26. while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));
  27. return r;
  28. #endif
  29. }
  30. #ifndef WANT_WIDE
  31. libc_hidden_def(memcmp)
  32. # ifdef __UCLIBC_SUSV3_LEGACY__
  33. strong_alias(memcmp,bcmp)
  34. # endif
  35. #endif