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