wcslen_s.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // Copyright (c) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  4. //
  5. /***
  6. *wcslen_s.c - contains wcsnlen() routine
  7. *
  8. *
  9. *Purpose:
  10. * wcslen returns the length of a null-terminated wide-character string,
  11. * not including the null char16_t itself.
  12. *
  13. *******************************************************************************/
  14. #include <string.h>
  15. #include <errno.h>
  16. #include <limits.h>
  17. #include "internal_securecrt.h"
  18. #include "mbusafecrt_internal.h"
  19. /***
  20. *wcsnlen - return the length of a null-terminated wide-character string
  21. *
  22. *Purpose:
  23. * Finds the length in bytes of the given string, not including
  24. * the final null character. Only the first maxsize characters
  25. * are inspected: if the null character is not found, maxsize is
  26. * returned.
  27. *
  28. *Entry:
  29. * const char16_t * wcs - string whose length is to be computed
  30. * size_t maxsize
  31. *
  32. *Exit:
  33. * Length of the string "wcs", exclusive of the final null byte, or
  34. * maxsize if the null character is not found.
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39. size_t __cdecl wcsnlen(const char16_t *wcs, size_t maxsize)
  40. {
  41. size_t n;
  42. /* Note that we do not check if s == NULL, because we do not
  43. * return errno_t...
  44. */
  45. for (n = 0; n < maxsize && *wcs; n++, wcs++)
  46. ;
  47. return n;
  48. }