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