strnlen.c 665 B

12345678910111213141516171819202122232425262728293031323334353637
  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 Wstrnlen wcsnlen
  10. #else
  11. # define Wstrnlen strnlen
  12. #endif
  13. libc_hidden_proto(Wstrnlen)
  14. size_t Wstrnlen(const Wchar *s, size_t max)
  15. {
  16. register const Wchar *p = s;
  17. #ifdef __BCC__
  18. /* bcc can optimize the counter if it thinks it is a pointer... */
  19. register const char *maxp = (const char *) max;
  20. #else
  21. # define maxp max
  22. #endif
  23. while (maxp && *p) {
  24. ++p;
  25. --maxp;
  26. }
  27. return p - s;
  28. }
  29. #undef maxp
  30. libc_hidden_def(Wstrnlen)