strncmp.c 795 B

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