ReactOS  0.4.15-dev-3163-gf17c2c0
_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)
15 _CRTIMP
16 size_t
17 __cdecl
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 
errno_t __cdecl _set_errno(_In_ int _Value)
#define INT_MAX
Definition: limits.h:40
#define __cdecl
Definition: accygwin.h:79
#define _CRTIMP
Definition: crtdefs.h:72
Definition: arc.h:39
#define _In_
Definition: ms_sal.h:308
#define _In_z_
Definition: ms_sal.h:313
_Success_(return, 0)
Definition: _mbstrnlen.c:13
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
#define _Check_return_
Definition: ms_sal.h:557
int __cdecl _ismbblead(unsigned int)
Definition: ismblead.c:20
#define const
Definition: zconf.h:230