memcmp.c 835 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. /* Experimentally off - libc_hidden_proto(memcmp) */
  12. # define Wmemcmp memcmp
  13. #endif
  14. int Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n)
  15. {
  16. register const Wuchar *r1 = (const Wuchar *) s1;
  17. register const Wuchar *r2 = (const Wuchar *) s2;
  18. #ifdef WANT_WIDE
  19. while (n && (*r1 == *r2)) {
  20. ++r1;
  21. ++r2;
  22. --n;
  23. }
  24. return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
  25. #else
  26. int r = 0;
  27. while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));
  28. return r;
  29. #endif
  30. }
  31. #ifndef WANT_WIDE
  32. libc_hidden_def(memcmp)
  33. # ifdef __UCLIBC_SUSV3_LEGACY__
  34. strong_alias(memcmp,bcmp)
  35. # endif
  36. #endif