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