ReactOS 0.4.15-dev-7953-g1f49173
_mbstrnlen.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS CRT
4 * PURPOSE: Implementation of _mbstrnlen
5 * FILE: lib/sdk/crt/string/_mbstrnlen.c
6 * PROGRAMMER: Timo Kreuzer
7 */
8
9#include <precomp.h>
10#include <mbctype.h>
11#include <specstrings.h>
12
13_Success_(return>0)
16size_t
18_mbstrnlen(
19 _In_z_ const char *pmbstr,
20 _In_ size_t cjMaxLen)
21{
22 size_t cchCount = 0;
23 unsigned char jMbsByte;
24
25 /* Check parameters */
26 if (!MSVCRT_CHECK_PMT((pmbstr != 0)) && (cjMaxLen <= INT_MAX))
27 {
29 return -1;
30 }
31
32 /* Loop while we have bytes to process */
33 while (cjMaxLen-- > 0)
34 {
35 /* Get next mb byte */
36 jMbsByte = *pmbstr++;
37
38 /* If this is 0, we're done */
39 if (jMbsByte == 0) break;
40
41 /* if this is a lead byte, continue with next char */
42 if (_ismbblead(jMbsByte))
43 {
44 // FIXME: check if this is a valid char.
45 continue;
46 }
47
48 /* Count this character */
49 cchCount++;
50 }
51
52 return cchCount;
53}
54
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
#define _CRTIMP
Definition: crtdefs.h:72
#define INT_MAX
Definition: limits.h:40
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
int __cdecl _ismbblead(unsigned int)
Definition: ismblead.c:20
#define _Success_(expr)
Definition: ms_sal.h:259
#define _In_z_
Definition: ms_sal.h:313
#define _Check_return_
Definition: ms_sal.h:557
#define _In_
Definition: ms_sal.h:308
errno_t __cdecl _set_errno(_In_ int _Value)
#define const
Definition: zconf.h:233