strncmp.c 758 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 Wstrncmp wcsncmp
  10. #else
  11. # define Wstrncmp strncmp
  12. #endif
  13. int Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n)
  14. {
  15. #ifdef WANT_WIDE
  16. while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) {
  17. if (!*s1++) {
  18. return 0;
  19. }
  20. ++s2;
  21. --n;
  22. }
  23. return (n == 0) ? 0 : (*((Wuchar *)s1) - *((Wuchar *)s2));
  24. #else
  25. int r = 0;
  26. while (n--
  27. && ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++))
  28. == 0)
  29. && *s1++);
  30. return r;
  31. #endif
  32. }
  33. #ifndef WANT_WIDE
  34. libc_hidden_weak(strncmp)
  35. #endif