ReactOS 0.4.16-dev-136-g52192f1
mbrtowc.c
Go to the documentation of this file.
1/*
2 * msvcrt.dll mbcs functions
3 *
4 * Copyright 1999 Alexandre Julliard
5 * Copyright 2000 Jon Griffths
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22#include <precomp.h>
23#include <locale.h>
24
25/*********************************************************************
26 * mbrtowc(MSVCRT.@)
27 */
28size_t CDECL mbrtowc(wchar_t *dst, const char *str,
29 size_t n, mbstate_t *state)
30{
31 mbstate_t s = (state ? *state : 0);
32 char tmpstr[2];
33 int len = 0;
34
35 if(dst)
36 *dst = 0;
37
38 if(!n || !str || !*str)
39 return 0;
40
41 if(___mb_cur_max_func() == 1) {
42 tmpstr[len++] = *str;
43 }else if(!s && isleadbyte((unsigned char)*str)) {
44 if(n == 1) {
45 s = (unsigned char)*str;
46 len = -2;
47 }else {
48 tmpstr[0] = str[0];
49 tmpstr[1] = str[1];
50 len = 2;
51 }
52 }else if(!s) {
53 tmpstr[len++] = *str;
54 }else {
55 tmpstr[0] = s;
56 tmpstr[1] = *str;
57 len = 2;
58 s = 0;
59 }
60
61 if(len > 0) {
62 if(!MultiByteToWideChar(___lc_codepage_func(), 0, tmpstr, len, dst, dst ? 1 : 0))
63 len = -1;
64 }
65
66 if(state)
67 *state = s;
68 return len;
69}
static int state
Definition: maze.c:121
#define CDECL
Definition: compat.h:29
#define MultiByteToWideChar
Definition: compat.h:110
unsigned char
Definition: typeof.h:29
GLdouble s
Definition: gl.h:2039
GLdouble n
Definition: glext.h:7729
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
#define ___mb_cur_max_func()
Definition: ctype.h:636
_CRTIMP unsigned int __cdecl ___lc_codepage_func(void)
Definition: locale.c:627
#define isleadbyte(_c)
Definition: wchar.h:596
const WCHAR * str
#define mbrtowc(wp, cp, len, sp)
Definition: wchar.h:158