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